/** * Persists a given instance and prove if this was properly done. * * @throws org.rdform.api.context.PersistenceException if this exception occurs then this test * will fails. */ @Test public void testPersist() throws PersistenceException { final SimpleModel toPersist = new SimpleModel("Mopuffus", "Lumpkins", 38); final URI aboutBeforePersist = toPersist.getAbout(); // for a fresh instance the about must be null. assertNull(aboutBeforePersist); // here the instance becomes managed (but not persisted) persistenceContext.persist(toPersist); final boolean mangedBeforeFlush = persistenceContext.isManged(toPersist); // the instance is managed but not persisted assertTrue(mangedBeforeFlush); final boolean wasPersistedBeforeFlush = persistenceContext.wasPersisted(toPersist); // the instance is managed but not persisted assertFalse(wasPersistedBeforeFlush); persistenceContext.flush(); final URI about = toPersist.getAbout(); // after persistence the about property gets set to a non-null // (generated URI) assertNotNull(about); final boolean mangedAfterFlush = persistenceContext.isManged(toPersist); // the context is/was flushed there are no more managed instances assertFalse(mangedAfterFlush); final boolean wasPersisted = persistenceContext.wasPersisted(toPersist); assertTrue(wasPersisted); }
@Test public void simpleTest() { final String xml = "<model><name>my name</name><description>my description</description></model>"; final SimpleModel model = createGson().fromXml(xml, SimpleModel.class); assertEquals("my name", model.getName()); assertEquals("my description", model.getDescription()); }
@Test public void testPersistGet() throws PersistenceException { final SimpleModel toPersist = new SimpleModel("Mopuffus", "Lumpkins", 38); persistenceContext.persist(toPersist); persistenceContext.flush(); final URI about = toPersist.getAbout(); final Object o = persistenceContext.get(about); }