Package cz.muni.fi.pa165.ddtroops.persistence

Source Code of cz.muni.fi.pa165.ddtroops.persistence.RaceDAOTest

package cz.muni.fi.pa165.ddtroops.persistence;

import cz.muni.fi.pa165.ddtroops.daointerfaces.RaceDAO;
import cz.muni.fi.pa165.ddtroops.entities.Race;
import java.util.List;
import java.util.logging.Logger;
import junit.framework.TestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

/**
* Testclass for RaceDAOImpl class.
*
* @author Matěj Škrabánek
*/

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:testAppContext.xml" })
@Transactional
public class RaceDAOTest extends TestCase {
    private static final Logger logger = Logger.getLogger(SkillDAOTest.class.getName());
    @Autowired
    private RaceDAO raceDAO;

    @Test
    public void testCreateValid(){

        Race race = new Race();
        race.setName("Ogloj Chorchoj");
        race.setDescription("Velky cerv");
        race.setCharisma(Byte.MIN_VALUE);
        race.setConstitution(Byte.MIN_VALUE);
        race.setDexterity(Byte.MIN_VALUE);
        race.setIntelligence(Byte.MIN_VALUE);
        race.setStrength(Byte.MIN_VALUE);
        race.setWisdom(Byte.MIN_VALUE);

        raceDAO.create(race);
        assertNotNull(race.getId());
    }

    @Test
    public void testCreateInvalid(){

        Race race = new Race();
        race.setName("Ogloj Chorchoj");
        race.setDescription("Velky cerv");

        try{
            raceDAO.create(race);
        }
        catch(Exception ex)
        {
            assertTrue(true);
        }
    }

    @Test
    public void testGetById()
    {

        Race race = new Race();
        race.setName("Ogloj Chorchoj");
        race.setDescription("Velky cerv");
        race.setCharisma(Byte.MIN_VALUE);
        race.setConstitution(Byte.MIN_VALUE);
        race.setDexterity(Byte.MIN_VALUE);
        race.setIntelligence(Byte.MIN_VALUE);
        race.setStrength(Byte.MIN_VALUE);
        race.setWisdom(Byte.MIN_VALUE);

        raceDAO.create(race);
        assertEquals(race, raceDAO.getById(race.getId()));
    }

    @Test
    public void testUpdate()
    {

        Race race = new Race();
        race.setName("Ogloj");
        race.setDescription("Velky cerv");
        race.setCharisma(Byte.MIN_VALUE);
        race.setConstitution(Byte.MIN_VALUE);
        race.setDexterity(Byte.MIN_VALUE);
        race.setIntelligence(Byte.MIN_VALUE);
        race.setStrength(Byte.MIN_VALUE);
        race.setWisdom(Byte.MIN_VALUE);

        raceDAO.create(race);
        assertEquals("Ogloj", raceDAO.getById(race.getId()).getName());

        race.setName("Stupid Ogloj");
        raceDAO.update(race);
        assertEquals("Stupid Ogloj", raceDAO.getById(race.getId()).getName());
    }

    @Test
    public void testGetAll()
    {
        Race race = new Race();
        race.setName("Ogloj");
        race.setDescription("Velky cerv");
        race.setCharisma(Byte.MIN_VALUE);
        race.setConstitution(Byte.MIN_VALUE);
        race.setDexterity(Byte.MIN_VALUE);
        race.setIntelligence(Byte.MIN_VALUE);
        race.setStrength(Byte.MIN_VALUE);
        race.setWisdom(Byte.MIN_VALUE);

        raceDAO.create(race);

        Race race2 = new Race();
        race2.setName("Ogloj");
        race2.setDescription("Velky cerv");
        race2.setCharisma(Byte.MIN_VALUE);
        race2.setConstitution(Byte.MIN_VALUE);
        race2.setDexterity(Byte.MIN_VALUE);
        race2.setIntelligence(Byte.MIN_VALUE);
        race2.setStrength(Byte.MIN_VALUE);
        race2.setWisdom(Byte.MIN_VALUE);

        raceDAO.create(race2);
        List<Race> races = raceDAO.getAll();
        assertTrue(races.contains(race)&&races.contains(race2));
    }

    @Test
    public void testDelete(){
        Race race = new Race();
        race.setName("Ogloj");
        race.setDescription("Velky cerv");
        race.setCharisma(Byte.MIN_VALUE);
        race.setConstitution(Byte.MIN_VALUE);
        race.setDexterity(Byte.MIN_VALUE);
        race.setIntelligence(Byte.MIN_VALUE);
        race.setStrength(Byte.MIN_VALUE);
        race.setWisdom(Byte.MIN_VALUE);

        raceDAO.create(race);
        List<Race> races = raceDAO.getAll();
        Long raceId = race.getId();

        raceDAO.delete(race);
        assertNull(raceDAO.getById(raceId));
    }
}
TOP

Related Classes of cz.muni.fi.pa165.ddtroops.persistence.RaceDAOTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.