Subversion Repositories Integrator Subversion

Rev

Blame | Last modification | View Log | Download | RSS feed

package br.gov.al.saude.scs.core.domain;

import static br.gov.al.saude.scs.constantes.ContantesScs.PAPEL_COORDENADOR;
import static br.gov.al.saude.scs.constantes.ContantesScs.PAPEL_REPRESENTANTE;
import static br.gov.al.saude.test.ConstantesTestHelper.CINCO_ITENS;
import static br.gov.al.saude.test.ConstantesTestHelper.PRIMEIRO_REGISTRO;
import static br.gov.al.saude.test.ConstantesTestHelper.MensagensRetorno.MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO;
import static br.gov.al.saude.test.ConstantesTestHelper.OrgaoConstantes.CODIGO_ORGAO_SESAU;
import static br.gov.al.saude.test.ConstantesTestHelper.PessoaConstantes.SEQUENCIAL_PESSOA_BRUNO_LOPES_2;
import static br.gov.al.saude.test.ConstantesTestHelper.PessoaConstantes.SEQUENCIAL_PESSOA_ELIANE_LEITE_3;
import static br.gov.al.saude.test.ConstantesTestHelper.PessoaConstantes.SEQUENCIAL_PESSOA_ELIANE_MARIA_LEITE_3;
import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.ANO_EXERCICIO_2013;
import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.CARGA_HORARIA_0H;
import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.CARGA_HORARIA_110H;
import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.CARGA_HORARIA_32H;
import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.CARGA_HORARIA_36H;
import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.CARGA_HORARIA_48H;
import static br.gov.al.saude.test.ConstantesTestHelper.TurmaConstantes.SEQUENCIAL_TURMA_1;
import static br.gov.al.saude.test.ConstantesTestHelper.TurmaParticipantesConstantes.INDICADOR_REMUNERADO_NAO;
import static br.gov.al.saude.test.ConstantesTestHelper.TurmaParticipantesConstantes.INDICADOR_REMUNERADO_SIM;
import static br.gov.al.saude.test.ConstantesTestHelper.TurmaProcessoConstantes.NUMERO_PROCESSO_77725;
import static br.gov.al.saude.test.util.ConversorDeTipo.FORMAT_DATE_DD_MM_YYYY_HH_MM_SS;
import static br.gov.al.saude.test.util.ConversorDeTipo.converterStringParaDate;
import static br.gov.al.saude.test.util.StringUtils.valueLong;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.jmock.Expectations;
import org.jmock.integration.junit4.JMock;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import br.gov.al.saude.framework.core.consulta.restricao.Restricoes;
import br.gov.al.saude.framework.core.generic.GenericRepository;
import br.gov.al.saude.framework.core.generic.GenericService;
import br.gov.al.saude.framework.core.interfaces.Cadastrar;
import br.gov.al.saude.framework.core.interfaces.Contexto;
import br.gov.al.saude.framework.core.util.DataUtils;
import br.gov.al.saude.framework.core.validador.Validador;
import br.gov.al.saude.sca.model.usuario.view.UsuarioView;
import br.gov.al.saude.scg.model.view.PessoaFisicaView;
import br.gov.al.saude.scs.core.domain.turma.TurmaService;
import br.gov.al.saude.scs.core.domain.turma.impl.TurmaServiceImpl;
import br.gov.al.saude.scs.core.infrastructure.persistence.jpa.turma.TurmaRepository;
import br.gov.al.saude.scs.core.infrastructure.webservice.WsIntegraComponent;
import br.gov.al.saude.scs.model.Capacitacao;
import br.gov.al.saude.scs.model.Perfil;
import br.gov.al.saude.scs.model.Turma;
import br.gov.al.saude.scs.model.TurmaParticipante;
import br.gov.al.saude.scs.model.TurmaPeriodo;
import br.gov.al.saude.scs.model.dto.ConsultaTurmaDTO;
import br.gov.al.saude.scs.model.dto.ProcessoIntegraDTO;
import br.gov.al.saude.scs.model.dto.TurmaDTO;
import br.gov.al.saude.scs.parametros.ParametrosConsultarDespesasTurma;
import br.gov.al.saude.scs.parametros.ParametrosConsultarTurma;
import br.gov.al.saude.test.builder.CapacitacaoBuilder;
import br.gov.al.saude.test.builder.TurmaBuilder;
import br.gov.al.saude.test.builder.TurmaParticipanteBuilder;
import br.gov.al.saude.test.builder.TurmaPeriodoBuilder;
import br.gov.al.saude.test.builder.UsuarioViewBuilder;
import br.gov.al.saude.test.unidade.generic.service.ServiceImplTest;
import br.gov.al.saude.test.util.CommandSemMensagem;
import br.gov.al.saude.test.util.StringUtils;
import br.gov.al.saude.test.util.VerificadorLancamentoException;

