@Test public void testManyToMany() throws Exception { EntityTest test = lookup("EntityTest", EntityTest.class); test.manyToManyCreate(); Flight f1 = test.findFlightById(new Long(1)); assertTrue( "Name read from Hibernate is Airline 1", f1.getCompany().getName().equals("Airline 1")); Flight f2 = test.findFlightById(new Long(2)); assertTrue( "Name read from Hibernate is Airline 1", f2.getCompany().getName().equals("Airline 2")); assertEquals(1, f1.getCustomers().size()); assertEquals(2, f2.getCustomers().size()); }
@Test public void testManyToOne() throws Exception { EntityTest test = lookup("EntityTest", EntityTest.class); Flight f = test.manyToOneCreate(); Flight f2 = test.findFlightById(f.getId()); assertEquals(f.getId(), new Long(1)); assertEquals(f.getName(), f2.getName()); assertEquals(f.getCompany().getName(), f2.getCompany().getName()); Company c = test.findCompanyById(f.getCompany().getId()); assertNotNull("Company has one flight.", c.getFlights()); assertEquals(f.getCompany().getFlights().size(), c.getFlights().size()); }