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.PAPEL_COORDENADOR; |
||
| 4 | import static br.gov.al.saude.scs.constantes.ContantesScs.PAPEL_REPRESENTANTE; |
||
| 5 | import static br.gov.al.saude.test.ConstantesTestHelper.CINCO_ITENS; |
||
| 6 | import static br.gov.al.saude.test.ConstantesTestHelper.PRIMEIRO_REGISTRO; |
||
| 7 | import static br.gov.al.saude.test.ConstantesTestHelper.MensagensRetorno.MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO; |
||
| 8 | import static br.gov.al.saude.test.ConstantesTestHelper.OrgaoConstantes.CODIGO_ORGAO_SESAU; |
||
| 9 | import static br.gov.al.saude.test.ConstantesTestHelper.PessoaConstantes.SEQUENCIAL_PESSOA_BRUNO_LOPES_2; |
||
| 10 | import static br.gov.al.saude.test.ConstantesTestHelper.PessoaConstantes.SEQUENCIAL_PESSOA_ELIANE_LEITE_3; |
||
| 11 | import static br.gov.al.saude.test.ConstantesTestHelper.PessoaConstantes.SEQUENCIAL_PESSOA_ELIANE_MARIA_LEITE_3; |
||
| 12 | import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.ANO_EXERCICIO_2013; |
||
| 13 | import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.CARGA_HORARIA_0H; |
||
| 14 | import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.CARGA_HORARIA_110H; |
||
| 15 | import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.CARGA_HORARIA_32H; |
||
| 16 | import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.CARGA_HORARIA_36H; |
||
| 17 | import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.CARGA_HORARIA_48H; |
||
| 18 | import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.SEQUENCIAL_TURMA_1; |
||
| 19 | import static br.gov.al.saude.test.ConstantesTestHelper.TurmaParticipantesConstantes.INDICADOR_REMUNERADO_NAO; |
||
| 20 | import static br.gov.al.saude.test.ConstantesTestHelper.TurmaParticipantesConstantes.INDICADOR_REMUNERADO_SIM; |
||
| 21 | import static br.gov.al.saude.test.ConstantesTestHelper.TurmaProcessoConstantes.NUMERO_PROCESSO_77725; |
||
| 22 | import static br.gov.al.saude.test.util.ConversorDeTipo.FORMAT_DATE_DD_MM_YYYY_HH_MM_SS; |
||
| 23 | import static br.gov.al.saude.test.util.ConversorDeTipo.converterStringParaDate; |
||
| 24 | import static br.gov.al.saude.test.util.StringUtils.valueLong; |
||
| 25 | |||
| 26 | import java.util.ArrayList; |
||
| 27 | import java.util.HashSet; |
||
| 28 | import java.util.List; |
||
| 29 | import java.util.Set; |
||
| 30 | |||
| 31 | import org.jmock.Expectations; |
||
| 32 | import org.jmock.integration.junit4.JMock; |
||
| 33 | import org.junit.Before; |
||
| 34 | import org.junit.Test; |
||
| 35 | import org.junit.runner.RunWith; |
||
| 36 | |||
| 37 | import br.gov.al.saude.framework.core.consulta.restricao.Restricoes; |
||
| 38 | import br.gov.al.saude.framework.core.generic.GenericRepository; |
||
| 39 | import br.gov.al.saude.framework.core.generic.GenericService; |
||
| 40 | import br.gov.al.saude.framework.core.interfaces.Cadastrar; |
||
| 41 | import br.gov.al.saude.framework.core.interfaces.Contexto; |
||
| 42 | import br.gov.al.saude.framework.core.util.DataUtils; |
||
| 43 | import br.gov.al.saude.framework.core.validador.Validador; |
||
| 44 | import br.gov.al.saude.sca.model.usuario.view.UsuarioView; |
||
| 45 | import br.gov.al.saude.scg.model.view.PessoaFisicaView; |
||
| 46 | import br.gov.al.saude.scs.core.domain.turma.TurmaService; |
||
| 47 | import br.gov.al.saude.scs.core.domain.turma.impl.TurmaServiceImpl; |
||
| 48 | import br.gov.al.saude.scs.core.infrastructure.persistence.jpa.turma.TurmaRepository; |
||
| 49 | import br.gov.al.saude.scs.core.infrastructure.webservice.WsIntegraComponent; |
||
| 50 | import br.gov.al.saude.scs.model.Capacitacao; |
||
| 51 | import br.gov.al.saude.scs.model.Perfil; |
||
| 52 | import br.gov.al.saude.scs.model.Turma; |
||
| 53 | import br.gov.al.saude.scs.model.TurmaParticipante; |
||
| 54 | import br.gov.al.saude.scs.model.TurmaPeriodo; |
||
| 55 | import br.gov.al.saude.scs.model.dto.ConsultaTurmaDTO; |
||
| 56 | import br.gov.al.saude.scs.model.dto.ProcessoIntegraDTO; |
||
| 57 | import br.gov.al.saude.scs.model.dto.TurmaDTO; |
||
| 58 | import br.gov.al.saude.scs.parametros.ParametrosConsultarDespesasTurma; |
||
| 59 | import br.gov.al.saude.scs.parametros.ParametrosConsultarTurma; |
||
| 60 | import br.gov.al.saude.test.builder.CapacitacaoBuilder; |
||
| 61 | import br.gov.al.saude.test.builder.TurmaBuilder; |
||
| 62 | import br.gov.al.saude.test.builder.TurmaParticipanteBuilder; |
||
| 63 | import br.gov.al.saude.test.builder.TurmaPeriodoBuilder; |
||
| 64 | import br.gov.al.saude.test.builder.UsuarioViewBuilder; |
||
| 65 | import br.gov.al.saude.test.unidade.generic.service.ServiceImplTest; |
||
| 66 | import br.gov.al.saude.test.util.CommandSemMensagem; |
||
| 67 | import br.gov.al.saude.test.util.StringUtils; |
||
| 68 | import br.gov.al.saude.test.util.VerificadorLancamentoException; |
||
| 69 | |||
| 70 | @RunWith(JMock.class) |
||
| 71 | public class TurmaServiceImplTest extends ServiceImplTest<Turma> { |
||
| 72 | |||
| 73 | private TurmaService turmaService; |
||
| 74 | private TurmaRepository turmaRepositoryMock; |
||
| 75 | private WsIntegraComponent wsIntegraComponentMock; |
||
| 76 | |||
| 77 | @Before |
||
| 78 | public void inicializarContexto() { |
||
| 79 | super.inicializarContexto(); |
||
| 80 | turmaRepositoryMock = getContexto().mock(TurmaRepository.class); |
||
| 81 | wsIntegraComponentMock = getContexto().mock(WsIntegraComponent.class); |
||
| 82 | validadorMock = getContexto().mock(Validador.class); |
||
| 83 | turmaService = new TurmaServiceImpl(validadorMock, turmaRepositoryMock, wsIntegraComponentMock); |
||
| 84 | Turma turma = new Turma(); |
||
| 85 | Set<TurmaPeriodo> periodos = new HashSet<TurmaPeriodo>(); |
||
| 86 | TurmaPeriodo turmaPeriodo = new TurmaPeriodoBuilder() |
||
| 87 | .comDataInicial("01/10/2014 00:00:00") |
||
| 88 | .comDataFinal("31/10/2014 23:59:59") |
||
| 89 | .build(); |
||
| 90 | periodos.add(turmaPeriodo); |
||
| 91 | turma.setPeriodos(periodos); |
||
| 92 | setEntidade(turma); |
||
| 93 | } |
||
| 94 | |||
| 95 | @Override |
||
| 96 | protected GenericRepository<Turma> getRepositoryMock() { |
||
| 97 | return turmaRepositoryMock; |
||
| 98 | } |
||
| 99 | |||
| 100 | @Override |
||
| 101 | protected GenericService<Turma> getService() { |
||
| 102 | return turmaService; |
||
| 103 | } |
||
| 104 | |||
| 105 | @Test @SuppressWarnings("unchecked") |
||
| 106 | public void aoConsultarTurmaComConsultaTurmaDTODeveriaDelegarParaOhRepositorio() throws Exception { |
||
| 107 | final Capacitacao capacitacao = new CapacitacaoBuilder().comSequencial("1").build(); |
||
| 108 | final Turma turma = new TurmaBuilder().comSequencial("2").build(); |
||
| 109 | final Integer ano = StringUtils.valueInt("2013"); |
||
| 110 | |||
| 111 | ConsultaTurmaDTO consultaTurmaDTO = new ConsultaTurmaDTO(capacitacao, turma, ano); |
||
| 112 | |||
| 113 | getContexto().checking(new Expectations(){{ |
||
| 114 | oneOf(turmaRepositoryMock).consultarTurmaComPeriodosPassandoRestricoes(with(any(Turma.class)), with(any(Integer.class)), with(any(Integer.class)), with(any(List.class))); |
||
| 115 | will(returnValue(with(any(List.class)))); |
||
| 116 | }}); |
||
| 117 | turmaService.consultarTurma(PRIMEIRO_REGISTRO, CINCO_ITENS, consultaTurmaDTO); |
||
| 118 | } |
||
| 119 | |||
| 120 | @Test @SuppressWarnings("unchecked") |
||
| 121 | public void aoConsultarTurmaComConsultaTurmaDTOParametrosNulosDeveriaDelegarParaOhRepositorio() throws Exception { |
||
| 122 | final Capacitacao capacitacao = null; |
||
| 123 | final Turma turma = null; |
||
| 124 | final Integer ano = null; |
||
| 125 | |||
| 126 | ConsultaTurmaDTO consultaTurmaDTO = new ConsultaTurmaDTO(capacitacao, turma, ano); |
||
| 127 | |||
| 128 | getContexto().checking(new Expectations(){{ |
||
| 129 | oneOf(turmaRepositoryMock).consultarTurmaComPeriodosPassandoRestricoes(with(any(Turma.class)), with(any(Integer.class)), with(any(Integer.class)), with(any(List.class))); |
||
| 130 | will(returnValue(with(any(List.class)))); |
||
| 131 | }}); |
||
| 132 | turmaService.consultarTurma(PRIMEIRO_REGISTRO, CINCO_ITENS, consultaTurmaDTO); |
||
| 133 | } |
||
| 134 | |||
| 135 | @Test |
||
| 136 | public void aoObterQuantidadeDeRegistrosConsultarTurmaInformandoCapacitacaoDeveriaDelegarParaOhRepositorio(){ |
||
| 137 | Capacitacao capacitacao = new Capacitacao(); |
||
| 138 | final List<Restricoes> restricoes = new ArrayList<Restricoes>(); |
||
| 139 | restricoes.add(Restricoes.igual("capacitacao", capacitacao)); |
||
| 140 | getContexto().checking(new Expectations(){{ |
||
| 141 | oneOf(turmaRepositoryMock).obterQuantidadeDeRegistrosConsultarTurmaComPeriodosPassandoRestricoes(with(restricoes)); |
||
| 142 | will(returnValue(with(any(Integer.class)))); |
||
| 143 | }}); |
||
| 144 | turmaService.obterQuantidadeDeRegistrosConsultarTurma(new ConsultaTurmaDTO(capacitacao, null, null)); |
||
| 145 | } |
||
| 146 | |||
| 147 | @Test |
||
| 148 | public void aoObterQuantidadeDeRegistrosConsultarTurmaInformandoTurmaDeveriaDelegarParaOhRepositorio(){ |
||
| 149 | Turma turma = new TurmaBuilder().comSequencial("1").build(); |
||
| 150 | final List<Restricoes> restricoes = new ArrayList<Restricoes>(); |
||
| 151 | restricoes.add(Restricoes.igual("sequencial", turma.getSequencial())); |
||
| 152 | getContexto().checking(new Expectations(){{ |
||
| 153 | oneOf(turmaRepositoryMock).obterQuantidadeDeRegistrosConsultarTurmaComPeriodosPassandoRestricoes(with(restricoes)); |
||
| 154 | will(returnValue(with(any(Integer.class)))); |
||
| 155 | }}); |
||
| 156 | turmaService.obterQuantidadeDeRegistrosConsultarTurma(new ConsultaTurmaDTO(null, turma, null)); |
||
| 157 | } |
||
| 158 | |||
| 159 | @Test |
||
| 160 | public void aoObterQuantidadeDeRegistrosConsultarTurmaInformandoAnoDeveriaDelegarParaOhRepositorio(){ |
||
| 161 | Integer ano = new Integer("1"); |
||
| 162 | final List<Restricoes> restricoes = new ArrayList<Restricoes>(); |
||
| 163 | restricoes.add(Restricoes.igual("anoExercicio", ano)); |
||
| 164 | getContexto().checking(new Expectations(){{ |
||
| 165 | oneOf(turmaRepositoryMock).obterQuantidadeDeRegistrosConsultarTurmaComPeriodosPassandoRestricoes(with(restricoes)); |
||
| 166 | will(returnValue(with(any(Integer.class)))); |
||
| 167 | }}); |
||
| 168 | turmaService.obterQuantidadeDeRegistrosConsultarTurma(new ConsultaTurmaDTO(null, null, ano)); |
||
| 169 | } |
||
| 170 | |||
| 171 | @Test |
||
| 172 | public void aoObterQuantidadeDeRegistrosConsultarTurmaSemInformarParametrosDeveriaDelegarParaOhRepositorio(){ |
||
| 173 | final List<Restricoes> restricoes = new ArrayList<Restricoes>(); |
||
| 174 | getContexto().checking(new Expectations(){{ |
||
| 175 | oneOf(turmaRepositoryMock).obterQuantidadeDeRegistrosConsultarTurmaComPeriodosPassandoRestricoes(with(restricoes)); |
||
| 176 | will(returnValue(with(any(Integer.class)))); |
||
| 177 | }}); |
||
| 178 | turmaService.obterQuantidadeDeRegistrosConsultarTurma(new ConsultaTurmaDTO(null, null, null)); |
||
| 179 | } |
||
| 180 | |||
| 181 | @Test |
||
| 182 | public void aoConsultarTurmaDtoInformandoUsuarioComPapelCoordenadorDeveriaDelegarParaOhRepositorio(){ |
||
| 183 | UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_COORDENADOR).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build(); |
||
| 184 | final ParametrosConsultarTurma parametros = new ParametrosConsultarTurma(usuarioLogado, null, null, null, null, null); |
||
| 185 | final Long sequencialPessoaRepresentante = null; |
||
| 186 | getContexto().checking(new Expectations(){{ |
||
| 187 | oneOf(turmaRepositoryMock).consultarTurmaDTO(with(same(parametros)), with(same(sequencialPessoaRepresentante))); |
||
| 188 | will(returnValue(new ArrayList<TurmaDTO>())); |
||
| 189 | }}); |
||
| 190 | turmaService.consultarTurmaDTO(parametros); |
||
| 191 | } |
||
| 192 | |||
| 193 | @Test |
||
| 194 | public void aoConsultarTurmaDtoInformandoUsuarioComPapelRepresentanteDeveriaDelegarParaOhRepositorio(){ |
||
| 195 | UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_REPRESENTANTE).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build(); |
||
| 196 | final ParametrosConsultarTurma parametros = new ParametrosConsultarTurma(usuarioLogado, null, null, null, null, null); |
||
| 197 | final Long sequencialPessoaRepresentante = usuarioLogado.getSequencialPessoa(); |
||
| 198 | getContexto().checking(new Expectations(){{ |
||
| 199 | oneOf(turmaRepositoryMock).consultarTurmaDTO(with(same(parametros)), with(same(sequencialPessoaRepresentante))); |
||
| 200 | will(returnValue(new ArrayList<TurmaDTO>())); |
||
| 201 | }}); |
||
| 202 | turmaService.consultarTurmaDTO(parametros); |
||
| 203 | } |
||
| 204 | |||
| 205 | @Test |
||
| 206 | public void aoConsultarTurmaDtoInformandoUsuarioSemPapelRepresentanteOuCoordenadorDeveriaNaoDelegarParaOhRepositorio(){ |
||
| 207 | UsuarioView usuarioLogado = new UsuarioViewBuilder().comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build(); |
||
| 208 | final ParametrosConsultarTurma parametros = new ParametrosConsultarTurma(usuarioLogado, null, null, null, null, null); |
||
| 209 | getContexto().checking(new Expectations(){{ |
||
| 210 | never(turmaRepositoryMock).consultarTurmaDTO(with(any(ParametrosConsultarTurma.class)), with(any(Long.class))); |
||
| 211 | }}); |
||
| 212 | turmaService.consultarTurmaDTO(parametros); |
||
| 213 | } |
||
| 214 | |||
| 215 | @Test |
||
| 216 | public void aoObterQuantidadeRegistrosConsultarTurmaDtoInformandoUsuarioComPapelCoordenadorDeveriaDelegarParaOhRepositorio(){ |
||
| 217 | UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_COORDENADOR).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build(); |
||
| 218 | final ParametrosConsultarTurma parametros = new ParametrosConsultarTurma(usuarioLogado, null, null, null, null, null); |
||
| 219 | final Long sequencialPessoaRepresentante = null; |
||
| 220 | getContexto().checking(new Expectations(){{ |
||
| 221 | oneOf(turmaRepositoryMock).obterQuantidadeRegistrosConsultarTurmaDTO(with(same(parametros)), with(same(sequencialPessoaRepresentante))); |
||
| 222 | will(returnValue(with(any(Integer.class)))); |
||
| 223 | }}); |
||
| 224 | turmaService.obterQuantidadeRegistrosConsultarTurmaDTO(parametros); |
||
| 225 | } |
||
| 226 | |||
| 227 | @Test |
||
| 228 | public void aoObterQuantidadeRegistrosConsultarTurmaDtoInformandoUsuarioComPapelRepresentanteDeveriaDelegarParaOhRepositorio(){ |
||
| 229 | UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_REPRESENTANTE).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build(); |
||
| 230 | final ParametrosConsultarTurma parametros = new ParametrosConsultarTurma(usuarioLogado, null, null, null, null, null); |
||
| 231 | final Long sequencialPessoaRepresentante = usuarioLogado.getSequencialPessoa(); |
||
| 232 | getContexto().checking(new Expectations(){{ |
||
| 233 | oneOf(turmaRepositoryMock).obterQuantidadeRegistrosConsultarTurmaDTO(with(same(parametros)), with(same(sequencialPessoaRepresentante))); |
||
| 234 | will(returnValue(with(any(Integer.class)))); |
||
| 235 | }}); |
||
| 236 | turmaService.obterQuantidadeRegistrosConsultarTurmaDTO(parametros); |
||
| 237 | } |
||
| 238 | |||
| 239 | @Test |
||
| 240 | public void aoObterQuantidadeRegistrosConsultarTurmaDtoInformandoUsuarioSemPapelRepresentanteOuCoordenadorDeveriaNaoDelegarParaOhRepositorio(){ |
||
| 241 | UsuarioView usuarioLogado = new UsuarioViewBuilder().comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build(); |
||
| 242 | final ParametrosConsultarTurma parametros = new ParametrosConsultarTurma(usuarioLogado, null, null, null, null, null); |
||
| 243 | getContexto().checking(new Expectations(){{ |
||
| 244 | never(turmaRepositoryMock).obterQuantidadeRegistrosConsultarTurmaDTO(with(any(ParametrosConsultarTurma.class)), with(any(Long.class))); |
||
| 245 | }}); |
||
| 246 | turmaService.obterQuantidadeRegistrosConsultarTurmaDTO(parametros); |
||
| 247 | } |
||
| 248 | |||
| 249 | @Test |
||
| 250 | public void aoCadastrarTurmaComDataInicialPosteriorAhDataFinalDeveriaLancarExcecao() throws Exception{ |
||
| 251 | Set<TurmaPeriodo> periodos = new HashSet<TurmaPeriodo>(); |
||
| 252 | TurmaPeriodo turmaPeriodo = new TurmaPeriodoBuilder().comDataInicial("31/10/2014 00:00:00") |
||
| 253 | .comDataFinal("01/10/2014 23:59:59").build(); |
||
| 254 | periodos.add(turmaPeriodo); |
||
| 255 | getEntidade().setPeriodos(periodos); |
||
| 256 | getContexto().checking(new Expectations(){{ |
||
| 257 | ignoring(getValidadorMock()).validar(with(same(getEntidade())), with(new Class<?>[]{Cadastrar.class})); |
||
| 258 | never(getRepositoryMock()).cadastrar(with(same(getEntidade()))); |
||
| 259 | }}); |
||
| 260 | VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() { |
||
| 261 | @Override |
||
| 262 | public void execute() throws Exception { |
||
| 263 | getService().cadastrar(getEntidade()); |
||
| 264 | } |
||
| 265 | }, TurmaService.MENSAGEM_DATA_INICIAL_DO_PERIODO_NAO_PODE_SER_POSTERIOR_A_DATA_FINAL); |
||
| 266 | } |
||
| 267 | |||
| 268 | @Test |
||
| 269 | public void aoConsultarPessoaDeveriaDelegarParaOhRepositorio() throws Exception { |
||
| 270 | getContexto().checking(new Expectations(){{ |
||
| 271 | oneOf(turmaRepositoryMock).consultarPessoa(with(any(Long.class))); |
||
| 272 | will(returnValue(with(any(PessoaFisicaView.class)))); |
||
| 273 | }}); |
||
| 274 | turmaService.consultarPessoa(1l); |
||
| 275 | } |
||
| 276 | |||
| 277 | @Test |
||
| 278 | public void aoListarOrgaoDeveriaDelegarParaOhRepositorio() throws Exception { |
||
| 279 | getContexto().checking(new Expectations(){{ |
||
| 280 | oneOf(turmaRepositoryMock).listarOrgaos(); |
||
| 281 | will(returnValue(with(any(List.class)))); |
||
| 282 | }}); |
||
| 283 | turmaService.listarOrgaos(); |
||
| 284 | } |
||
| 285 | |||
| 286 | @Test |
||
| 287 | public void aoVerificarAlertasDoParticipanteDeveriaDelegarParaOhRepositorio() throws Exception { |
||
| 288 | getContexto().checking(new Expectations(){{ |
||
| 289 | oneOf(turmaRepositoryMock).verificarSeParticipanteOrganizadorJaUltrapassouCargaHorariaRemunerada120Horas(with(any(Long.class))); |
||
| 290 | will(returnValue(with(any(Boolean.class)))); |
||
| 291 | }}); |
||
| 292 | turmaService.verificarAlertasDoParticipante(1l); |
||
| 293 | } |
||
| 294 | |||
| 295 | @Test |
||
| 296 | public void aoVerificarAlertasDoParticipanteComHorasUltrapassadasDeveriaLancarExcecao() throws Exception { |
||
| 297 | getContexto().checking(new Expectations(){{ |
||
| 298 | oneOf(turmaRepositoryMock).verificarSeParticipanteOrganizadorJaUltrapassouCargaHorariaRemunerada120Horas(with(any(Long.class))); |
||
| 299 | will(returnValue(true)); |
||
| 300 | }}); |
||
| 301 | VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() { |
||
| 302 | @Override |
||
| 303 | public void execute() throws Exception { |
||
| 304 | turmaService.verificarAlertasDoParticipante(1l); |
||
| 305 | } |
||
| 306 | }, TurmaService.MENSAGEM_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO); |
||
| 307 | } |
||
| 308 | |||
| 309 | @Test |
||
| 310 | public void aoVerificarRestricoesDoParticipanteComUsuarioCoordenadorNaoDeveriaLancarExcecao() throws Exception { |
||
| 311 | UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_COORDENADOR).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build(); |
||
| 312 | DataUtils.setDataAtualParaOsTestes(converterStringParaDate("05/07/2013 00:00:00", FORMAT_DATE_DD_MM_YYYY_HH_MM_SS)); |
||
| 313 | getContexto().checking(new Expectations(){{ |
||
| 314 | never(turmaRepositoryMock).consultarDataUltimaAusenciaPessoaParticipante(with(any(TurmaParticipante.class))); |
||
| 315 | }}); |
||
| 316 | turmaService.verificarFaltasDoParticipante(usuarioLogado, new TurmaParticipante()); |
||
| 317 | } |
||
| 318 | |||
| 319 | @Test |
||
| 320 | public void aoVerificarRestricoesDoParticipanteComUsuarioRepresentanteDeveriaLancarExcecao() throws Exception { |
||
| 321 | final UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_REPRESENTANTE).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build(); |
||
| 322 | DataUtils.setDataAtualParaOsTestes(converterStringParaDate("05/07/2013 00:00:00", FORMAT_DATE_DD_MM_YYYY_HH_MM_SS)); |
||
| 323 | getContexto().checking(new Expectations(){{ |
||
| 324 | oneOf(turmaRepositoryMock).consultarDataUltimaAusenciaPessoaParticipante(with(any(TurmaParticipante.class))); |
||
| 325 | will(returnValue(converterStringParaDate("02/07/2013 00:00:00", FORMAT_DATE_DD_MM_YYYY_HH_MM_SS))); |
||
| 326 | }}); |
||
| 327 | VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() { |
||
| 328 | @Override |
||
| 329 | public void execute() throws Exception { |
||
| 330 | turmaService.verificarFaltasDoParticipante(usuarioLogado, new TurmaParticipante()); |
||
| 331 | } |
||
| 332 | }, TurmaService.MENSAGEM_PARTICIPANTE_NAO_PODERA_SER_INSERIDO_EM_TURMAS_FAVOR_CONSULTAR_GERENCIA_DE_EDUCACAO_EM_SAUDE_GESTAO_DE_PESSOAS_ATRAVES_DO_TELEFONE_3315_1476_PARA_OUTRAS_INFORMACOES); |
||
| 333 | } |
||
| 334 | |||
| 335 | @Test |
||
| 336 | public void aoVerificarRestricoesDoParticipanteComUsuarioRepresentanteComDataUltimaAusenciaAnteriorAhDataAtualMenosUltimos6MesesNaoDeveriaLancarExcecao() throws Exception { |
||
| 337 | final UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_REPRESENTANTE).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build(); |
||
| 338 | DataUtils.setDataAtualParaOsTestes(converterStringParaDate("05/07/2013 00:00:00", FORMAT_DATE_DD_MM_YYYY_HH_MM_SS)); |
||
| 339 | getContexto().checking(new Expectations(){{ |
||
| 340 | oneOf(turmaRepositoryMock).consultarDataUltimaAusenciaPessoaParticipante(with(any(TurmaParticipante.class))); |
||
| 341 | will(returnValue(converterStringParaDate("02/01/2013 00:00:00", FORMAT_DATE_DD_MM_YYYY_HH_MM_SS))); |
||
| 342 | }}); |
||
| 343 | turmaService.verificarFaltasDoParticipante(usuarioLogado, new TurmaParticipante()); |
||
| 344 | } |
||
| 345 | |||
| 346 | @Test |
||
| 347 | public void aoDetalharTurmaComProcessoDeveriaDelegarParaOhRepositorio() throws Exception { |
||
| 348 | final Turma turma = new TurmaBuilder() |
||
| 349 | .comSequencial(SEQUENCIAL_TURMA_1) |
||
| 350 | .comProcessos(SEQUENCIAL_TURMA_1 + "," + |
||
| 351 | CODIGO_ORGAO_SESAU + "," + |
||
| 352 | NUMERO_PROCESSO_77725 + "," + |
||
| 353 | ANO_EXERCICIO_2013) |
||
| 354 | .build(); |
||
| 355 | getContexto().checking(new Expectations(){{ |
||
| 356 | oneOf(turmaRepositoryMock).detalharTurma(with(valueLong(SEQUENCIAL_TURMA_1))); |
||
| 357 | will(returnValue(turma)); |
||
| 358 | oneOf(turmaRepositoryMock).consultarElementosDespesa(with(any(ParametrosConsultarDespesasTurma.class))); |
||
| 359 | }}); |
||
| 360 | turmaService.detalharTurma(valueLong(SEQUENCIAL_TURMA_1)); |
||
| 361 | } |
||
| 362 | |||
| 363 | @Test |
||
| 364 | public void aoDetalharTurmaSemProcessoDeveriaDelegarParaOhRepositorio() throws Exception { |
||
| 365 | getContexto().checking(new Expectations(){{ |
||
| 366 | oneOf(turmaRepositoryMock).detalharTurma(with(valueLong(SEQUENCIAL_TURMA_1))); |
||
| 367 | never(turmaRepositoryMock).consultarElementosDespesa(with(any(ParametrosConsultarDespesasTurma.class))); |
||
| 368 | }}); |
||
| 369 | turmaService.detalharTurma(valueLong(SEQUENCIAL_TURMA_1)); |
||
| 370 | } |
||
| 371 | |||
| 372 | @Test |
||
| 373 | public void aoConsultarTurmaComParticipantesDeveriaDelegarParaOhRepositorio() throws Exception { |
||
| 374 | getContexto().checking(new Expectations(){{ |
||
| 375 | oneOf(turmaRepositoryMock).consultarTurmaComParticipantes(with(any(Long.class))); |
||
| 376 | will(returnValue(with(any(Turma.class)))); |
||
| 377 | }}); |
||
| 378 | turmaService.consultarTurmaComParticipantes(1L); |
||
| 379 | } |
||
| 380 | |||
| 381 | @Test |
||
| 382 | public void aoConsultarDespesasTurmaDeveriaDelegarParaOhRepositorio() throws Exception{ |
||
| 383 | getContexto().checking(new Expectations(){{ |
||
| 384 | oneOf(getValidadorMock()).validar(with(any(ParametrosConsultarDespesasTurma.class)), with(new Class<?>[]{Contexto.class})); |
||
| 385 | oneOf(turmaRepositoryMock).consultarElementosDespesa(with(any(ParametrosConsultarDespesasTurma.class))); |
||
| 386 | oneOf(wsIntegraComponentMock).consultarProcessoIntegra(with(any(Integer.class)), with(any(String.class)), with(any(Integer.class))); |
||
| 387 | will(returnValue(new ProcessoIntegraDTO())); |
||
| 388 | }}); |
||
| 389 | turmaService.consultarDespesasTurma(new ParametrosConsultarDespesasTurma()); |
||
| 390 | } |
||
| 391 | |||
| 392 | @Test |
||
| 393 | public void aoConsultarDespesasTurmaDeveriaDelegarParaOhValidadorComContexto() throws Exception { |
||
| 394 | getContexto().checking(new Expectations(){{ |
||
| 395 | oneOf(getValidadorMock()).validar(with(any(ParametrosConsultarDespesasTurma.class)), with(new Class<?>[]{Contexto.class})); |
||
| 396 | ignoring(turmaRepositoryMock).consultarElementosDespesa(with(any(ParametrosConsultarDespesasTurma.class))); |
||
| 397 | ignoring(wsIntegraComponentMock).consultarProcessoIntegra(with(any(Integer.class)), with(any(String.class)), with(any(Integer.class))); |
||
| 398 | will(returnValue(new ProcessoIntegraDTO())); |
||
| 399 | }}); |
||
| 400 | turmaService.consultarDespesasTurma(new ParametrosConsultarDespesasTurma()); |
||
| 401 | } |
||
| 402 | |||
| 403 | @Test |
||
| 404 | public void aoConsultarIndicadorDeServidorDeveriaDelegarParaOhRepositorio() throws Exception{ |
||
| 405 | getContexto().checking(new Expectations(){{ |
||
| 406 | oneOf(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class))); |
||
| 407 | }}); |
||
| 408 | turmaService.consultarIndicadorDeServidor(new PessoaFisicaView()); |
||
| 409 | } |
||
| 410 | |||
| 411 | @Test |
||
| 412 | public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteQueNaoEhServidorDeveriaNaoLancarExcecao() throws Exception{ |
||
| 413 | getContexto().checking(new Expectations(){{ |
||
| 414 | one(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class))); |
||
| 415 | will(returnValue(false)); |
||
| 416 | never(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class))); |
||
| 417 | }}); |
||
| 418 | turmaService.verificarAlertaDeRestricaoDoParticipante(new TurmaParticipante(), new ArrayList<TurmaParticipante>()); |
||
| 419 | } |
||
| 420 | |||
| 421 | @Test |
||
| 422 | public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilOrganizadorIhAnoValidoIhPossuiCargaHorariaMenorQueCentoEhVinteDeveriaNaoLancarExcecao() throws Exception{ |
||
| 423 | Perfil perfil = new Perfil(); |
||
| 424 | perfil.setIndicadorOrganizador(true); |
||
| 425 | Turma turma = new TurmaBuilder().comAnoExercicio(ANO_EXERCICIO_2013).build(); |
||
| 426 | TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder() |
||
| 427 | .comTurma(turma) |
||
| 428 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 429 | .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2) |
||
| 430 | .comPerfil(perfil) |
||
| 431 | .comCargaHorariaEspecifica(CARGA_HORARIA_36H) |
||
| 432 | .build(); |
||
| 433 | TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder() |
||
| 434 | .comTurma(turma) |
||
| 435 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 436 | .comPessoa(SEQUENCIAL_PESSOA_ELIANE_MARIA_LEITE_3) |
||
| 437 | .comPerfil(perfil) |
||
| 438 | .comCargaHorariaEspecifica(CARGA_HORARIA_110H) |
||
| 439 | .build(); |
||
| 440 | List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>(); |
||
| 441 | participantes.add(turmaParticipante1); |
||
| 442 | participantes.add(turmaParticipante2); |
||
| 443 | getContexto().checking(new Expectations(){{ |
||
| 444 | allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class))); |
||
| 445 | will(returnValue(true)); |
||
| 446 | oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class))); |
||
| 447 | will(returnValue(65)); |
||
| 448 | }}); |
||
| 449 | turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes); |
||
| 450 | } |
||
| 451 | |||
| 452 | @Test |
||
| 453 | public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilOrganizadorIhAnoValidoIhPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{ |
||
| 454 | Perfil perfil = new Perfil(); |
||
| 455 | perfil.setIndicadorOrganizador(true); |
||
| 456 | Turma turma = new TurmaBuilder().comAnoExercicio(ANO_EXERCICIO_2013).build(); |
||
| 457 | final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder() |
||
| 458 | .comTurma(turma) |
||
| 459 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 460 | .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2) |
||
| 461 | .comPerfil(perfil) |
||
| 462 | .comCargaHorariaEspecifica(CARGA_HORARIA_32H) |
||
| 463 | .build(); |
||
| 464 | TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder() |
||
| 465 | .comTurma(turma) |
||
| 466 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 467 | .comPessoa(SEQUENCIAL_PESSOA_ELIANE_LEITE_3) |
||
| 468 | .comPerfil(perfil) |
||
| 469 | .comCargaHorariaEspecifica(CARGA_HORARIA_0H) |
||
| 470 | .build(); |
||
| 471 | final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>(); |
||
| 472 | participantes.add(turmaParticipante1); |
||
| 473 | participantes.add(turmaParticipante2); |
||
| 474 | getContexto().checking(new Expectations(){{ |
||
| 475 | allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class))); |
||
| 476 | will(returnValue(true)); |
||
| 477 | oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class))); |
||
| 478 | will(returnValue(100)); |
||
| 479 | }}); |
||
| 480 | VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() { |
||
| 481 | @Override |
||
| 482 | public void execute() throws Exception { |
||
| 483 | turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes); |
||
| 484 | } |
||
| 485 | }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO); |
||
| 486 | } |
||
| 487 | |||
| 488 | @Test |
||
| 489 | public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilOrganizadorIhAnoValidoIhCapturandoCargaHorariaDaTurmaPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{ |
||
| 490 | Perfil perfil = new Perfil(); |
||
| 491 | perfil.setIndicadorOrganizador(true); |
||
| 492 | Turma turma = new TurmaBuilder() |
||
| 493 | .comCargaHoraria(CARGA_HORARIA_36H) |
||
| 494 | .comAnoExercicio(ANO_EXERCICIO_2013) |
||
| 495 | .build(); |
||
| 496 | final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder() |
||
| 497 | .comTurma(turma) |
||
| 498 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 499 | .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2) |
||
| 500 | .comPerfil(perfil) |
||
| 501 | .build(); |
||
| 502 | TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder() |
||
| 503 | .comTurma(turma) |
||
| 504 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 505 | .comPessoa(SEQUENCIAL_PESSOA_ELIANE_LEITE_3) |
||
| 506 | .comPerfil(perfil) |
||
| 507 | .comCargaHorariaEspecifica(CARGA_HORARIA_0H) |
||
| 508 | .build(); |
||
| 509 | final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>(); |
||
| 510 | participantes.add(turmaParticipante1); |
||
| 511 | participantes.add(turmaParticipante2); |
||
| 512 | getContexto().checking(new Expectations(){{ |
||
| 513 | allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class))); |
||
| 514 | will(returnValue(true)); |
||
| 515 | oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class))); |
||
| 516 | will(returnValue(100)); |
||
| 517 | }}); |
||
| 518 | VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() { |
||
| 519 | @Override |
||
| 520 | public void execute() throws Exception { |
||
| 521 | turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes); |
||
| 522 | } |
||
| 523 | }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO); |
||
| 524 | } |
||
| 525 | |||
| 526 | @Test |
||
| 527 | public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilOrganizadorIhAnoValidoIhCapturandoCargaHorariaVaziaDaTurmaPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{ |
||
| 528 | Perfil perfil = new Perfil(); |
||
| 529 | perfil.setIndicadorOrganizador(true); |
||
| 530 | Turma turma = new TurmaBuilder() |
||
| 531 | .comAnoExercicio(ANO_EXERCICIO_2013) |
||
| 532 | .build(); |
||
| 533 | final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder() |
||
| 534 | .comTurma(turma) |
||
| 535 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 536 | .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2) |
||
| 537 | .comPerfil(perfil) |
||
| 538 | .build(); |
||
| 539 | TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder() |
||
| 540 | .comTurma(turma) |
||
| 541 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 542 | .comPessoa(SEQUENCIAL_PESSOA_ELIANE_LEITE_3) |
||
| 543 | .comPerfil(perfil) |
||
| 544 | .comCargaHorariaEspecifica(CARGA_HORARIA_0H) |
||
| 545 | .build(); |
||
| 546 | final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>(); |
||
| 547 | participantes.add(turmaParticipante1); |
||
| 548 | participantes.add(turmaParticipante2); |
||
| 549 | getContexto().checking(new Expectations(){{ |
||
| 550 | allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class))); |
||
| 551 | will(returnValue(true)); |
||
| 552 | oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class))); |
||
| 553 | will(returnValue(150)); |
||
| 554 | }}); |
||
| 555 | VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() { |
||
| 556 | @Override |
||
| 557 | public void execute() throws Exception { |
||
| 558 | turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes); |
||
| 559 | } |
||
| 560 | }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO); |
||
| 561 | } |
||
| 562 | |||
| 563 | @Test |
||
| 564 | public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhNaoRemuneradoIhPerfilOrganizadorIhAnoValidoIhPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{ |
||
| 565 | Perfil perfil = new Perfil(); |
||
| 566 | perfil.setIndicadorOrganizador(true); |
||
| 567 | Turma turma = new TurmaBuilder().comAnoExercicio(ANO_EXERCICIO_2013).build(); |
||
| 568 | final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder() |
||
| 569 | .comTurma(turma) |
||
| 570 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_NAO) |
||
| 571 | .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2) |
||
| 572 | .comPerfil(perfil) |
||
| 573 | .comCargaHorariaEspecifica(CARGA_HORARIA_32H) |
||
| 574 | .build(); |
||
| 575 | TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder() |
||
| 576 | .comTurma(turma) |
||
| 577 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_NAO) |
||
| 578 | .comPessoa(SEQUENCIAL_PESSOA_ELIANE_LEITE_3) |
||
| 579 | .comPerfil(perfil) |
||
| 580 | .comCargaHorariaEspecifica(CARGA_HORARIA_0H) |
||
| 581 | .build(); |
||
| 582 | final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>(); |
||
| 583 | participantes.add(turmaParticipante1); |
||
| 584 | participantes.add(turmaParticipante2); |
||
| 585 | getContexto().checking(new Expectations(){{ |
||
| 586 | allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class))); |
||
| 587 | will(returnValue(true)); |
||
| 588 | oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class))); |
||
| 589 | will(returnValue(125)); |
||
| 590 | }}); |
||
| 591 | VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() { |
||
| 592 | @Override |
||
| 593 | public void execute() throws Exception { |
||
| 594 | turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes); |
||
| 595 | } |
||
| 596 | }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO); |
||
| 597 | } |
||
| 598 | |||
| 599 | @Test |
||
| 600 | public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilNaoOrganizadorIhAnoValidoIhPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{ |
||
| 601 | Perfil perfil = new Perfil(); |
||
| 602 | perfil.setIndicadorOrganizador(false); |
||
| 603 | Turma turma = new TurmaBuilder().comAnoExercicio(ANO_EXERCICIO_2013).build(); |
||
| 604 | final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder() |
||
| 605 | .comTurma(turma) |
||
| 606 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 607 | .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2) |
||
| 608 | .comPerfil(perfil) |
||
| 609 | .comCargaHorariaEspecifica(CARGA_HORARIA_32H) |
||
| 610 | .build(); |
||
| 611 | TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder() |
||
| 612 | .comTurma(turma) |
||
| 613 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 614 | .comPessoa(SEQUENCIAL_PESSOA_ELIANE_LEITE_3) |
||
| 615 | .comPerfil(perfil) |
||
| 616 | .comCargaHorariaEspecifica(CARGA_HORARIA_0H) |
||
| 617 | .build(); |
||
| 618 | final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>(); |
||
| 619 | participantes.add(turmaParticipante1); |
||
| 620 | participantes.add(turmaParticipante2); |
||
| 621 | getContexto().checking(new Expectations(){{ |
||
| 622 | allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class))); |
||
| 623 | will(returnValue(true)); |
||
| 624 | oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class))); |
||
| 625 | will(returnValue(125)); |
||
| 626 | }}); |
||
| 627 | VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() { |
||
| 628 | @Override |
||
| 629 | public void execute() throws Exception { |
||
| 630 | turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes); |
||
| 631 | } |
||
| 632 | }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO); |
||
| 633 | } |
||
| 634 | |||
| 635 | @Test |
||
| 636 | public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilOrganizadorIhAnoValidoIhListaComParticipanteNaoServidorIhPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{ |
||
| 637 | Perfil perfil = new Perfil(); |
||
| 638 | perfil.setIndicadorOrganizador(true); |
||
| 639 | Turma turma = new TurmaBuilder() |
||
| 640 | .comAnoExercicio(ANO_EXERCICIO_2013) |
||
| 641 | .comCargaHoraria(CARGA_HORARIA_48H) |
||
| 642 | .build(); |
||
| 643 | final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder() |
||
| 644 | .comTurma(turma) |
||
| 645 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 646 | .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2) |
||
| 647 | .comPerfil(perfil) |
||
| 648 | .build(); |
||
| 649 | final TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder() |
||
| 650 | .comTurma(turma) |
||
| 651 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 652 | .comPessoa(SEQUENCIAL_PESSOA_ELIANE_LEITE_3) |
||
| 653 | .comPerfil(perfil) |
||
| 654 | .comCargaHorariaEspecifica(CARGA_HORARIA_0H) |
||
| 655 | .build(); |
||
| 656 | final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>(); |
||
| 657 | participantes.add(turmaParticipante1); |
||
| 658 | participantes.add(turmaParticipante2); |
||
| 659 | getContexto().checking(new Expectations(){{ |
||
| 660 | allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(same(turmaParticipante1.getPessoa()))); |
||
| 661 | will(returnValue(true)); |
||
| 662 | oneOf(turmaRepositoryMock).consultarIndicadorDeServidor(with(same(turmaParticipante2.getPessoa()))); |
||
| 663 | will(returnValue(false)); |
||
| 664 | oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class))); |
||
| 665 | will(returnValue(100)); |
||
| 666 | }}); |
||
| 667 | VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() { |
||
| 668 | @Override |
||
| 669 | public void execute() throws Exception { |
||
| 670 | turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes); |
||
| 671 | } |
||
| 672 | }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO); |
||
| 673 | } |
||
| 674 | |||
| 675 | @Test |
||
| 676 | public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilOrganizadorIhSemInformarAnoIhPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{ |
||
| 677 | Perfil perfil = new Perfil(); |
||
| 678 | perfil.setIndicadorOrganizador(true); |
||
| 679 | Turma turma = new TurmaBuilder().build(); |
||
| 680 | final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder() |
||
| 681 | .comTurma(turma) |
||
| 682 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 683 | .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2) |
||
| 684 | .comPerfil(perfil) |
||
| 685 | .comCargaHorariaEspecifica(CARGA_HORARIA_110H) |
||
| 686 | .build(); |
||
| 687 | TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder() |
||
| 688 | .comTurma(turma) |
||
| 689 | .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM) |
||
| 690 | .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2) |
||
| 691 | .comPerfil(perfil) |
||
| 692 | .comCargaHorariaEspecifica(CARGA_HORARIA_110H) |
||
| 693 | .build(); |
||
| 694 | final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>(); |
||
| 695 | participantes.add(turmaParticipante1); |
||
| 696 | participantes.add(turmaParticipante2); |
||
| 697 | getContexto().checking(new Expectations(){{ |
||
| 698 | allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class))); |
||
| 699 | will(returnValue(true)); |
||
| 700 | oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class))); |
||
| 701 | will(returnValue(0)); |
||
| 702 | |||
| 703 | }}); |
||
| 704 | VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() { |
||
| 705 | @Override |
||
| 706 | public void execute() throws Exception { |
||
| 707 | turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes); |
||
| 708 | } |
||
| 709 | }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO); |
||
| 710 | } |
||
| 711 | |||
| 712 | } |