TopologyViewImpl oldView = TopologyTestHelper
.cloneTopologyView(newView);
assertNull(newView.compareTopology(oldView));
DefaultInstanceDescriptionImpl id = TopologyTestHelper
.createInstanceDescription(newView.getClusterViews().iterator()
.next());
TopologyTestHelper.addInstanceDescription(newView, id);
assertEquals(Type.TOPOLOGY_CHANGED, newView.compareTopology(oldView));
assertEquals(2, newView.getInstances().size());
// addInstanceDescription now no longer throws an exception if you add
// the same
// instance twice. this provides greater stability
TopologyTestHelper.addInstanceDescription(newView, id);
assertEquals(2, newView.getInstances().size());
// try{
// TopologyTestHelper.addInstanceDescription(newView, id);
// fail("should not be able to add twice");
// } catch(Exception e) {
// // ok
// }
oldView = TopologyTestHelper.cloneTopologyView(newView);
assertNull(newView.compareTopology(oldView));
TopologyTestHelper.getWriteableProperties(
newView.getInstances().iterator().next()).put("a", "b");
assertEquals(Type.PROPERTIES_CHANGED, newView.compareTopology(oldView));
oldView = TopologyTestHelper.cloneTopologyView(newView);
assertNull(newView.compareTopology(oldView));
TopologyTestHelper.getWriteableProperties(
newView.getInstances().iterator().next()).put("a", "B");
assertEquals(Type.PROPERTIES_CHANGED, newView.compareTopology(oldView));
oldView = TopologyTestHelper.cloneTopologyView(newView);
assertNull(newView.compareTopology(oldView));
Map<String, String> p = TopologyTestHelper
.getWriteableProperties(newView.getInstances().iterator()
.next());
p.remove("a");
p.put("a", "B");
assertNull(newView.compareTopology(oldView));
// now change the properties of the first instance but modify the second instance' cluster
Iterator<InstanceDescription> it = newView.getInstances().iterator();
DefaultInstanceDescriptionImpl firstInstance = (DefaultInstanceDescriptionImpl) it.next();
assertNotNull(firstInstance);
DefaultInstanceDescriptionImpl secondInstance = (DefaultInstanceDescriptionImpl) it.next();
assertNotNull(secondInstance);
TopologyTestHelper.getWriteableProperties(
firstInstance).put("c", "d");
DefaultClusterViewImpl cluster = new DefaultClusterViewImpl(UUID.randomUUID().toString());
PrivateAccessor.setField(secondInstance, "clusterView", null);