Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.gov.al.saude.rhd.core.domain; |
| 2 | |||
| 3 | import static br.gov.al.saude.test.ConstantesTestHelper.UsuarioScaConstantes.*; |
||
| 4 | import static br.gov.al.saude.test.ConstantesTestHelper.PessoaConstantes.*; |
||
| 5 | |||
| 6 | import java.util.ArrayList; |
||
| 7 | |||
| 8 | import org.jmock.Expectations; |
||
| 9 | import org.jmock.Mockery; |
||
| 10 | import org.jmock.integration.junit4.JMock; |
||
| 11 | import org.jmock.integration.junit4.JUnit4Mockery; |
||
| 12 | import org.junit.Before; |
||
| 13 | import org.junit.Test; |
||
| 14 | import org.junit.runner.RunWith; |
||
| 15 | |||
| 16 | import br.gov.al.saude.rhd.core.domain.unidade.UnidadeService; |
||
| 17 | import br.gov.al.saude.rhd.core.domain.unidade.impl.UnidadeServiceImpl; |
||
| 18 | import br.gov.al.saude.rhd.core.infrastructure.persistence.jpa.UnidadeRepository; |
||
| 19 | import br.gov.al.saude.rhd.model.view.UnidadeView; |
||
| 20 | import br.gov.al.saude.sca.model.usuario.view.UsuarioView; |
||
| 21 | import br.gov.al.saude.test.builder.UsuarioViewBuilder; |
||
| 22 | |||
| 23 | @RunWith(JMock.class) |
||
| 24 | public class UnidadeServiceImplTest{ |
||
| 25 | |||
| 26 | private UnidadeRepository unidadeRepositoryMock; |
||
| 27 | private UnidadeService unidadeService; |
||
| 28 | private Mockery contexto; |
||
| 29 | |||
| 30 | @Before |
||
| 31 | public void inicializarContexto() { |
||
| 32 | contexto = new JUnit4Mockery(); |
||
| 33 | unidadeRepositoryMock = getContexto().mock(UnidadeRepository.class); |
||
| 34 | unidadeService = new UnidadeServiceImpl(unidadeRepositoryMock); |
||
| 35 | } |
||
| 36 | |||
| 37 | public Mockery getContexto() { |
||
| 38 | return contexto; |
||
| 39 | } |
||
| 40 | |||
| 41 | @Test |
||
| 42 | public void aoListarUnidadeExercicioPorPapelUsuarioComPapelCoordenadorDeveriaDelegarParaOhRepositorio() throws Exception { |
||
| 43 | UsuarioView usuario = new UsuarioViewBuilder() |
||
| 44 | .comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2) |
||
| 45 | .comRole(PAPEL_RHD_COORDENADOR_RHD).build(); |
||
| 46 | getContexto().checking(new Expectations(){{ |
||
| 47 | oneOf(unidadeRepositoryMock).consultarTodos(); |
||
| 48 | will(returnValue(new ArrayList<UnidadeView>())); |
||
| 49 | never(unidadeRepositoryMock).consultarUnidadesExercicioServidor(with(any(Long.class))); |
||
| 50 | }}); |
||
| 51 | unidadeService.listarUnidadeExercicioPorPapelUsuario(usuario); |
||
| 52 | } |
||
| 53 | |||
| 54 | @Test |
||
| 55 | public void aoListarUnidadeExercicioPorPapelUsuarioComPapelServidorOuApoiadorDeveriaDelegarParaOhRepositorio() throws Exception { |
||
| 56 | UsuarioView usuario = new UsuarioViewBuilder() |
||
| 57 | .comSequencial(SEQUENCIAL_PESSOA_CARLOS_EDUARDO_7) |
||
| 58 | .comRole(PAPEL_RHD_APOIADOR_RHD) |
||
| 59 | .build(); |
||
| 60 | getContexto().checking(new Expectations(){{ |
||
| 61 | never(unidadeRepositoryMock).consultarTodos(); |
||
| 62 | oneOf(unidadeRepositoryMock).consultarUnidadesExercicioServidor(with(any(Long.class))); |
||
| 63 | will(returnValue(new ArrayList<UnidadeView>())); |
||
| 64 | }}); |
||
| 65 | unidadeService.listarUnidadeExercicioPorPapelUsuario(usuario); |
||
| 66 | } |
||
| 67 | |||
| 68 | @Test |
||
| 69 | public void aoListarUnidadeExercicioPorPapelUsuarioSemPermissoesDeveriaDelegarParaOhRepositorio() throws Exception { |
||
| 70 | UsuarioView usuario = new UsuarioView(); |
||
| 71 | usuario.setPermissoes(null); |
||
| 72 | getContexto().checking(new Expectations(){{ |
||
| 73 | never(unidadeRepositoryMock).consultarTodos(); |
||
| 74 | oneOf(unidadeRepositoryMock).consultarUnidadesExercicioServidor(with(any(Long.class))); |
||
| 75 | will(returnValue(new ArrayList<UnidadeView>())); |
||
| 76 | }}); |
||
| 77 | unidadeService.listarUnidadeExercicioPorPapelUsuario(usuario); |
||
| 78 | } |
||
| 79 | |||
| 80 | |||
| 81 | } |