public void testMany2One() throws PersistenceException { TestObject berlin = new TestObject("Berlin"); TestObject freiburg = new TestObject("Freiburg"); RelatedObject silo1 = new RelatedObject("silo1"); RelatedObject silo2 = new RelatedObject("silo2"); berlin.addOne2many(silo1); berlin.addOne2many(silo2); assertTrue(silo1.getMany2one() == berlin); assertTrue(silo2.getMany2one() == berlin); assertTrue(berlin.getOne2many().contains(silo1)); assertTrue(berlin.getOne2many().contains(silo2)); getPersistenceManager().commit(); berlin.removeOne2many(silo1); assertNotSame("is marked changed", ModificationType.CHANGED, berlin.getModificationType()); assertEquals("is not marked changed", ModificationType.CHANGED, silo1.getModificationType()); assertTrue(silo1.getMany2one() == null); assertTrue(!berlin.getOne2many().contains(silo1)); assertTrue(((PersistentSet) berlin.getOne2many()).isDirty()); getPersistenceManager().commit(); assertFalse(((PersistentSet) berlin.getOne2many()).isDirty()); berlin.addOne2many(silo1); assertNotSame("is marked changed", ModificationType.CHANGED, berlin.getModificationType()); assertEquals("is not marked changed", ModificationType.CHANGED, silo1.getModificationType()); assertTrue(silo1.getMany2one() == berlin); assertTrue(berlin.getOne2many().contains(silo1)); getPersistenceManager().commit(); freiburg.addOne2many(silo1); assertTrue(silo1.getMany2one() == freiburg); assertTrue(freiburg.getOne2many().contains(silo1)); assertFalse(berlin.getOne2many().contains(silo1)); getPersistenceManager().commit(); }
/** * This test is focused on the "worst case". Two pairs objects are related bidirectional. Now we * change the relationship "over cross". What shall happen is the new relationship is maintained. * the old partners are "alone". * * @throws PersistenceException */ public void testOne2One() throws PersistenceException { TestObject peter = new TestObject("Peter"); TestObject paul = new TestObject("Paul"); RelatedObject mary = new RelatedObject("Mary"); RelatedObject jane = new RelatedObject("Jane"); assertEquals("is not marked new", ModificationType.NEW, peter.getModificationType()); assertEquals("is not marked new", ModificationType.NEW, paul.getModificationType()); assertEquals("is not marked new", ModificationType.NEW, mary.getModificationType()); assertEquals("is not marked new", ModificationType.NEW, jane.getModificationType()); getPersistenceManager().commit(); peter.setOne2one(mary); jane.setOne2one(paul); assertTrue(peter.getOne2one() == mary); assertTrue(mary.getOne2one() == peter); assertTrue(paul.getOne2one() == jane); assertTrue(jane.getOne2one() == paul); getPersistenceManager().commit(); assertNotSame("is marked changed", ModificationType.CHANGED, peter.getModificationType()); assertNotSame("is marked changed", ModificationType.CHANGED, paul.getModificationType()); assertNotSame("is marked changed", ModificationType.CHANGED, mary.getModificationType()); assertNotSame("is marked changed", ModificationType.CHANGED, jane.getModificationType()); paul.setOne2one(mary); assertTrue(paul.getOne2one() == mary); assertTrue(mary.getOne2one() == paul); assertEquals("is not marked changed", ModificationType.CHANGED, paul.getModificationType()); // assertTrue(mary.isMarkedChanged()); // assertTrue(jane.isMarkedChanged()); assertTrue(jane.getOne2one() == null); assertEquals("is not marked changed", ModificationType.CHANGED, peter.getModificationType()); assertTrue(peter.getOne2one() == null); getPersistenceManager().commit(); mary.setOne2one(null); // assertTrue(mary.isMarkedChanged()); assertEquals("is not marked changed", ModificationType.CHANGED, paul.getModificationType()); assertTrue(paul.getOne2one() == null); assertTrue(mary.getOne2one() == null); }