Package de.timefinder.data.access

Source Code of de.timefinder.data.access.PersonDaoTest

/*
*  Copyright 2009 Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net.
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*  under the License.
*/
package de.timefinder.data.access;

import de.timefinder.data.Event;
import de.timefinder.data.Person;
import de.timefinder.data.Role;
import de.timefinder.data.TimeFinderTester;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net
*/
public class PersonDaoTest extends TimeFinderTester {

    @Before
    @Override
    public void setUp() {
        super.setUp();
    }

    @Test
    public void testPerson() {
        System.out.println("removePerson");

        Person p = new Person();
        p.setName("testName2");
        assertFalse(pDao.detach(p));

        pDao.attach(p);
        assertTrue(pDao.detach(p));

        Person andreas1 = new Person();
        andreas1.setName("Andy");
        assertEquals(0, pDao.getAll().size());
        pDao.attach(andreas1);
        assertEquals(1, pDao.getAll().size());
    }

    @Test
    public void testHasEqual() {
        System.out.println("hasEqual");

        String name = "Achim1";
        Person p2 = new Person();
        p2.setName(name);
        pDao.attach(p2);

        Person p3 = new Person();
        p3.setName(name + "false");

        assertTrue(pDao.getAll().contains(p2));
        assertFalse(pDao.getAll().contains(p3));
    }

    @Test
    public void testRole() {
        Person p = new Person();
        Event ev1 = new Event();
        p.addEvent(ev1, Role.TEACHER, true);
        assertEquals(p.getRole(ev1), Role.TEACHER);

        Event ev2 = new Event();
        p.addEvent(ev2, true);
        assertEquals(p.getRole(ev2), Role.STUDENT);
    }

    /**
     * This method gets a person from db => person1, changes its name,
     * but does not update it.
     * Then it gets the person again from db => person2.
     * Now updating the person1 will result in two identical objects?
     */
    @Test
    public void testIdentical() {
        System.out.println("identival");
        String name = "Testachim";
        Person person = new Person();
        person.setName(name);
        pDao.attach(person);
        Person person1 = pDao.getAll().iterator().next();
        person1.setName("achim");

        Person person2 = pDao.getAll().iterator().next();

        pDao.commit();

        assertSame("Both persons should be identical", person2, person1);
    }
}
TOP

Related Classes of de.timefinder.data.access.PersonDaoTest

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.