@RunWith(JMock.class)
public class TurmaServiceImplTest extends ServiceImplTest<Turma> {
       
        private TurmaService turmaService;
        private TurmaRepository turmaRepositoryMock;
        private WsIntegraComponent wsIntegraComponentMock;
       
        @Before
        public void inicializarContexto() {
                super.inicializarContexto();
                turmaRepositoryMock = getContexto().mock(TurmaRepository.class);
                wsIntegraComponentMock = getContexto().mock(WsIntegraComponent.class);
                validadorMock = getContexto().mock(Validador.class);
                turmaService = new TurmaServiceImpl(validadorMock, turmaRepositoryMock, wsIntegraComponentMock);
                Turma turma = new Turma();
                Set<TurmaPeriodo> periodos = new HashSet<TurmaPeriodo>();
                TurmaPeriodo turmaPeriodo = new TurmaPeriodoBuilder()
                                                                                .comDataInicial("01/10/2014 00:00:00")
                                                                                .comDataFinal("31/10/2014 23:59:59")
                                                                                .build();
                periodos.add(turmaPeriodo);
                turma.setPeriodos(periodos);
                setEntidade(turma);
        }

        @Override
        protected GenericRepository<Turma> getRepositoryMock() {
                return turmaRepositoryMock;
        }

        @Override
        protected GenericService<Turma> getService() {
                return turmaService;
        }
       
