public void testSerializeCommitted() throws Exception { Artist artist = (Artist) context.newObject("Artist"); artist.setArtistName("artist1"); assertNotNull(artist.getObjectId()); context.commitChanges(); DataContext deserializedContext = Util.cloneViaSerialization(context); assertSame(context.getParentDataDomain(), deserializedContext.getParentDataDomain()); // there should be only one object registered Artist deserializedArtist = (Artist) deserializedContext.getObjectStore().getObjectIterator().next(); assertNotNull(deserializedArtist); // deserialized as hollow... assertEquals(PersistenceState.HOLLOW, deserializedArtist.getPersistenceState()); assertFalse(deserializedArtist.getObjectId().isTemporary()); assertEquals("artist1", deserializedArtist.getArtistName()); assertSame(deserializedContext, deserializedArtist.getObjectContext()); // test that to-many relationships are initialized List<?> paintings = deserializedArtist.getPaintingArray(); assertNotNull(paintings); assertEquals(0, paintings.size()); }
public void testLocalObject_FFE_InvalidID() throws Exception { tArtist.insert(777, "AA"); final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 777); Artist a3 = context2.localObject(a1); assertEquals(PersistenceState.HOLLOW, a3.getPersistenceState()); context1.invalidateObjects(a1); tArtist.deleteAll(); assertEquals(PersistenceState.HOLLOW, a3.getPersistenceState()); try { a3.getArtistName(); fail( "FaultFailureException wasn't thrown on attempt to " + "resolve HOLLOW object with no backing DB row"); } catch (FaultFailureException e) { // expected } }
public void testSerializeNew() throws Exception { Artist artist = (Artist) context.newObject("Artist"); artist.setArtistName("artist1"); assertNotNull(artist.getObjectId()); DataContext deserializedContext = Util.cloneViaSerialization(context); assertSame(context.getParentDataDomain(), deserializedContext.getParentDataDomain()); // there should be only one object registered Artist deserializedArtist = (Artist) deserializedContext.getObjectStore().getObjectIterator().next(); assertNotNull(deserializedArtist); assertEquals(PersistenceState.NEW, deserializedArtist.getPersistenceState()); assertTrue(deserializedArtist.getObjectId().isTemporary()); assertEquals("artist1", deserializedArtist.getArtistName()); assertSame(deserializedContext, deserializedArtist.getObjectContext()); }
public void testSerializeModified() throws Exception { Artist artist = (Artist) context.newObject("Artist"); artist.setArtistName("artist1"); assertNotNull(artist.getObjectId()); context.commitChanges(); artist.setArtistName("artist2"); DataContext deserializedContext = Util.cloneViaSerialization(context); assertSame(context.getParentDataDomain(), deserializedContext.getParentDataDomain()); // there should be only one object registered Artist deserializedArtist = (Artist) deserializedContext.getObjectStore().getObjectIterator().next(); assertNotNull(deserializedArtist); // deserialized as hollow... assertEquals(PersistenceState.MODIFIED, deserializedArtist.getPersistenceState()); assertFalse(deserializedArtist.getObjectId().isTemporary()); assertEquals("artist2", deserializedArtist.getArtistName()); assertSame(deserializedContext, deserializedArtist.getObjectContext()); }