use of org.opennms.features.topology.api.support.SavedHistory in project opennms by OpenNMS.
the class BundleContextHistoryManagerTest method testHistoryManager.
@Test
public void testHistoryManager() throws IOException {
String admin = "admin";
String user1 = "user1";
displayableVertices.add(new TestVertex("100"));
// simple save
String historyHash = historyManager.saveOrUpdateHistory(admin, graphContainerMock);
SavedHistory savedHistory = historyManager.getHistoryByFragment(historyHash);
Properties properties = loadProperties();
Assert.assertNotNull(savedHistory);
Assert.assertNotNull(properties);
// user -> historyId and historyId -> historyContent
Assert.assertEquals(2, properties.size());
Assert.assertTrue(properties.containsKey(admin));
Assert.assertTrue(properties.containsKey(historyHash));
Assert.assertNotNull(properties.get(admin));
// no access to this field after this line!
properties = null;
// save again (nothing should change)
String historyHash2 = historyManager.saveOrUpdateHistory(admin, graphContainerMock);
SavedHistory savedHistory2 = historyManager.getHistoryByFragment(historyHash2);
properties = loadProperties();
Assert.assertNotNull(savedHistory2);
Assert.assertNotNull(properties);
// user -> historyId and historyId -> historyContent
Assert.assertEquals(2, properties.size());
Assert.assertTrue(properties.containsKey(admin));
Assert.assertTrue(properties.containsKey(historyHash2));
Assert.assertEquals(properties.get(admin), historyHash2);
Assert.assertNotNull(properties.get(historyHash2));
// change entry for user "admin"
displayableVertices.add(new TestVertex("200"));
String historyHash3 = historyManager.saveOrUpdateHistory(admin, graphContainerMock);
SavedHistory savedHistory3 = historyManager.getHistoryByFragment(historyHash3);
properties = loadProperties();
Assert.assertNotNull(savedHistory3);
Assert.assertNotNull(properties);
// user -> historyId and historyId -> historyContent
Assert.assertEquals(3, properties.size());
Assert.assertTrue(properties.containsKey(admin));
Assert.assertTrue(properties.containsKey(historyHash3));
// this should not be removed
Assert.assertTrue(properties.containsKey(historyHash2));
Assert.assertNotNull(properties.get(historyHash3));
// create an entry for another user, but with same historyHash
String historyHash4 = historyManager.saveOrUpdateHistory(user1, graphContainerMock);
SavedHistory savedHistory4 = historyManager.getHistoryByFragment(historyHash3);
properties = loadProperties();
Assert.assertEquals(historyHash3, historyHash4);
Assert.assertNotNull(savedHistory4);
Assert.assertNotNull(properties);
// user -> historyId and historyId -> historyContent
Assert.assertEquals(4, properties.size());
Assert.assertTrue(properties.containsKey(user1));
Assert.assertTrue(properties.containsKey(admin));
Assert.assertTrue(properties.containsKey(historyHash4));
Assert.assertEquals(historyHash4, properties.get(admin));
Assert.assertEquals(historyHash4, properties.get(user1));
Assert.assertNotNull(properties.get(historyHash4));
// change entry for user1
displayableVertices.remove(0);
String historyHash5 = historyManager.saveOrUpdateHistory(user1, graphContainerMock);
SavedHistory savedHistory5 = historyManager.getHistoryByFragment(historyHash3);
properties = loadProperties();
Assert.assertNotNull(savedHistory5);
Assert.assertNotNull(properties);
// user -> historyId and historyId -> historyContent
Assert.assertEquals(5, properties.size());
Assert.assertTrue(properties.containsKey(admin));
Assert.assertTrue(properties.containsKey(user1));
Assert.assertTrue(properties.containsKey(historyHash4));
Assert.assertTrue(properties.containsKey(historyHash5));
Assert.assertNotNull(properties.get(historyHash5));
Assert.assertEquals(historyHash4, properties.get(admin));
Assert.assertEquals(historyHash5, properties.get(user1));
}
use of org.opennms.features.topology.api.support.SavedHistory in project opennms by OpenNMS.
the class ShowHistoryCommand method doExecute.
@Override
protected Object doExecute() throws Exception {
final SavedHistory savedHistory = historyManager.getHistoryByUserId(user);
if (savedHistory == null) {
System.out.println("No History for user '" + user + "' found.");
} else {
System.out.println("History for user '" + user + "':");
JAXBContext jaxbContext = JAXBContext.newInstance(SavedHistory.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(savedHistory, System.out);
}
return null;
}
use of org.opennms.features.topology.api.support.SavedHistory in project opennms by OpenNMS.
the class ShowHistoryCommand method execute.
@Override
public Object execute() throws Exception {
final SavedHistory savedHistory = historyManager.getHistoryByUserId(user);
if (savedHistory == null) {
System.out.println("No History for user '" + user + "' found.");
} else {
System.out.println("History for user '" + user + "':");
JAXBContext jaxbContext = JAXBContext.newInstance(SavedHistory.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(savedHistory, System.out);
}
return null;
}
use of org.opennms.features.topology.api.support.SavedHistory in project opennms by OpenNMS.
the class BundleContextHistoryManager method saveOrUpdateHistory.
@Override
public String saveOrUpdateHistory(String userId, GraphContainer graphContainer) {
SavedHistory history = new SavedHistory(graphContainer, m_operations);
saveHistory(userId, history);
return history.getFragment();
}
Aggregations