        @Test @SuppressWarnings("unchecked")
        public void aoConsultarTurmaComConsultaTurmaDTODeveriaDelegarParaOhRepositorio() throws Exception {
                final Capacitacao capacitacao = new CapacitacaoBuilder().comSequencial("1").build();
                final Turma turma = new TurmaBuilder().comSequencial("2").build();
                final Integer ano = StringUtils.valueInt("2013");
               
                ConsultaTurmaDTO consultaTurmaDTO = new ConsultaTurmaDTO(capacitacao, turma, ano);
               
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).consultarTurmaComPeriodosPassandoRestricoes(with(any(Turma.class)), with(any(Integer.class)), with(any(Integer.class)), with(any(List.class)));
                        will(returnValue(with(any(List.class))));
                }});
                turmaService.consultarTurma(PRIMEIRO_REGISTRO, CINCO_ITENS, consultaTurmaDTO);
        }
       
        @Test @SuppressWarnings("unchecked")
        public void aoConsultarTurmaComConsultaTurmaDTOParametrosNulosDeveriaDelegarParaOhRepositorio() throws Exception {
                final Capacitacao capacitacao = null;
                final Turma turma = null;
                final Integer ano = null;
               
                ConsultaTurmaDTO consultaTurmaDTO = new ConsultaTurmaDTO(capacitacao, turma, ano);
               
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).consultarTurmaComPeriodosPassandoRestricoes(with(any(Turma.class)), with(any(Integer.class)), with(any(Integer.class)), with(any(List.class)));
                        will(returnValue(with(any(List.class))));
                }});
                turmaService.consultarTurma(PRIMEIRO_REGISTRO, CINCO_ITENS, consultaTurmaDTO);
        }
       
        @Test
        public void aoObterQuantidadeDeRegistrosConsultarTurmaInformandoCapacitacaoDeveriaDelegarParaOhRepositorio(){
                Capacitacao capacitacao = new Capacitacao();
                final List<Restricoes> restricoes = new ArrayList<Restricoes>();
                restricoes.add(Restricoes.igual("capacitacao", capacitacao));
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).obterQuantidadeDeRegistrosConsultarTurmaComPeriodosPassandoRestricoes(with(restricoes));
                        will(returnValue(with(any(Integer.class))));
                }});
                turmaService.obterQuantidadeDeRegistrosConsultarTurma(new ConsultaTurmaDTO(capacitacao, null, null));
        }
       
        @Test
        public void aoObterQuantidadeDeRegistrosConsultarTurmaInformandoTurmaDeveriaDelegarParaOhRepositorio(){
                Turma turma = new TurmaBuilder().comSequencial("1").build();
                final List<Restricoes> restricoes = new ArrayList<Restricoes>();
                restricoes.add(Restricoes.igual("sequencial", turma.getSequencial()));
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).obterQuantidadeDeRegistrosConsultarTurmaComPeriodosPassandoRestricoes(with(restricoes));
                        will(returnValue(with(any(Integer.class))));
                }});
                turmaService.obterQuantidadeDeRegistrosConsultarTurma(new ConsultaTurmaDTO(null, turma, null));
        }
       
        @Test
        public void aoObterQuantidadeDeRegistrosConsultarTurmaInformandoAnoDeveriaDelegarParaOhRepositorio(){
                Integer ano = new Integer("1");
                final List<Restricoes> restricoes = new ArrayList<Restricoes>();
                restricoes.add(Restricoes.igual("anoExercicio", ano));
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).obterQuantidadeDeRegistrosConsultarTurmaComPeriodosPassandoRestricoes(with(restricoes));
                        will(returnValue(with(any(Integer.class))));
                }});
                turmaService.obterQuantidadeDeRegistrosConsultarTurma(new ConsultaTurmaDTO(null, null, ano));
        }
       
        @Test
        public void aoObterQuantidadeDeRegistrosConsultarTurmaSemInformarParametrosDeveriaDelegarParaOhRepositorio(){
                final List<Restricoes> restricoes = new ArrayList<Restricoes>();
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).obterQuantidadeDeRegistrosConsultarTurmaComPeriodosPassandoRestricoes(with(restricoes));
                        will(returnValue(with(any(Integer.class))));
                }});
                turmaService.obterQuantidadeDeRegistrosConsultarTurma(new ConsultaTurmaDTO(null, null, null));
        }
       
        @Test
        public void aoConsultarTurmaDtoInformandoUsuarioComPapelCoordenadorDeveriaDelegarParaOhRepositorio(){
                UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_COORDENADOR).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build();
                final ParametrosConsultarTurma parametros = new ParametrosConsultarTurma(usuarioLogado, null, null, null, null, null);
                final Long sequencialPessoaRepresentante = null;
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).consultarTurmaDTO(with(same(parametros)), with(same(sequencialPessoaRepresentante)));
                        will(returnValue(new ArrayList<TurmaDTO>()));
                }});
                turmaService.consultarTurmaDTO(parametros);
        }
       
        @Test
        public void aoConsultarTurmaDtoInformandoUsuarioComPapelRepresentanteDeveriaDelegarParaOhRepositorio(){
                UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_REPRESENTANTE).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build();
                final ParametrosConsultarTurma parametros = new ParametrosConsultarTurma(usuarioLogado, null, null, null, null, null);
                final Long sequencialPessoaRepresentante = usuarioLogado.getSequencialPessoa();
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).consultarTurmaDTO(with(same(parametros)), with(same(sequencialPessoaRepresentante)));
                        will(returnValue(new ArrayList<TurmaDTO>()));
                }});
                turmaService.consultarTurmaDTO(parametros);
        }
       
        @Test
        public void aoConsultarTurmaDtoInformandoUsuarioSemPapelRepresentanteOuCoordenadorDeveriaNaoDelegarParaOhRepositorio(){
                UsuarioView usuarioLogado = new UsuarioViewBuilder().comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build();
                final ParametrosConsultarTurma parametros = new ParametrosConsultarTurma(usuarioLogado, null, null, null, null, null);
                getContexto().checking(new Expectations(){{
                        never(turmaRepositoryMock).consultarTurmaDTO(with(any(ParametrosConsultarTurma.class)), with(any(Long.class)));
                }});
                turmaService.consultarTurmaDTO(parametros);
        }
       
        @Test
        public void aoObterQuantidadeRegistrosConsultarTurmaDtoInformandoUsuarioComPapelCoordenadorDeveriaDelegarParaOhRepositorio(){
                UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_COORDENADOR).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build();
                final ParametrosConsultarTurma parametros = new ParametrosConsultarTurma(usuarioLogado, null, null, null, null, null);
                final Long sequencialPessoaRepresentante = null;
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).obterQuantidadeRegistrosConsultarTurmaDTO(with(same(parametros)), with(same(sequencialPessoaRepresentante)));
                        will(returnValue(with(any(Integer.class))));
                }});
                turmaService.obterQuantidadeRegistrosConsultarTurmaDTO(parametros);
        }
       
        @Test
        public void aoObterQuantidadeRegistrosConsultarTurmaDtoInformandoUsuarioComPapelRepresentanteDeveriaDelegarParaOhRepositorio(){
                UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_REPRESENTANTE).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build();
                final ParametrosConsultarTurma parametros = new ParametrosConsultarTurma(usuarioLogado, null, null, null, null, null);
                final Long sequencialPessoaRepresentante = usuarioLogado.getSequencialPessoa();
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).obterQuantidadeRegistrosConsultarTurmaDTO(with(same(parametros)), with(same(sequencialPessoaRepresentante)));
                        will(returnValue(with(any(Integer.class))));
                }});
                turmaService.obterQuantidadeRegistrosConsultarTurmaDTO(parametros);
        }
       
        @Test
        public void aoObterQuantidadeRegistrosConsultarTurmaDtoInformandoUsuarioSemPapelRepresentanteOuCoordenadorDeveriaNaoDelegarParaOhRepositorio(){
                UsuarioView usuarioLogado = new UsuarioViewBuilder().comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build();
                final ParametrosConsultarTurma parametros = new ParametrosConsultarTurma(usuarioLogado, null, null, null, null, null);
                getContexto().checking(new Expectations(){{
                        never(turmaRepositoryMock).obterQuantidadeRegistrosConsultarTurmaDTO(with(any(ParametrosConsultarTurma.class)), with(any(Long.class)));
                }});
                turmaService.obterQuantidadeRegistrosConsultarTurmaDTO(parametros);
        }
       
        @Test
        public void aoCadastrarTurmaComDataInicialPosteriorAhDataFinalDeveriaLancarExcecao() throws Exception{
                Set<TurmaPeriodo> periodos = new HashSet<TurmaPeriodo>();
                TurmaPeriodo turmaPeriodo = new TurmaPeriodoBuilder().comDataInicial("31/10/2014 00:00:00")
                                .comDataFinal("01/10/2014 23:59:59").build();
                periodos.add(turmaPeriodo);
                getEntidade().setPeriodos(periodos);
                getContexto().checking(new Expectations(){{
                        ignoring(getValidadorMock()).validar(with(same(getEntidade())), with(new Class<?>[]{Cadastrar.class}));
                        never(getRepositoryMock()).cadastrar(with(same(getEntidade())));
                }});
                VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() {
                        @Override
                        public void execute() throws Exception {
                                getService().cadastrar(getEntidade());
                        }
                }, TurmaService.MENSAGEM_DATA_INICIAL_DO_PERIODO_NAO_PODE_SER_POSTERIOR_A_DATA_FINAL);
        }
       
        @Test
        public void aoConsultarPessoaDeveriaDelegarParaOhRepositorio() throws Exception {
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).consultarPessoa(with(any(Long.class)));
                        will(returnValue(with(any(PessoaFisicaView.class))));
                }});
                turmaService.consultarPessoa(1l);
        }
       
        @Test
        public void aoListarOrgaoDeveriaDelegarParaOhRepositorio() throws Exception {
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).listarOrgaos();
                        will(returnValue(with(any(List.class))));
                }});
                turmaService.listarOrgaos();
        }
         
        @Test
        public void aoVerificarAlertasDoParticipanteDeveriaDelegarParaOhRepositorio() throws Exception {
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).verificarSeParticipanteOrganizadorJaUltrapassouCargaHorariaRemunerada120Horas(with(any(Long.class)));
                        will(returnValue(with(any(Boolean.class))));
                }});
                turmaService.verificarAlertasDoParticipante(1l);
        }
       
        @Test
        public void aoVerificarAlertasDoParticipanteComHorasUltrapassadasDeveriaLancarExcecao() throws Exception {
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).verificarSeParticipanteOrganizadorJaUltrapassouCargaHorariaRemunerada120Horas(with(any(Long.class)));
                        will(returnValue(true));
                }});
                VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() {
                        @Override
                        public void execute() throws Exception {
                                turmaService.verificarAlertasDoParticipante(1l);
                        }
                }, TurmaService.MENSAGEM_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO);
        }
       
        @Test
        public void aoVerificarRestricoesDoParticipanteComUsuarioCoordenadorNaoDeveriaLancarExcecao() throws Exception {
                UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_COORDENADOR).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build();
                DataUtils.setDataAtualParaOsTestes(converterStringParaDate("05/07/2013 00:00:00", FORMAT_DATE_DD_MM_YYYY_HH_MM_SS));
                getContexto().checking(new Expectations(){{
                        never(turmaRepositoryMock).consultarDataUltimaAusenciaPessoaParticipante(with(any(TurmaParticipante.class)));
                }});
                turmaService.verificarFaltasDoParticipante(usuarioLogado, new TurmaParticipante());
        }
       
        @Test
        public void aoVerificarRestricoesDoParticipanteComUsuarioRepresentanteDeveriaLancarExcecao() throws Exception {
                final UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_REPRESENTANTE).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build();
                DataUtils.setDataAtualParaOsTestes(converterStringParaDate("05/07/2013 00:00:00", FORMAT_DATE_DD_MM_YYYY_HH_MM_SS));
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).consultarDataUltimaAusenciaPessoaParticipante(with(any(TurmaParticipante.class)));
                        will(returnValue(converterStringParaDate("02/07/2013 00:00:00", FORMAT_DATE_DD_MM_YYYY_HH_MM_SS)));
                }});
                VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() {
                        @Override
                        public void execute() throws Exception {
                                turmaService.verificarFaltasDoParticipante(usuarioLogado, new TurmaParticipante());
                        }
                }, 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);
        }
       
        @Test
        public void aoVerificarRestricoesDoParticipanteComUsuarioRepresentanteComDataUltimaAusenciaAnteriorAhDataAtualMenosUltimos6MesesNaoDeveriaLancarExcecao() throws Exception {
                final UsuarioView usuarioLogado = new UsuarioViewBuilder().comRole(PAPEL_REPRESENTANTE).comSequencial(SEQUENCIAL_PESSOA_BRUNO_LOPES_2).build();
                DataUtils.setDataAtualParaOsTestes(converterStringParaDate("05/07/2013 00:00:00", FORMAT_DATE_DD_MM_YYYY_HH_MM_SS));
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).consultarDataUltimaAusenciaPessoaParticipante(with(any(TurmaParticipante.class)));
                        will(returnValue(converterStringParaDate("02/01/2013 00:00:00", FORMAT_DATE_DD_MM_YYYY_HH_MM_SS)));
                }});
                turmaService.verificarFaltasDoParticipante(usuarioLogado, new TurmaParticipante());
        }
       
        @Test
        public void aoDetalharTurmaComProcessoDeveriaDelegarParaOhRepositorio() throws Exception {
                final Turma turma = new TurmaBuilder()
                                                                .comSequencial(SEQUENCIAL_TURMA_1)
                                                                .comProcessos(SEQUENCIAL_TURMA_1 + "," +
                                                                                          CODIGO_ORGAO_SESAU + "," +
                                                                                          NUMERO_PROCESSO_77725 + "," +
                                                                                          ANO_EXERCICIO_2013)
                                                            .build();
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).detalharTurma(with(valueLong(SEQUENCIAL_TURMA_1)));
                        will(returnValue(turma));
                        oneOf(turmaRepositoryMock).consultarElementosDespesa(with(any(ParametrosConsultarDespesasTurma.class)));
                }});
                turmaService.detalharTurma(valueLong(SEQUENCIAL_TURMA_1));
        }
       
        @Test
        public void aoDetalharTurmaSemProcessoDeveriaDelegarParaOhRepositorio() throws Exception {
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).detalharTurma(with(valueLong(SEQUENCIAL_TURMA_1)));
                        never(turmaRepositoryMock).consultarElementosDespesa(with(any(ParametrosConsultarDespesasTurma.class)));
                }});
                turmaService.detalharTurma(valueLong(SEQUENCIAL_TURMA_1));
        }
       
        @Test
        public void aoConsultarTurmaComParticipantesDeveriaDelegarParaOhRepositorio() throws Exception {
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).consultarTurmaComParticipantes(with(any(Long.class)));
                        will(returnValue(with(any(Turma.class))));
                }});
                turmaService.consultarTurmaComParticipantes(1L);
        }
       
        @Test
        public void aoConsultarDespesasTurmaDeveriaDelegarParaOhRepositorio() throws Exception{
                getContexto().checking(new Expectations(){{
                        oneOf(getValidadorMock()).validar(with(any(ParametrosConsultarDespesasTurma.class)), with(new Class<?>[]{Contexto.class}));
                        oneOf(turmaRepositoryMock).consultarElementosDespesa(with(any(ParametrosConsultarDespesasTurma.class)));
                        oneOf(wsIntegraComponentMock).consultarProcessoIntegra(with(any(Integer.class)), with(any(String.class)), with(any(Integer.class)));
                        will(returnValue(new ProcessoIntegraDTO()));
                }});
                turmaService.consultarDespesasTurma(new ParametrosConsultarDespesasTurma());
        }
       
        @Test
        public void aoConsultarDespesasTurmaDeveriaDelegarParaOhValidadorComContexto() throws Exception {
                getContexto().checking(new Expectations(){{
                        oneOf(getValidadorMock()).validar(with(any(ParametrosConsultarDespesasTurma.class)), with(new Class<?>[]{Contexto.class}));
                        ignoring(turmaRepositoryMock).consultarElementosDespesa(with(any(ParametrosConsultarDespesasTurma.class)));
                        ignoring(wsIntegraComponentMock).consultarProcessoIntegra(with(any(Integer.class)), with(any(String.class)), with(any(Integer.class)));
                        will(returnValue(new ProcessoIntegraDTO()));
                }});
                turmaService.consultarDespesasTurma(new ParametrosConsultarDespesasTurma());
        }
       
        @Test
        public void aoConsultarIndicadorDeServidorDeveriaDelegarParaOhRepositorio() throws Exception{
                getContexto().checking(new Expectations(){{
                        oneOf(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class)));
                }});
                turmaService.consultarIndicadorDeServidor(new PessoaFisicaView());
        }
       
        @Test
        public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteQueNaoEhServidorDeveriaNaoLancarExcecao() throws Exception{
                getContexto().checking(new Expectations(){{
                        one(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class)));
                        will(returnValue(false));
                        never(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class)));
                }});
                turmaService.verificarAlertaDeRestricaoDoParticipante(new TurmaParticipante(), new ArrayList<TurmaParticipante>());
        }
       
        @Test
        public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilOrganizadorIhAnoValidoIhPossuiCargaHorariaMenorQueCentoEhVinteDeveriaNaoLancarExcecao() throws Exception{
                Perfil perfil = new Perfil();
                perfil.setIndicadorOrganizador(true);
                Turma turma = new TurmaBuilder().comAnoExercicio(ANO_EXERCICIO_2013).build();
                TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder()
                                                                                                   .comTurma(turma)
                                                                                                   .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                   .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2)
                                                                                                   .comPerfil(perfil)
                                                                                                   .comCargaHorariaEspecifica(CARGA_HORARIA_36H)
                                                                                                   .build();
                TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder()
                                                                                                   .comTurma(turma)
                                                                                                   .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                   .comPessoa(SEQUENCIAL_PESSOA_ELIANE_MARIA_LEITE_3)
                                                                                                   .comPerfil(perfil)
                                                                                                   .comCargaHorariaEspecifica(CARGA_HORARIA_110H)
                                                                                                   .build();
                List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>();
                participantes.add(turmaParticipante1);
                participantes.add(turmaParticipante2);
                getContexto().checking(new Expectations(){{
                        allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class)));
                        will(returnValue(true));
                        oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class)));
                        will(returnValue(65));
                }});
                turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes);
        }
       
        @Test
        public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilOrganizadorIhAnoValidoIhPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{
                Perfil perfil = new Perfil();
                perfil.setIndicadorOrganizador(true);
                Turma turma = new TurmaBuilder().comAnoExercicio(ANO_EXERCICIO_2013).build();
                final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder()
                                                                                                                 .comTurma(turma)
                                                                                                                 .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                                 .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2)
                                                                                                                 .comPerfil(perfil)
                                                                                                                 .comCargaHorariaEspecifica(CARGA_HORARIA_32H)
                                                                                                                 .build();
                TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder()
                                                                                                   .comTurma(turma)
                                                                                                   .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                   .comPessoa(SEQUENCIAL_PESSOA_ELIANE_LEITE_3)
                                                                                                   .comPerfil(perfil)
                                                                                                   .comCargaHorariaEspecifica(CARGA_HORARIA_0H)
                                                                                                   .build();
                final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>();
                participantes.add(turmaParticipante1);
                participantes.add(turmaParticipante2);
                getContexto().checking(new Expectations(){{
                        allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class)));
                        will(returnValue(true));
                        oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class)));
                        will(returnValue(100));
                }});
                VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() {
                        @Override
                        public void execute() throws Exception {
                                turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes);
                        }
                }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO);
        }
       
        @Test
        public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilOrganizadorIhAnoValidoIhCapturandoCargaHorariaDaTurmaPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{
                Perfil perfil = new Perfil();
                perfil.setIndicadorOrganizador(true);
                Turma turma = new TurmaBuilder()
                                                  .comCargaHoraria(CARGA_HORARIA_36H)
                                                  .comAnoExercicio(ANO_EXERCICIO_2013)
                                                  .build();
                final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder()
                                                                                                                 .comTurma(turma)
                                                                                                                 .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                                 .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2)
                                                                                                                 .comPerfil(perfil)
                                                                                                                 .build();
                TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder()
                                                                                                   .comTurma(turma)
                                                                                                   .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                   .comPessoa(SEQUENCIAL_PESSOA_ELIANE_LEITE_3)
                                                                                                   .comPerfil(perfil)
                                                                                                   .comCargaHorariaEspecifica(CARGA_HORARIA_0H)
                                                                                                   .build();
                final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>();
                participantes.add(turmaParticipante1);
                participantes.add(turmaParticipante2);
                getContexto().checking(new Expectations(){{
                        allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class)));
                        will(returnValue(true));
                        oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class)));
                        will(returnValue(100));
                }});
                VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() {
                        @Override
                        public void execute() throws Exception {
                                turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes);
                        }
                }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO);
        }
       
        @Test
        public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilOrganizadorIhAnoValidoIhCapturandoCargaHorariaVaziaDaTurmaPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{
                Perfil perfil = new Perfil();
                perfil.setIndicadorOrganizador(true);
                Turma turma = new TurmaBuilder()
                                                  .comAnoExercicio(ANO_EXERCICIO_2013)
                                                  .build();
                final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder()
                                                                                                                 .comTurma(turma)
                                                                                                                 .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                                 .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2)
                                                                                                                 .comPerfil(perfil)
                                                                                                                 .build();
                TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder()
                                                                                                   .comTurma(turma)
                                                                                                   .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                   .comPessoa(SEQUENCIAL_PESSOA_ELIANE_LEITE_3)
                                                                                                   .comPerfil(perfil)
                                                                                                   .comCargaHorariaEspecifica(CARGA_HORARIA_0H)
                                                                                                   .build();
                final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>();
                participantes.add(turmaParticipante1);
                participantes.add(turmaParticipante2);
                getContexto().checking(new Expectations(){{
                        allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class)));
                        will(returnValue(true));
                        oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class)));
                        will(returnValue(150));
                }});
                VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() {
                        @Override
                        public void execute() throws Exception {
                                turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes);
                        }
                }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO);
        }
       
        @Test
        public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhNaoRemuneradoIhPerfilOrganizadorIhAnoValidoIhPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{
                Perfil perfil = new Perfil();
                perfil.setIndicadorOrganizador(true);
                Turma turma = new TurmaBuilder().comAnoExercicio(ANO_EXERCICIO_2013).build();
                final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder()
                                                                                                                 .comTurma(turma)
                                                                                                                 .comIndicadorRemunerado(INDICADOR_REMUNERADO_NAO)
                                                                                                                 .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2)
                                                                                                                 .comPerfil(perfil)
                                                                                                                 .comCargaHorariaEspecifica(CARGA_HORARIA_32H)
                                                                                                                 .build();
                TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder()
                                                                                                   .comTurma(turma)
                                                                                                   .comIndicadorRemunerado(INDICADOR_REMUNERADO_NAO)
                                                                                                   .comPessoa(SEQUENCIAL_PESSOA_ELIANE_LEITE_3)
                                                                                                   .comPerfil(perfil)
                                                                                                   .comCargaHorariaEspecifica(CARGA_HORARIA_0H)
                                                                                                   .build();
                final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>();
                participantes.add(turmaParticipante1);
                participantes.add(turmaParticipante2);
                getContexto().checking(new Expectations(){{
                        allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class)));
                        will(returnValue(true));
                        oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class)));
                        will(returnValue(125));
                }});
                VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() {
                        @Override
                        public void execute() throws Exception {
                                turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes);
                        }
                }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO);
        }
       
        @Test
        public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilNaoOrganizadorIhAnoValidoIhPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{
                Perfil perfil = new Perfil();
                perfil.setIndicadorOrganizador(false);
                Turma turma = new TurmaBuilder().comAnoExercicio(ANO_EXERCICIO_2013).build();
                final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder()
                                                                                                                 .comTurma(turma)
                                                                                                                 .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                                 .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2)
                                                                                                                 .comPerfil(perfil)
                                                                                                                 .comCargaHorariaEspecifica(CARGA_HORARIA_32H)
                                                                                                                 .build();
                TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder()
                                                                                                   .comTurma(turma)
                                                                                                   .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                   .comPessoa(SEQUENCIAL_PESSOA_ELIANE_LEITE_3)
                                                                                                   .comPerfil(perfil)
                                                                                                   .comCargaHorariaEspecifica(CARGA_HORARIA_0H)
                                                                                                   .build();
                final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>();
                participantes.add(turmaParticipante1);
                participantes.add(turmaParticipante2);
                getContexto().checking(new Expectations(){{
                        allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class)));
                        will(returnValue(true));
                        oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class)));
                        will(returnValue(125));
                }});
                VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() {
                        @Override
                        public void execute() throws Exception {
                                turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes);
                        }
                }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO);
        }
       
        @Test
        public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilOrganizadorIhAnoValidoIhListaComParticipanteNaoServidorIhPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{
                Perfil perfil = new Perfil();
                perfil.setIndicadorOrganizador(true);
                Turma turma = new TurmaBuilder()
                                                  .comAnoExercicio(ANO_EXERCICIO_2013)
                                                  .comCargaHoraria(CARGA_HORARIA_48H)
                                                  .build();
                final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder()
                                                                                                                 .comTurma(turma)
                                                                                                                 .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                                 .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2)
                                                                                                                 .comPerfil(perfil)
                                                                                                                 .build();
                final TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder()
                                                                                                             .comTurma(turma)
                                                                                                             .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                                 .comPessoa(SEQUENCIAL_PESSOA_ELIANE_LEITE_3)
                                                                                                                 .comPerfil(perfil)
                                                                                                                 .comCargaHorariaEspecifica(CARGA_HORARIA_0H)
                                                                                                                 .build();
                final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>();
                participantes.add(turmaParticipante1);
                participantes.add(turmaParticipante2);
                getContexto().checking(new Expectations(){{
                        allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(same(turmaParticipante1.getPessoa())));
                        will(returnValue(true));
                        oneOf(turmaRepositoryMock).consultarIndicadorDeServidor(with(same(turmaParticipante2.getPessoa())));
                        will(returnValue(false));
                        oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class)));
                        will(returnValue(100));
                }});
                VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() {
                        @Override
                        public void execute() throws Exception {
                                turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes);
                        }
                }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO);
        }
       
        @Test
        public void aoVerificarAlertaDeRestricaoDoParticipanteInformandoParticipanteServidorIhRemuneradoIhPerfilOrganizadorIhSemInformarAnoIhPossuiCargaHorariaMaiorQueCentoEhVinteDeveriaLancarExcecao() throws Exception{
                Perfil perfil = new Perfil();
                perfil.setIndicadorOrganizador(true);
                Turma turma = new TurmaBuilder().build();
                final TurmaParticipante turmaParticipante1 = new TurmaParticipanteBuilder()
                                                                                                                 .comTurma(turma)
                                                                                                                 .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                                 .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2)
                                                                                                                 .comPerfil(perfil)
                                                                                                                 .comCargaHorariaEspecifica(CARGA_HORARIA_110H)
                                                                                                                 .build();
                TurmaParticipante turmaParticipante2 = new TurmaParticipanteBuilder()
                                                                                                   .comTurma(turma)
                                                                                                   .comIndicadorRemunerado(INDICADOR_REMUNERADO_SIM)
                                                                                                   .comPessoa(SEQUENCIAL_PESSOA_BRUNO_LOPES_2)
                                                                                                   .comPerfil(perfil)
                                                                                                   .comCargaHorariaEspecifica(CARGA_HORARIA_110H)
                                                                                                   .build();
                final List<TurmaParticipante> participantes = new ArrayList<TurmaParticipante>();
                participantes.add(turmaParticipante1);
                participantes.add(turmaParticipante2);
                getContexto().checking(new Expectations(){{
                        allowing(turmaRepositoryMock).consultarIndicadorDeServidor(with(any(PessoaFisicaView.class)));
                        will(returnValue(true));
                        oneOf(turmaRepositoryMock).consultarCargaHorariaRemunerada(with(any(Long.class)), with(any(Turma.class)));
                        will(returnValue(0));
                       
                }});
                VerificadorLancamentoException.verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem() {
                        @Override
                        public void execute() throws Exception {
                                turmaService.verificarAlertaDeRestricaoDoParticipante(turmaParticipante1, participantes);
                        }
                }, MSG_ERRO_O_ORGANIZADOR_JA_ULTRAPASSOU_AS_120_HORAS_DE_CARGA_HORARIA_REMUNERADA_NO_ANO);
        }
       
}