@Test public void testSerializeWorkspaceSnapshot() throws Exception { Product definingProduct = RECORDS.newProduct("zee product"); definingProduct.setWorkspace(definingProduct.getId()); definingProduct.insert(); Agency pseudoScientist = RECORDS.newAgency("Behold the Pseudo Scientist!"); pseudoScientist.setWorkspace(definingProduct.getId()); pseudoScientist.insert(); WorkspaceLabelRecord auth = RECORDS.newWorkspaceLabel("Su Su Sudio", definingProduct, pseudoScientist); auth.insert(); WorkspaceSnapshot retrieved = new WorkspaceSnapshot(definingProduct, create); assertEquals(2, retrieved.getRecords().size()); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new CoREModule()); File temp = File.createTempFile("snaptest", "wsp"); temp.deleteOnExit(); try (FileOutputStream os = new FileOutputStream(temp)) { mapper.writeValue(os, retrieved); } WorkspaceSnapshot deserialized; try (FileInputStream is = new FileInputStream(temp)) { deserialized = mapper.readValue(is, WorkspaceSnapshot.class); } assertEquals(2, deserialized.getRecords().size()); assertTrue(deserialized.getRecords().stream().anyMatch(r -> pseudoScientist.equals(r))); assertFalse(deserialized.getRecords().stream().anyMatch(r -> definingProduct.equals(r))); create.configuration().connectionProvider().acquire().rollback(); WorkspaceSnapshot.load(create, temp.toURI().toURL()); }
@Test public void testSerializeSnapshot() throws Exception { Agency pseudoScientist = RECORDS.newAgency("Behold the Pseudo Scientist!"); pseudoScientist.insert(); Product definingProduct = RECORDS.newProduct("zee product"); definingProduct.insert(); StateSnapshot retrieved = new StateSnapshot(RECORDS.create(), Collections.emptyList()); assertEquals(2, retrieved.getRecords().size()); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new CoREModule()); File temp = File.createTempFile("snaptest", "wsp"); temp.deleteOnExit(); try (FileOutputStream os = new FileOutputStream(temp)) { mapper.writeValue(os, retrieved); } StateSnapshot deserialized; try (FileInputStream is = new FileInputStream(temp)) { deserialized = mapper.readValue(is, StateSnapshot.class); } assertEquals(2, deserialized.getRecords().size()); assertTrue(deserialized.getRecords().stream().anyMatch(r -> pseudoScientist.equals(r))); }