com.dominion.salud.nomenclator.negocio.service.tools.BuzonSucesosServiceTest.java Source code

Java tutorial

Introduction

Here is the source code for com.dominion.salud.nomenclator.negocio.service.tools.BuzonSucesosServiceTest.java

Source

/*
 * Copyright (C) 2015 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.nomenclator.negocio.service.tools;

import com.dominion.salud.nomenclator.configuration.NOMENCLATORAppConfig;
import com.dominion.salud.nomenclator.configuration.NOMENCLATORJpaConfiguration;
import com.dominion.salud.nomenclator.negocio.entities.tools.BuzonSucesos;
import java.io.File;
import java.io.FileInputStream;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
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.mock.web.MockMultipartFile;
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;
import org.springframework.web.multipart.MultipartFile;

/**
 *
 * @author jcgonzalez
 */
@Transactional
@Rollback(true)
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { NOMENCLATORAppConfig.class, NOMENCLATORJpaConfiguration.class })
@WebAppConfiguration
public class BuzonSucesosServiceTest {

    private static final Logger logger = LoggerFactory.getLogger(BuzonSucesosServiceTest.class);
    private static BuzonSucesos buzonSucesos = null;

    @Autowired
    private BuzonSucesosService buzonSucesosService;

    @Before
    public void setUp() {
        buzonSucesos = new BuzonSucesos();
        buzonSucesos.setCodProceso("PROCESO DE PRUEBA");
        buzonSucesos.setFecIni(new Date());
        buzonSucesos.setMensaje("BuzonSuceso de Prueba");
        buzonSucesosService.save(buzonSucesos);
    }

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

        try {
            logger.debug("     COUNT: " + buzonSucesosService.count());

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

        logger.info("END [" + getClass().getName() + ".count()]");
    }

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

        try {
            logger.debug("     EXISTS: " + buzonSucesosService.exists(buzonSucesos.getIdBuzonSuceso()));

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

        logger.info("END [" + getClass().getName() + ".exists()]");
    }

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

        try {
            List<BuzonSucesos> listaBuzonSucesos = buzonSucesosService.findAll();
            if (listaBuzonSucesos != null && !listaBuzonSucesos.isEmpty()) {
                Iterator<BuzonSucesos> iteradorBuzonSucesos = listaBuzonSucesos.iterator();
                while (iteradorBuzonSucesos.hasNext()) {
                    logger.debug("     FIND_ALL: " + iteradorBuzonSucesos.next().toString());
                }
                Assert.assertTrue(true);
            } else {
                Assert.fail("SIN RESULTADOS");
            }

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

        logger.info("END [" + getClass().getName() + ".findAll()]");
    }

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

        try {
            logger.debug("     FIND_ONE: " + buzonSucesosService.findOne(buzonSucesos.getIdBuzonSuceso()));

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

        logger.info("END [" + getClass().getName() + ".findOne()]");
    }

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

        try {
            logger.info("     INSERT: " + buzonSucesos.toString());

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

        logger.info("END [" + getClass().getName() + ".save()]");
    }

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

        try {
            buzonSucesosService.delete(buzonSucesos);
            logger.info("     DELETE: " + buzonSucesos.toString());

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

        logger.info("END [" + getClass().getName() + ".delete()]");
    }

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

        try {
            buzonSucesos.setMensaje("BuzonSuceso de Prueba (act)");
            buzonSucesosService.save(buzonSucesos);
            logger.info("     UPDATE: " + buzonSucesos.toString());

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

        logger.info("END [" + getClass().getName() + ".update()]");
    }

    @Ignore
    @Test
    public void upload() {
        logger.info("INIT [" + getClass().getName() + ".upload()]");

        try {
            System.setProperty("nomenclator.temp",
                    "/home/jcgonzalez/Documentos/PROYECTOS/Nomenclator/Bases de Datos/Version 5 - 2015.07.06/xml/temp/");
            File file = new File(
                    "/home/jcgonzalez/Documentos/PROYECTOS/Nomenclator/Bases de Datos/Version 5 - 2015.07.06/xml/AEMPS.01082016.zip");
            FileInputStream input = new FileInputStream(file);
            MultipartFile multipartFile = new MockMultipartFile("file", file.getName(), "text/plain",
                    IOUtils.toByteArray(input));

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

        logger.info("END [" + getClass().getName() + ".upload()]");
    }
}