Java tutorial
/* * Copyright (C) 2016 Dominion Global * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.dominion.salud.mpr.negocio.repositories.integracion; import com.dominion.salud.mpr.configuration.MPRJpaConfiguration; import com.dominion.salud.mpr.configuration.MPRAppConfig; import com.dominion.salud.mpr.negocio.configuration.MPRConstantes; import com.dominion.salud.mpr.negocio.entities.admin.Centros; import com.dominion.salud.mpr.negocio.entities.integracion.BuzonOutHis; import com.dominion.salud.mpr.negocio.repositories.admin.CentrosRepository; import java.util.Date; import java.util.Iterator; import java.util.List; import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.time.DateUtils; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.Rollback; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; /** * * @author jcgonzalez */ @Transactional @Rollback(true) @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { MPRAppConfig.class, MPRJpaConfiguration.class }) public class BuzonOutHisRepositoryTest { private static final Logger logger = LoggerFactory.getLogger(BuzonOutHisRepositoryTest.class); private static Centros centros; private static BuzonOutHis buzonOutHis; @Autowired private BuzonOutHisRepository buzonOutHisRepository; @Autowired private CentrosRepository centrosRepository; @Before public void setUp() { centros = new Centros(); centros.setTxtCentro("Centros de Prueba"); centros.setCodCentro("PRU"); centrosRepository.save(centros); buzonOutHis = new BuzonOutHis(); buzonOutHis.setCentros(centros); buzonOutHis.setIdBuzonOut(NumberUtils.createLong("0")); buzonOutHis.setFechaOut(new Date()); buzonOutHis.setFechaPro(new Date()); buzonOutHis.setTipo("PRU"); buzonOutHis.setIdMensaje("PRUE"); buzonOutHis.setMensaje("BuzonOutHis de Prueba"); buzonOutHisRepository.save(buzonOutHis); } @Test public void count() { logger.debug("INIT [" + getClass().getName() + ".count()]"); try { logger.debug(" COUNT: " + buzonOutHisRepository.count()); Assert.assertTrue(true); } catch (Exception e) { Assert.fail(e.toString()); } logger.debug("END [" + getClass().getName() + ".count()]"); } @Test public void exists() { logger.debug("INIT [" + getClass().getName() + ".exists()]"); try { logger.debug(" EXISTS: " + buzonOutHisRepository.exists(buzonOutHis.getIdBuzonOutHis())); Assert.assertTrue(true); } catch (Exception e) { Assert.fail(e.toString()); } logger.debug("END [" + getClass().getName() + ".exists()]"); } @Test public void findAll() { logger.debug("INIT [" + getClass().getName() + ".findAll()]"); try { List<BuzonOutHis> listaBuzonOutHis = buzonOutHisRepository.findAll(); if (listaBuzonOutHis != null && !listaBuzonOutHis.isEmpty()) { Iterator<BuzonOutHis> iteradorBuzonOutHis = listaBuzonOutHis.iterator(); while (iteradorBuzonOutHis.hasNext()) { logger.debug(" FIND_ALL: " + iteradorBuzonOutHis.next().toString()); } Assert.assertTrue(true); } else { Assert.fail("SIN RESULTADOS"); } Assert.assertTrue(true); } catch (Exception e) { Assert.fail(e.toString()); } logger.debug("END [" + getClass().getName() + ".findAll()]"); } @Test public void findOne() { logger.debug("INIT [" + getClass().getName() + ".findOne()]"); try { logger.debug(" FIND_ONE: " + buzonOutHisRepository.findOne(buzonOutHis.getIdBuzonOutHis())); Assert.assertTrue(true); } catch (Exception e) { Assert.fail(e.toString()); } logger.debug("END [" + getClass().getName() + ".findOne()]"); } @Test public void save() { logger.debug("INIT [" + getClass().getName() + ".save()]"); try { logger.debug(" INSERT: " + buzonOutHis.toString()); Assert.assertTrue(true); } catch (Exception e) { Assert.fail(e.toString()); } logger.debug("END [" + getClass().getName() + ".save()]"); } @Test public void delete() { logger.debug("INIT [" + getClass().getName() + ".delete()]"); try { buzonOutHisRepository.delete(buzonOutHis); logger.debug(" DELETE: " + buzonOutHis.toString()); Assert.assertTrue(true); } catch (Exception e) { Assert.fail(e.toString()); } logger.debug("END [" + getClass().getName() + ".delete()]"); } @Test public void update() { logger.debug("INIT [" + getClass().getName() + ".update()]"); try { buzonOutHis.setMensaje("BuzonOutHis de Prueba (act)"); buzonOutHisRepository.save(buzonOutHis); logger.debug(" UPDATE: " + buzonOutHis.toString()); Assert.assertTrue(true); } catch (Exception e) { Assert.fail(e.toString()); } logger.debug("END [" + getClass().getName() + ".update()]"); } @Test public void findAllByAntiguedad() { logger.debug("INIT [" + getClass().getName() + ".findAllByAntiguedad()]"); try { buzonOutHis.setFechaOut( DateUtils.addDays(new Date(), ((MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN_OLD + 1) * -1))); buzonOutHisRepository.save(buzonOutHis); logger.debug(" UPDATE: " + buzonOutHis.toString()); buzonOutHis .setFechaOut(DateUtils.addDays(new Date(), (MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN_OLD * -1))); List<BuzonOutHis> listaBuzonOutHis = buzonOutHisRepository.findAllByAntiguedad(); if (listaBuzonOutHis != null && !listaBuzonOutHis.isEmpty()) { Iterator<BuzonOutHis> iteradorBuzonOutHis = listaBuzonOutHis.iterator(); while (iteradorBuzonOutHis.hasNext()) { logger.debug(" FIND_ALL_BY_ANTIGUEDAD: " + iteradorBuzonOutHis.next().toString()); } } Assert.assertTrue(true); } catch (Exception e) { Assert.fail(e.toString()); } logger.debug("END [" + getClass().getName() + ".findAllByAntiguedad()]"); } }