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.service.integracion; import com.dominion.salud.mpr.configuration.MPRJpaConfiguration; import com.dominion.salud.mpr.configuration.MPRAppConfig; import com.dominion.salud.mpr.negocio.entities.admin.Centros; import com.dominion.salud.mpr.negocio.entities.integracion.BuzonOutHis; import com.dominion.salud.mpr.negocio.service.admin.CentrosService; import java.util.Date; import java.util.Iterator; import java.util.List; import org.apache.commons.lang3.math.NumberUtils; 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.test.context.web.WebAppConfiguration; import org.springframework.transaction.annotation.Transactional; /** * * @author jcgonzalez */ @Transactional @Rollback(true) @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { MPRAppConfig.class, MPRJpaConfiguration.class }) @WebAppConfiguration public class BuzonOutHisServiceTest { private static final Logger logger = LoggerFactory.getLogger(BuzonOutHisServiceTest.class); private static Centros centros; private static BuzonOutHis buzonOutHis; @Autowired private BuzonOutHisService buzonOutHisService; @Autowired private CentrosService centrosService; @Before public void setUp() { centros = new Centros(); centros.setTxtCentro("Centros de Prueba"); centros.setCodCentro("PRU"); centrosService.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"); buzonOutHisService.save(buzonOutHis); } @Test public void count() { logger.debug("INIT [" + getClass().getName() + ".count()]"); try { logger.debug(" COUNT: " + buzonOutHisService.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: " + buzonOutHisService.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 = buzonOutHisService.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: " + buzonOutHisService.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 { buzonOutHisService.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)"); buzonOutHisService.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 clean() { logger.debug("INIT [" + getClass().getName() + ".clean()]"); try { buzonOutHisService.clean(); Assert.assertTrue(true); } catch (Exception e) { Assert.fail(e.toString()); } logger.debug("END [" + getClass().getName() + ".clean()]"); } }