NetworkNode tainan = new NetworkNode();
tainan.setName("Tainan machine");
tainan.setIpAddress("192.168.1.200");
// Contruct sensor elements
NetworkElement vibSensor1 = new NetworkElement();
vibSensor1.setName("Vibration sensor V10");
NetworkElement vibSensor2 = new NetworkElement();
vibSensor2.setName("Vibration sensor V20");
NetworkElement tempSensor1 = new NetworkElement();
tempSensor1.setName("Temperature sensor T10");
NetworkElement tempSensor2 = new NetworkElement();
tempSensor2.setName("Temperature sensor T20");
// Add sensor element to DataNode
taipei.addElement(vibSensor1);
taipei.addElement(tempSensor1);
tainan.addElement(vibSensor2);
tainan.addElement(tempSensor2);
assertEquals("Element size ", 2, taipei.getElements().size());
// Add elements to domains
vibSensorDomain.addElement(vibSensor1);
vibSensorDomain.addElement(vibSensor2);
tempSensorDomain.addElement(tempSensor1);
tempSensorDomain.addElement(tempSensor2);
// ask cache to manage the domains
cache1.putObject("/vib", vibSensorDomain);
cache1.putObject("/temp", tempSensorDomain);
System.out.println(cache1.printDetails());
NetworkDomain temp1 = (NetworkDomain) cache1.getObject("/temp");
NetworkDomain vib1 = (NetworkDomain) cache1.getObject("/vib");
NetworkNode taipei1 = (NetworkNode) temp1.getNodes().get(0);
// NetworkNode taipei1 = (NetworkNode)temp1.getNodes().get(1); this would fail on equality
NetworkNode taipei2 = (NetworkNode) vib1.getNodes().get(0);
List l1 = temp1.getNodes();
assertEquals("Size is ", 2, l1.size());
l1 = taipei.getElements();
assertEquals("Size is ", 2, l1.size());
assertEquals("IPAddress ", taipei.getIpAddress(), taipei1.getIpAddress());
assertTrue("DataNode should be the same", (taipei1 == taipei2));
taipei2.setIpAddress("192.168.10.100");
assertEquals("New admin id is ", "192.168.10.100", taipei.getIpAddress());
List l2 = taipei1.getElements();
assertEquals("Size is ", 2, l2.size());
NetworkElement vibSens1 = (NetworkElement) l2.get(0);
NetworkElement tempSens1 = (NetworkElement) l2.get(1);
int SUSPENDED = 2;
vibSens1.setStatus(SUSPENDED);
tempSens1.setStatus(SUSPENDED);
assertEquals("Status ", vibSensor1.getStatus(), vibSens1.getStatus());
assertEquals("Status ", tempSensor1.getStatus(), tempSens1.getStatus());
}