Commit b56fd3a1a5728ec069633ed3d14d8f9642f49fc1

Authored by Roberto Alencar
2 parents 3bbee542 5c3e4d5e

Merge branch 'PBGAS_HOTFIX_157' of http://ggas.com.br/root/cdl_pbgas_ggas into developer

src/main/resources/hibernate.properties
... ... @@ -2,8 +2,8 @@
2 2 hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
3 3 hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
4 4  
5   -hibernate.connection.username=GGAS_TESTE
6   -hibernate.connection.password=GGAS_TESTE
  5 +hibernate.connection.username=GGAS_ADMIN
  6 +hibernate.connection.password=GGAS_ADMIN
7 7 #hibernate.connection.username=GGAS_ADMIN
8 8 #hibernate.connection.password=GGAS_ADMIN
9 9 hibernate.connection.url=jdbc:oracle:thin:@aplicacao.ggas.com.br:1521:XE
... ...
src/test/java/br/com/ggas/medicao/consumo/TesteCityGateMedicao.java 0 → 100644
... ... @@ -0,0 +1,222 @@
  1 +/**
  2 + *
  3 + */
  4 +
  5 +package br.com.ggas.medicao.consumo;
  6 +
  7 +import java.util.Calendar;
  8 +import java.util.Date;
  9 +
  10 +import org.junit.Assert;
  11 +import org.junit.Before;
  12 +import org.junit.Test;
  13 +import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.transaction.annotation.Transactional;
  15 +
  16 +import br.com.ggas.cadastro.operacional.CityGate;
  17 +import br.com.ggas.comum.GGASTestCase;
  18 +import br.com.ggas.geral.exception.GGASException;
  19 +import br.com.ggas.geral.exception.NegocioException;
  20 +
  21 +/**
  22 + * @author Rafael Bruno
  23 + */
  24 +public class TesteCityGateMedicao extends GGASTestCase {
  25 +
  26 + @Autowired
  27 + ControladorCityGateMedicao controladorCityGateMedicao;
  28 +
  29 + @Before
  30 + @Transactional
  31 + public void setUp() throws GGASException {
  32 +
  33 + super.cargaInicial.carregar();
  34 + this.inserirCityGate();
  35 + }
  36 +
  37 + // ------------------------------------------------------------------------------------
  38 + // Métodos de testes para testar a inclusão de City Gate Medicao
  39 + // ------------------------------------------------------------------------------------
  40 +
  41 + @Test
  42 + @Transactional
  43 + public void testeInserirCityGateMedicaoCamposObrigatorios() throws GGASException {
  44 +
  45 + CityGateMedicao cityGateMedicao = fachada.criarCityGateMedicao();
  46 +
  47 + try {
  48 + cityGateMedicao.setCityGate(null);
  49 + cityGateMedicao.setDadosAuditoria(null);
  50 + controladorCityGateMedicao.inserir(cityGateMedicao);
  51 +
  52 + Assert.assertTrue(Boolean.FALSE);
  53 + } catch (NegocioException e) {
  54 + Assert.assertTrue(Boolean.TRUE);
  55 + }
  56 + }
  57 +
  58 + @Test
  59 + @Transactional
  60 + public void testeInserirCityGateMedicaoSucesso() throws GGASException {
  61 +
  62 + int qtdInicio = controladorCityGateMedicao.obterTodas().size();
  63 +
  64 + inserirCityGateMedicao();
  65 +
  66 + int qtdFim = controladorCityGateMedicao.obterTodas().size();
  67 + Assert.assertEquals(qtdInicio + 1, qtdFim);
  68 + }
  69 +
  70 + // ------------------------------------------------------------------------------------
  71 + // Métodos de testes para testar a alteração de City Gate Medicao
  72 + // ------------------------------------------------------------------------------------
  73 +
  74 + @Test
  75 + @Transactional
  76 + public void testeAtualizarCityGateMedicaoSucesso() throws Throwable {
  77 +
  78 + CityGateMedicao cityGateMedicao = inserirCityGateMedicao();
  79 + Date DataAntesAlteracao = cityGateMedicao.getDataMedicao();
  80 +
  81 + cityGateMedicao.setDataMedicao(Calendar.getInstance().getTime());
  82 + cityGateMedicao.setCityGate((CityGate) buscar(CityGate.class));
  83 + getSesstion().update(cityGateMedicao);
  84 +
  85 + CityGateMedicao cityGateMedicaoAlterado = (CityGateMedicao) controladorCityGateMedicao.obter(cityGateMedicao.getChavePrimaria());
  86 + Date DataPosAlteracao = cityGateMedicaoAlterado.getDataMedicao();
  87 +
  88 + Assert.assertNotEquals(DataAntesAlteracao, DataPosAlteracao);
  89 +
  90 + }
  91 +
  92 + // ------------------------------------------------------------------------------------
  93 + // Métodos de testes para testar a remoção de City Gate Medicao
  94 + // ------------------------------------------------------------------------------------
  95 +
  96 + @Test
  97 + @Transactional
  98 + public void testeRemoverCityGateMedicaoSucesso() throws Throwable {
  99 +
  100 + CityGateMedicao cityGateMedicao = inserirCityGateMedicao();
  101 +
  102 + int qtdInicio = controladorCityGateMedicao.obterTodas().size();
  103 + controladorCityGateMedicao.remover(cityGateMedicao);
  104 + int qtdFim = controladorCityGateMedicao.obterTodas().size();
  105 +
  106 + Assert.assertEquals(qtdInicio - 1, qtdFim);
  107 + }
  108 +
  109 + // ------------------------------------------------------------------------------------
  110 + // Métodos de testes para testar a consulta de city gate medicao por chave
  111 + // ------------------------------------------------------------------------------------
  112 +
  113 + @Test
  114 + @Transactional
  115 + public void testeBuscarCityGateMedicaoPorChaveSucesso() throws GGASException {
  116 +
  117 + long chave = inserirCityGateMedicao().getChavePrimaria();
  118 + CityGateMedicao cityGateMedicao = (CityGateMedicao) controladorCityGateMedicao.obter(chave);
  119 + Assert.assertEquals(chave, cityGateMedicao.getChavePrimaria());
  120 + }
  121 +
  122 + @Test
  123 + @Transactional
  124 + public void testeBuscarCityGateMedicaoPorChaveFalha() throws GGASException {
  125 +
  126 + long chave = 9999L;
  127 + try {
  128 + controladorCityGateMedicao.obter(chave);
  129 + Assert.assertTrue(Boolean.FALSE);
  130 + } catch (NegocioException e) {
  131 + Assert.assertTrue(Boolean.TRUE);
  132 + }
  133 + }
  134 +
  135 + // ------------------------------------------------------------------------------------
  136 + // Métodos de testes para testar a consulta de City Gate Medicao por filtro
  137 + // ------------------------------------------------------------------------------------
  138 +
  139 + @Test
  140 + @Transactional
  141 + public void testeBuscarCityGateMedicaoPorCityGateEData() throws GGASException {
  142 +
  143 + CityGate cityGate = fachada.criarCityGate();
  144 + cityGate.setDescricao("Meu city gate");
  145 + super.salvar(cityGate);
  146 +
  147 + Date data = Calendar.getInstance().getTime();
  148 +
  149 + CityGateMedicao cityGateMedicao = fachada.criarCityGateMedicao();
  150 + cityGateMedicao.setCityGate(cityGate);
  151 + cityGateMedicao.setDataMedicao(data);
  152 +
  153 + super.salvar(cityGateMedicao);
  154 +
  155 + Assert.assertNotEquals(0, controladorCityGateMedicao.consultarCityGateMedicaoPorCityGateEData(cityGate, data).size());
  156 +
  157 + }
  158 +
  159 + @Test
  160 + @Transactional
  161 + public void testeBuscarCityGateMedicaoPorDataSucesso() throws GGASException {
  162 +
  163 + CityGate cityGate = (CityGate) buscar(CityGate.class);
  164 +
  165 + Date data = Calendar.getInstance().getTime();
  166 +
  167 + CityGateMedicao cityGateMedicao = fachada.criarCityGateMedicao();
  168 + cityGateMedicao.setCityGate(cityGate);
  169 + cityGateMedicao.setDataMedicao(data);
  170 +
  171 + super.salvar(cityGateMedicao);
  172 +
  173 + Assert.assertNotEquals(0, controladorCityGateMedicao.listarCityGateMedicaoPorData(data).size());
  174 +
  175 + }
  176 +
  177 + @Test
  178 + @Transactional
  179 + public void testeBuscarCityGateMedicaoPorDataFalha() throws GGASException {
  180 +
  181 + CityGate cityGate = (CityGate) buscar(CityGate.class);
  182 +
  183 + Date data = Calendar.getInstance().getTime();
  184 + Calendar dataAux = Calendar.getInstance();
  185 + dataAux.add(Calendar.DAY_OF_MONTH, 1);
  186 +
  187 + Date dataAlterada = dataAux.getTime();
  188 +
  189 + CityGateMedicao cityGateMedicao = fachada.criarCityGateMedicao();
  190 + cityGateMedicao.setCityGate(cityGate);
  191 + cityGateMedicao.setDataMedicao(data);
  192 +
  193 + super.salvar(cityGateMedicao);
  194 +
  195 + Assert.assertEquals(0, controladorCityGateMedicao.listarCityGateMedicaoPorData(dataAlterada).size());
  196 +
  197 + }
  198 +
  199 + // Metodos Privados
  200 +
  201 + private void inserirCityGate() throws GGASException {
  202 +
  203 + CityGate cityGate = (CityGate) controladorCityGateMedicao.criarCityGate();
  204 + cityGate.setDescricao("City Gate");
  205 +
  206 + super.salvar(cityGate);
  207 +
  208 + }
  209 +
  210 + @Transactional
  211 + private CityGateMedicao inserirCityGateMedicao() throws GGASException {
  212 +
  213 + CityGateMedicao cityGateMedicao = (CityGateMedicao) controladorCityGateMedicao.criar();
  214 + cityGateMedicao.setCityGate((CityGate) super.buscar(CityGate.class));
  215 + cityGateMedicao.setDataMedicao(Calendar.getInstance().getTime());
  216 +
  217 + super.salvar(cityGateMedicao);
  218 + return cityGateMedicao;
  219 +
  220 + }
  221 +
  222 +}
... ...