@Test public void shouldLoadAPerson() { Long template = dataInitializer.people.get(0); Person p = personDao.find(template); Assert.assertNotNull("Person not found!", p); Assert.assertEquals(template, p.getId()); }
@Test public void shouldSaveAPerson() { Person p = new Person(); p.setFirstName("Andy"); p.setLastName("Gibson"); personDao.save(p); Long id = p.getId(); Assert.assertNotNull(id); }
public Person findPerson() { if (person == null) { if (personDao != null) { Person p = personDao.findPerson(uid); if (p != null) { setPerson(p); } } else { throw new IllegalStateException(); } } return person; }
/** @inheritDoc */ public Person getPerson() { if (person == null) { if (personDao != null) { Person p = personDao.getPerson(uid); if (p != null) { setPerson(p); } } else { throw new IllegalStateException(); } } if (person == null) { throw new DataIntegrityViolationException( "Associated Person not found for Member with uid=" + uid); } return person; }
@Test public void testHibernateTemplate() throws SQLException { assertNotNull("Person DAO is null.", personDao); Collection<Person> lPersons = personDao.findPersons(); int expected = 2; assertNotNull("Person list is null.", lPersons); assertEquals("Number of persons should be " + expected + ".", expected, lPersons.size()); Integer firstId = new Integer(1); Integer secondId = new Integer(2); for (Person person : lPersons) { assertNotNull("Person is null.", person); if (firstId.equals(person.getId())) { String firstName = "Joe"; String lastName = "Smith"; int expectedAddresses = 1; assertEquals( "Person first name should be " + firstName + ".", firstName, person.getFirstName()); assertEquals( "Person last name should be " + lastName + ".", lastName, person.getLastName()); assertNotNull("Person's address list is null.", person.getAddresses()); assertEquals( "Number of person's address list should be " + expectedAddresses + ".", expectedAddresses, person.getAddresses().size()); Integer addressId = new Integer(1); String addr = "1060 West Addison St."; String city = "Chicago"; String state = "IL"; String zipPostal = "60613"; for (Address address : person.getAddresses()) { assertNotNull("Address is null.", address); assertEquals("Address id should be '" + addressId + "'.", addressId, address.getId()); assertEquals("Address address should be '" + address + "'.", addr, address.getAddress()); assertEquals("Address city should be '" + city + "'.", city, address.getCity()); assertEquals("Address state should be '" + state + "'.", state, address.getState()); assertEquals( "Address zip/postal should be '" + zipPostal + "'.", zipPostal, address.getZipPostal()); } } if (secondId.equals(person.getId())) { String firstName = "John"; String lastName = "Wilson"; int expectedAddresses = 2; assertEquals( "Person first name should be " + firstName + ".", firstName, person.getFirstName()); assertEquals( "Person last name should be " + lastName + ".", lastName, person.getLastName()); assertNotNull("Person's address list is null.", person.getAddresses()); assertEquals( "Number of person's address list should be " + expectedAddresses + ".", expectedAddresses, person.getAddresses().size()); Integer addressId = new Integer(3); String addr = "47 Howard St."; String city = "San Francisco"; String state = "CA"; String zipPostal = "94103"; for (Address address : person.getAddresses()) { assertNotNull("Address is null.", address); if (addressId.equals(address.getId())) { assertEquals("Address id should be '" + addressId + "'.", addressId, address.getId()); assertEquals( "Address address should be '" + address + "'.", addr, address.getAddress()); assertEquals("Address city should be '" + city + "'.", city, address.getCity()); assertEquals("Address state should be '" + state + "'.", state, address.getState()); assertEquals( "Address zip/postal should be '" + zipPostal + "'.", zipPostal, address.getZipPostal()); } } } logger.debug(person.toString()); } }
public void shouldListPeople() { List<Person> people = personDao.getPeople(); Assert.assertEquals(DataInitializer.PERSON_COUNT, people.size()); }
private void getTeamMembers(Team team, TeamPersonDao teamPersonDao, PersonDao personDao) { List<TeamPerson> teamPersonList = teamPersonDao.findByTeamId(team.getId()); for (TeamPerson tp : teamPersonList) { team.addMember(personDao.get(tp.getPersonId())); } }