com.dominion.salud.mpr.negocio.repositories.integracion.BuzonInHisRepositoryTest.java Source code

Java tutorial

Introduction

Here is the source code for com.dominion.salud.mpr.negocio.repositories.integracion.BuzonInHisRepositoryTest.java

Source

/*
 * 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.BuzonInHis;
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 BuzonInHisRepositoryTest {

    private static final Logger logger = LoggerFactory.getLogger(BuzonInHisRepositoryTest.class);
    private static Centros centros;
    private static BuzonInHis buzonInHis;

    @Autowired
    private BuzonInHisRepository buzonInHisRepository;
    @Autowired
    private CentrosRepository centrosRepository;

    @Before
    public void setUp() {
        centros = new Centros();
        centros.setTxtCentro("Centros de Prueba");
        centros.setCodCentro("PRU");
        centrosRepository.save(centros);

        buzonInHis = new BuzonInHis();
        buzonInHis.setCentros(centros);
        buzonInHis.setIdBuzonIn(NumberUtils.createLong("0"));
        buzonInHis.setFechaIn(new Date());
        buzonInHis.setFechaPro(new Date());
        buzonInHis.setTipo("PRU");
        buzonInHis.setIdMensaje("PRUE");
        buzonInHis.setMensaje("BuzonInHis de Prueba");
        buzonInHisRepository.save(buzonInHis);
    }

    @Test
    public void count() {
        logger.debug("INIT [" + getClass().getName() + ".count()]");

        try {
            logger.debug("     COUNT: " + buzonInHisRepository.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: " + buzonInHisRepository.exists(buzonInHis.getIdBuzonInHis()));

            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<BuzonInHis> listaBuzonInHis = buzonInHisRepository.findAll();
            if (listaBuzonInHis != null && !listaBuzonInHis.isEmpty()) {
                Iterator<BuzonInHis> iteradorBuzonInHis = listaBuzonInHis.iterator();
                while (iteradorBuzonInHis.hasNext()) {
                    logger.debug("     FIND_ALL: " + iteradorBuzonInHis.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: " + buzonInHisRepository.findOne(buzonInHis.getIdBuzonInHis()));

            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: " + buzonInHis.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 {
            buzonInHisRepository.delete(buzonInHis);
            logger.debug("     DELETE: " + buzonInHis.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 {
            buzonInHis.setMensaje("BuzonInHis de Prueba (act)");
            buzonInHisRepository.save(buzonInHis);
            logger.debug("     UPDATE: " + buzonInHis.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 {
            buzonInHis.setFechaIn(
                    DateUtils.addDays(new Date(), ((MPRConstantes._TASK_BUZON_IN_HIS_CLEAN_OLD + 1) * -1)));
            buzonInHisRepository.save(buzonInHis);
            logger.debug("     UPDATE: " + buzonInHis.toString());

            buzonInHis.setFechaIn(DateUtils.addDays(new Date(), (MPRConstantes._TASK_BUZON_IN_HIS_CLEAN_OLD * -1)));
            List<BuzonInHis> listaBuzonInHis = buzonInHisRepository.findAllByAntiguedad();
            if (listaBuzonInHis != null && !listaBuzonInHis.isEmpty()) {
                Iterator<BuzonInHis> iteradorBuzonInHis = listaBuzonInHis.iterator();
                while (iteradorBuzonInHis.hasNext()) {
                    logger.debug("     FIND_ALL_BY_ANTIGUEDAD: " + iteradorBuzonInHis.next().toString());
                }
            }

            Assert.assertTrue(true);
        } catch (Exception e) {
            Assert.fail(e.toString());
        }

        logger.debug("END [" + getClass().getName() + ".findAllByAntiguedad()]");
    }
}