@Test public void testUpdateObjects() { InternalSubnet subnet = new InternalSubnet(); TransactionManager transactionManager = new TransactionManager(subnet); RemoteObjectManager manager = new RemoteObjectManager(); RemoteObject object1 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001101"), transactionManager); manager.add(object1); RemoteObject object2 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001101"), transactionManager); manager.add(object2); RemoteObject object3 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001101"), transactionManager); manager.add(object3); RemoteObject object4 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001201"), transactionManager); manager.add(object4); RemoteObject object5 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001201"), transactionManager); manager.add(object5); assertEquals(object3, manager.get(subnet.getLocalNode(), new EOJ("001101"))); assertEquals(null, manager.get(subnet.getLocalNode(), new EOJ("001102"))); assertEquals(object5, manager.get(subnet.getLocalNode(), new EOJ("001201"))); assertEquals(null, manager.get(subnet.getLocalNode(), new EOJ("001202"))); }
@Test public void testGetWithSelector() { final InternalSubnet subnet = new InternalSubnet(); TransactionManager transactionManager = new TransactionManager(subnet); RemoteObjectManager manager = new RemoteObjectManager(); RemoteObject object1 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001101"), transactionManager); manager.add(object1); RemoteObject object2 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001102"), transactionManager); manager.add(object2); RemoteObject object3 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001103"), transactionManager); manager.add(object3); RemoteObject object4 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001201"), transactionManager); manager.add(object4); RemoteObject object5 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001202"), transactionManager); manager.add(object5); LinkedList<RemoteObject> list1 = manager.get( new Selector<RemoteObject>() { @Override public boolean select(RemoteObject object) { return object.getEOJ().getClassEOJ().equals(new ClassEOJ("0011")); } }); assertEquals(3, list1.size()); LinkedList<RemoteObject> list2 = manager.get( new Selector<RemoteObject>() { @Override public boolean select(RemoteObject object) { return object.getEOJ().getClassEOJ().equals(new ClassEOJ("0012")); } }); assertEquals(2, list2.size()); LinkedList<RemoteObject> list3 = manager.get( new Selector<RemoteObject>() { @Override public boolean select(RemoteObject object) { return object.getNode().equals(subnet.getLocalNode()); } }); assertEquals(5, list3.size()); }
@Test public void testCreationAndGetRemoteObject() { InternalSubnet subnet = new InternalSubnet(); TransactionManager transactionManager = new TransactionManager(subnet); RemoteObjectManager manager = new RemoteObjectManager(); RemoteObject object = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001101"), transactionManager); manager.add(object); RemoteObject o = manager.get(subnet.getLocalNode(), new EOJ("001101")); ; assertEquals(object, o); try { new ResponseThread(subnet, transactionManager).start(); o.getData(EPC.xE0); } catch (EchonetObjectException e) { e.printStackTrace(); fail(); } RemoteObject object2 = manager.get(subnet.getLocalNode(), new EOJ("001101")); assertEquals(object, object2); manager.remove(object); object2 = manager.get(subnet.getLocalNode(), new EOJ("001101")); assertTrue(object2 == null); }
@Test public void testGetAtNode() { final InternalSubnet subnet = new InternalSubnet(); TransactionManager transactionManager = new TransactionManager(subnet); RemoteObjectManager manager = new RemoteObjectManager(); RemoteObject object1 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001101"), transactionManager); manager.add(object1); RemoteObject object2 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001102"), transactionManager); manager.add(object2); assertEquals(0, manager.getAtNode(subnet.getGroupNode()).size()); assertEquals(2, manager.getAtNode(subnet.getLocalNode()).size()); }
@Test public void testGetNodes() { final InternalSubnet subnet = new InternalSubnet(); TransactionManager transactionManager = new TransactionManager(subnet); RemoteObjectManager manager = new RemoteObjectManager(); assertTrue(manager.getNodes().isEmpty()); RemoteObject object1 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001101"), transactionManager); manager.add(object1); assertEquals(1, manager.getNodes().size()); RemoteObject object2 = new RemoteObject(subnet, subnet.getLocalNode(), new EOJ("001102"), transactionManager); manager.add(object2); assertEquals(1, manager.getNodes().size()); assertEquals(subnet.getLocalNode(), manager.getNodes().get(0)); }