Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.gov.al.saude.scs.core.domain; |
| 2 | |||
| 3 | import static br.gov.al.saude.scs.constantes.ContantesScs.MensagensContantes.MSG_OBRIGATORIO_INFORMAR_PARTICIPANTE; |
||
| 4 | |||
| 5 | import org.jmock.Expectations; |
||
| 6 | import org.jmock.integration.junit4.JMock; |
||
| 7 | import org.junit.Before; |
||
| 8 | import org.junit.Test; |
||
| 9 | import org.junit.runner.RunWith; |
||
| 10 | |||
| 11 | import br.gov.al.saude.framework.core.interfaces.Contexto; |
||
| 12 | import br.gov.al.saude.framework.core.validador.Validador; |
||
| 13 | import br.gov.al.saude.scs.core.domain.relatorio.RelatorioService; |
||
| 14 | import br.gov.al.saude.scs.core.domain.relatorio.impl.RelatorioServiceImpl; |
||
| 15 | import br.gov.al.saude.scs.core.infrastructure.relatorio.GeradorRelatorio; |
||
| 16 | import br.gov.al.saude.scs.model.TurmaParticipante; |
||
| 17 | import br.gov.al.saude.scs.parametros.ParametrosRelatorioCapacitacaoPorParticipante; |
||
| 18 | import br.gov.al.saude.scs.parametros.ParametrosRelatorioCapacitacaoPorPeriodo; |
||
| 19 | import br.gov.al.saude.scs.parametros.ParametrosRelatorioDespesas; |
||
| 20 | import br.gov.al.saude.scs.parametros.ParametrosRelatorioParticipantePorTurma; |
||
| 21 | import br.gov.al.saude.scs.parametros.ParametrosRelatorioParticipantesFaltantes; |
||
| 22 | import br.gov.al.saude.test.unidade.AbstractUnitTest; |
||
| 23 | import br.gov.al.saude.test.util.CommandSemMensagem; |
||
| 24 | import br.gov.al.saude.test.util.VerificadorLancamentoException; |
||
| 25 | |||
| 26 | |||
| 27 | @RunWith(JMock.class) |
||
| 28 | public class RelatorioServiceImplTest extends AbstractUnitTest { |
||
| 29 | |||
| 30 | private RelatorioService relatorioService; |
||
| 31 | private GeradorRelatorio geradorRelatorioMock; |
||
| 32 | private Validador validadorMock; |
||
| 33 | |||
| 34 | @Before |
||
| 35 | public void inicializarContexto(){ |
||
| 36 | validadorMock = getContexto().mock(Validador.class); |
||
| 37 | geradorRelatorioMock = getContexto().mock(GeradorRelatorio.class); |
||
| 38 | relatorioService = new RelatorioServiceImpl(getValidadorMock(), getGeradorRelatorioMock()); |
||
| 39 | } |
||
| 40 | |||
| 41 | @Test |
||
| 42 | public void aoEmitirRelatorioCapacitacaoPorParticipanteDeveriaDelegarParaOhGerador(){ |
||
| 43 | getContexto().checking(new Expectations(){{ |
||
| 44 | ignoring(getValidadorMock()).validar(with(any(ParametrosRelatorioCapacitacaoPorParticipante.class)), with(new Class<?>[]{Contexto.class})); |
||
| 45 | oneOf(getGeradorRelatorioMock()).emitirRelatorioCapacitacaoPorParticipante(with(any(ParametrosRelatorioCapacitacaoPorParticipante.class))); |
||
| 46 | }}); |
||
| 47 | getRelatorioService().emitirRelatorioCapacitacaoPorParticipante(new ParametrosRelatorioCapacitacaoPorParticipante()); |
||
| 48 | } |
||
| 49 | |||
| 50 | @Test |
||
| 51 | public void aoEmitirRelatorioCapacitacaoPorParticipanteDeveriaDelegarParaOhValidadorComContexto(){ |
||
| 52 | final ParametrosRelatorioCapacitacaoPorParticipante parametros = new ParametrosRelatorioCapacitacaoPorParticipante(); |
||
| 53 | getContexto().checking(new Expectations(){{ |
||
| 54 | oneOf(getValidadorMock()).validar(with(same(parametros)), with(new Class<?>[]{Contexto.class})); |
||
| 55 | ignoring(getGeradorRelatorioMock()).emitirRelatorioCapacitacaoPorParticipante(with(same(parametros))); |
||
| 56 | }}); |
||
| 57 | getRelatorioService().emitirRelatorioCapacitacaoPorParticipante(parametros); |
||
| 58 | } |
||
| 59 | |||
| 60 | @Test |
||
| 61 | public void aoEmitirRelatorioParticipantePorTurmaDeveriaDelegarParaOhGerador(){ |
||
| 62 | getContexto().checking(new Expectations(){{ |
||
| 63 | ignoring(getValidadorMock()).validar(with(any(ParametrosRelatorioCapacitacaoPorParticipante.class)), with(new Class<?>[]{Contexto.class})); |
||
| 64 | oneOf(getGeradorRelatorioMock()).emitirRelatorioParticipantePorTurma(with(any(ParametrosRelatorioParticipantePorTurma.class))); |
||
| 65 | }}); |
||
| 66 | getRelatorioService().emitirRelatorioParticipantePorTurma(new ParametrosRelatorioParticipantePorTurma()); |
||
| 67 | } |
||
| 68 | |||
| 69 | @Test |
||
| 70 | public void aoEmitirRelatorioParticipantePorTurmaDeveriaDelegarParaOhValidadorComContexto(){ |
||
| 71 | final ParametrosRelatorioParticipantePorTurma parametros = new ParametrosRelatorioParticipantePorTurma(); |
||
| 72 | getContexto().checking(new Expectations(){{ |
||
| 73 | oneOf(getValidadorMock()).validar(with(same(parametros)), with(new Class<?>[]{Contexto.class})); |
||
| 74 | ignoring(getGeradorRelatorioMock()).emitirRelatorioParticipantePorTurma(with(same(parametros))); |
||
| 75 | }}); |
||
| 76 | getRelatorioService().emitirRelatorioParticipantePorTurma(parametros); |
||
| 77 | } |
||
| 78 | |||
| 79 | @Test |
||
| 80 | public void aoEmitirRelatorioParticipantesFaltantesDeveriaDelegarParaOhGerador(){ |
||
| 81 | getContexto().checking(new Expectations(){{ |
||
| 82 | ignoring(getValidadorMock()).validar(with(any(ParametrosRelatorioParticipantesFaltantes.class)), with(new Class<?>[]{Contexto.class})); |
||
| 83 | oneOf(getGeradorRelatorioMock()).emitirRelatorioParticipantesFaltantes(with(any(ParametrosRelatorioParticipantesFaltantes.class))); |
||
| 84 | }}); |
||
| 85 | getRelatorioService().emitirRelatorioParticipantesFaltantes(new ParametrosRelatorioParticipantesFaltantes()); |
||
| 86 | } |
||
| 87 | |||
| 88 | @Test |
||
| 89 | public void aoEmitirRelatorioParticipantesFaltantesDeveriaDelegarParaOhValidadorComContexto(){ |
||
| 90 | final ParametrosRelatorioParticipantesFaltantes parametros = new ParametrosRelatorioParticipantesFaltantes(); |
||
| 91 | getContexto().checking(new Expectations(){{ |
||
| 92 | oneOf(getValidadorMock()).validar(with(same(parametros)), with(new Class<?>[]{Contexto.class})); |
||
| 93 | ignoring(getGeradorRelatorioMock()).emitirRelatorioParticipantesFaltantes(with(same(parametros))); |
||
| 94 | }}); |
||
| 95 | getRelatorioService().emitirRelatorioParticipantesFaltantes(parametros); |
||
| 96 | } |
||
| 97 | |||
| 98 | @Test |
||
| 99 | public void aoEmitirRelatorioCapacitacaoPorPeriodoDeveriaDelegarParaOhGerador(){ |
||
| 100 | getContexto().checking(new Expectations(){{ |
||
| 101 | ignoring(getValidadorMock()).validar(with(any(ParametrosRelatorioParticipantesFaltantes.class)), with(new Class<?>[]{Contexto.class})); |
||
| 102 | oneOf(getGeradorRelatorioMock()).emitirRelatorioCapacitacaoPorPeriodo(with(any(ParametrosRelatorioCapacitacaoPorPeriodo.class))); |
||
| 103 | }}); |
||
| 104 | getRelatorioService().emitirRelatorioCapacitacaoPorPeriodo(new ParametrosRelatorioCapacitacaoPorPeriodo()); |
||
| 105 | } |
||
| 106 | |||
| 107 | @Test |
||
| 108 | public void aoEmitirRelatorioCapacitacaoPorPeriodoDeveriaDelegarParaOhValidadorComContexto(){ |
||
| 109 | final ParametrosRelatorioCapacitacaoPorPeriodo parametros = new ParametrosRelatorioCapacitacaoPorPeriodo(); |
||
| 110 | getContexto().checking(new Expectations(){{ |
||
| 111 | oneOf(getValidadorMock()).validar(with(same(parametros)), with(new Class<?>[]{Contexto.class})); |
||
| 112 | ignoring(getGeradorRelatorioMock()).emitirRelatorioCapacitacaoPorPeriodo(with(same(parametros))); |
||
| 113 | }}); |
||
| 114 | getRelatorioService().emitirRelatorioCapacitacaoPorPeriodo(parametros); |
||
| 115 | } |
||
| 116 | |||
| 117 | @Test |
||
| 118 | public void aoEmitirRelatorioDespesasDeveriaDelegarParaOhGerador(){ |
||
| 119 | getContexto().checking(new Expectations(){{ |
||
| 120 | ignoring(getValidadorMock()).validar(with(any(ParametrosRelatorioDespesas.class)), with(new Class<?>[]{Contexto.class})); |
||
| 121 | oneOf(getGeradorRelatorioMock()).emitirRelatorioDespesas(with(any(ParametrosRelatorioDespesas.class))); |
||
| 122 | }}); |
||
| 123 | getRelatorioService().emitirRelatorioDespesas(new ParametrosRelatorioDespesas()); |
||
| 124 | } |
||
| 125 | |||
| 126 | @Test |
||
| 127 | public void aoEmitirRelatorioDespesasDeveriaDelegarParaOhValidadorComContexto(){ |
||
| 128 | final ParametrosRelatorioDespesas parametros = new ParametrosRelatorioDespesas(); |
||
| 129 | getContexto().checking(new Expectations(){{ |
||
| 130 | oneOf(getValidadorMock()).validar(with(same(parametros)), with(new Class<?>[]{Contexto.class})); |
||
| 131 | ignoring(getGeradorRelatorioMock()).emitirRelatorioDespesas(with(same(parametros))); |
||
| 132 | }}); |
||
| 133 | getRelatorioService().emitirRelatorioDespesas(parametros); |
||
| 134 | } |
||
| 135 | |||
| 136 | @Test |
||
| 137 | public void aoEmitirCertificadoDeveriaDelegarParaOhGerador(){ |
||
| 138 | getContexto().checking(new Expectations(){{ |
||
| 139 | oneOf(getGeradorRelatorioMock()).emitirCertificado(with(any(TurmaParticipante.class))); |
||
| 140 | }}); |
||
| 141 | getRelatorioService().emitirCertificado(new TurmaParticipante()); |
||
| 142 | } |
||
| 143 | |||
| 144 | @Test |
||
| 145 | public void aoEmitirCertificadoInformandoParticipanteNuloDeveriaLancarExcecao(){ |
||
| 146 | getContexto().checking(new Expectations(){{ |
||
| 147 | never(getGeradorRelatorioMock()).emitirCertificado(with(any(TurmaParticipante.class))); |
||
| 148 | }}); |
||
| 149 | VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() { |
||
| 150 | @Override |
||
| 151 | public void execute() throws Exception { |
||
| 152 | getRelatorioService().emitirCertificado(null); |
||
| 153 | } |
||
| 154 | }, MSG_OBRIGATORIO_INFORMAR_PARTICIPANTE); |
||
| 155 | } |
||
| 156 | |||
| 157 | public Validador getValidadorMock() { |
||
| 158 | return validadorMock; |
||
| 159 | } |
||
| 160 | |||
| 161 | public RelatorioService getRelatorioService() { |
||
| 162 | return relatorioService; |
||
| 163 | } |
||
| 164 | |||
| 165 | public GeradorRelatorio getGeradorRelatorioMock() { |
||
| 166 | return geradorRelatorioMock; |
||
| 167 | } |
||
| 168 | |||
| 169 | |||
| 170 | } |