Entity entity2 = new Entity(1L, null, 1, 5L, 1, c.getTime());
deviceManager.learnDeviceByEntity(entity1);
IDevice d = deviceManager.learnDeviceByEntity(entity2);
assertArrayEquals(new Integer[] { 1, 2 }, d.getIPv4Addresses());
assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
new SwitchPort(5L, 1)},
d.getAttachmentPoints());
Iterator<? extends IDevice> diter =
deviceManager.queryClassDevices(d.getEntityClass(),
null, null, 1, null, null);
assertTrue(diter.hasNext());
assertEquals(d.getDeviceKey(), diter.next().getDeviceKey());
diter = deviceManager.queryClassDevices(d.getEntityClass(),
null, null, 2, null, null);
assertTrue(diter.hasNext());
assertEquals(d.getDeviceKey(), diter.next().getDeviceKey());
replay(mockListener);
deviceManager.addListener(mockListener);
verify(mockListener);
reset(mockListener);
mockListener.deviceIPV4AddrChanged(isA(IDevice.class));
replay(mockListener);
deviceManager.entityCleanupTask.reschedule(0, null);
d = deviceManager.getDevice(d.getDeviceKey());
assertArrayEquals(new Integer[] { 2 }, d.getIPv4Addresses());
// Attachment points are not removed, previous ones are still valid.
assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
new SwitchPort(5L, 1) },
d.getAttachmentPoints());
diter = deviceManager.queryClassDevices(d.getEntityClass(),
null, null, 2, null, null);
assertTrue(diter.hasNext());
assertEquals(d.getDeviceKey(), diter.next().getDeviceKey());
diter = deviceManager.queryClassDevices(d.getEntityClass(),
null, null, 1, null, null);
assertFalse(diter.hasNext());
d = deviceManager.findDevice(1L, null, null, null, null);
assertArrayEquals(new Integer[] { 2 }, d.getIPv4Addresses());
// Attachment points are not removed, previous ones are still valid.
assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
new SwitchPort(5L, 1) },
d.getAttachmentPoints());
verify(mockListener);
}