|
|
|
@ -1,24 +1,24 @@ |
|
|
|
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao; |
|
|
|
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.GregorianCalendar; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import org.hibernate.Transaction; |
|
|
|
import org.hibernate.Transaction; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import com.ibm.icu.util.Calendar; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; |
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; |
|
|
|
|
|
|
|
|
|
|
|
class PersonDaoTest extends AbstractDatabaseTest { |
|
|
|
public class PersonDaoTest extends AbstractDatabaseTest { |
|
|
|
|
|
|
|
|
|
|
|
private PersonDaoImpl personDao; |
|
|
|
private PersonDaoImpl personDao; |
|
|
|
private Person person; |
|
|
|
private Person person; |
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
@Override |
|
|
|
|
|
|
|
@Before |
|
|
|
public void setUp() throws Exception { |
|
|
|
public void setUp() throws Exception { |
|
|
|
super.setUp(); |
|
|
|
super.setUp(); |
|
|
|
personDao = new PersonDaoImpl(); |
|
|
|
personDao = new PersonDaoImpl(); |
|
|
|
@ -26,16 +26,19 @@ class PersonDaoTest extends AbstractDatabaseTest { |
|
|
|
person = new Person(); |
|
|
|
person = new Person(); |
|
|
|
person.setPrename("prename"); |
|
|
|
person.setPrename("prename"); |
|
|
|
person.setSurname("surname"); |
|
|
|
person.setSurname("surname"); |
|
|
|
person.setBirth(new GregorianCalendar(2018, Calendar.NOVEMBER, 8).getTime()); |
|
|
|
// Date time = new GregorianCalendar(2018, Calendar.NOVEMBER, 8).getTime();
|
|
|
|
|
|
|
|
person.setBirth(LocalDate.of(2018, 11, 8)); |
|
|
|
person.setPassword("password"); |
|
|
|
person.setPassword("password"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void testSave() { |
|
|
|
public void testSave() { |
|
|
|
storePerson(); |
|
|
|
storePerson(); |
|
|
|
List<Person> stored = session.createNamedQuery(Person.QUERY_FINDALL, Person.class).list(); |
|
|
|
List<Person> stored = session.createNamedQuery(Person.QUERY_FINDALL, Person.class).list(); |
|
|
|
assertEquals(1, stored.size()); |
|
|
|
assertEquals(1, stored.size()); |
|
|
|
assertEquals(person, stored.get(0)); |
|
|
|
assertEquals(person, stored.get(0)); |
|
|
|
|
|
|
|
assertEquals(person, personDao.get(person.getId())); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void storePerson() { |
|
|
|
public void storePerson() { |
|
|
|
@ -45,7 +48,7 @@ class PersonDaoTest extends AbstractDatabaseTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void testUpdate() { |
|
|
|
public void testUpdate() { |
|
|
|
storePerson(); |
|
|
|
storePerson(); |
|
|
|
person.setSurname("surname2"); |
|
|
|
person.setSurname("surname2"); |
|
|
|
person.setPrename("prename2"); |
|
|
|
person.setPrename("prename2"); |
|
|
|
@ -59,18 +62,22 @@ class PersonDaoTest extends AbstractDatabaseTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void testListAll() { |
|
|
|
public void testListAll() { |
|
|
|
storePerson(); |
|
|
|
storePerson(); |
|
|
|
session.detach(person); |
|
|
|
session.detach(person); |
|
|
|
person = new Person(); |
|
|
|
person = new Person(); |
|
|
|
person.setSurname("surname2"); |
|
|
|
person.setSurname("surname2"); |
|
|
|
person.setPrename("prename2"); |
|
|
|
person.setPrename("prename2"); |
|
|
|
person.setBirth(new GregorianCalendar(2018, Calendar.NOVEMBER, 8).getTime()); |
|
|
|
person.setBirth(LocalDate.of(2018, 11, 8)); |
|
|
|
person.setPassword("password"); |
|
|
|
person.setPassword("password"); |
|
|
|
storePerson(); |
|
|
|
storePerson(); |
|
|
|
List<Person> stored = session.createNamedQuery(Person.QUERY_FINDALL, Person.class).list(); |
|
|
|
List<Person> stored = personDao.listAll(); |
|
|
|
assertEquals(2, stored.size()); |
|
|
|
assertEquals(2, stored.size()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testPersonGroup() { |
|
|
|
|
|
|
|
assertNotNull(new GroupDaoImpl()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|