}
public void testSerializationDeserialization() throws Exception
{
ProfileKey key = new ProfileKey("domain", "server", "name");
RepositoryContentMetadata rcm = new RepositoryContentMetadata(key);
RepositoryRootMetadata rrm = new RepositoryRootMetadata("normal");
RepositoryItemMetadata rim = new RepositoryItemMetadata();
rim.setRelativePath("/item");
rim.setOriginatingNode("192.168.100.1:1099");
rim.setTimestamp(1);
rrm.addItemMetadata(rim);
rim = new RepositoryItemMetadata();
rim.setRelativePath("/removed_item");
rim.setRemoved(true);
rim.setOriginatingNode("192.168.100.1:1099");
rim.setTimestamp(2);
rrm.addItemMetadata(rim);
rim = new RepositoryItemMetadata();
rim.setRelativePath("/dir.sar");
rim.setDirectory(true);
rim.setOriginatingNode("192.168.100.2:1099");
rim.setTimestamp(4);
rrm.addItemMetadata(rim);
rim = new RepositoryItemMetadata();
rim.setRelativePath("/dir.sar/item.jar");
rim.setOriginatingNode("192.168.100.2:1099");
rim.setTimestamp(4);
rrm.addItemMetadata(rim);
rim = new RepositoryItemMetadata();
rim.setRelativePath("/dir.sar/META-INF");
rim.setOriginatingNode("192.168.100.2:1099");
rim.setDirectory(true);
rim.setTimestamp(3);
rrm.addItemMetadata(rim);
rim = new RepositoryItemMetadata();
rim.setRelativePath("/dir.sar/META-INF/jboss-beans.xml");
rim.setDirectory(true);
rim.setOriginatingNode("192.168.100.2:1099");
rim.setTimestamp(3);
rrm.addItemMetadata(rim);
rim = new RepositoryItemMetadata();
rim.setRelativePath("/removed_dir.ear");
rim.setDirectory(true);
rim.setOriginatingNode("192.168.100.2:1099");
rim.setTimestamp(7);
rim.setRemoved(true);
rrm.addItemMetadata(rim);
rim = new RepositoryItemMetadata();
rim.setRelativePath("/removed_dir.ear/ejb.jar");
rim.setOriginatingNode("192.168.100.2:1099");
rim.setTimestamp(5);
rim.setRemoved(true);
rrm.addItemMetadata(rim);
rim = new RepositoryItemMetadata();
rim.setRelativePath("/removed_dir.ear/META-INF");
rim.setDirectory(true);
rim.setOriginatingNode("192.168.100.3:1099");
rim.setTimestamp(7);
rim.setRemoved(true);
rrm.addItemMetadata(rim);
rim = new RepositoryItemMetadata();
rim.setRelativePath("/removed_dir.ear/META-INF/application.xml");
rim.setDirectory(true);
rim.setOriginatingNode("192.168.100.3:1099");
rim.setTimestamp(7);
rim.setRemoved(true);
rrm.addItemMetadata(rim);
rim = new RepositoryItemMetadata();
rim.setRelativePath("/removed_dir.ear/war.war");
rim.setOriginatingNode("192.168.100.3:1099");
rim.setTimestamp(6);
rim.setRemoved(true);
rrm.addItemMetadata(rim);
RepositoryRootMetadata emptyRRM = new RepositoryRootMetadata("empty");
rim = new RepositoryItemMetadata();
rim.setRelativePath("/");
rim.setOriginatingNode("192.168.100.4:1099");
rim.setTimestamp(10);
rcm.setRepositories(Arrays.asList(new RepositoryRootMetadata[]{rrm, emptyRRM}));
rim = new RepositoryItemMetadata();
rim.setRelativePath("/");
rim.setOriginatingNode("127.0.0.1:1099");
rim.setTimestamp(20);
emptyRRM.addItemMetadata(rim);
File temp = new File(System.getProperty("java.io.tmpdir"));
JAXBRepositoryContentMetadataPersister testee = new JAXBRepositoryContentMetadataPersister(temp.toURI());
testee.store("test", rcm);
// Ensure we clean up
File stored = testee.getMetadataPath("test");
stored.deleteOnExit();
toDelete.add(stored);
InputStreamReader isr = new InputStreamReader(new FileInputStream(stored));
StringWriter writer = new StringWriter();
int read;
while ((read = isr.read()) != -1)
writer.write(read);
writer.close();
System.out.println(writer.toString());
RepositoryContentMetadata deserialized = testee.load("test");
assertEquals(rcm, deserialized);
}