deviceManager.learnDeviceByEntity(entity2);
deviceManager.learnDeviceByEntity(entity3);
IDevice d = deviceManager.learnDeviceByEntity(entity4);
// all entities are active, so entities 2,4 should win
assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 2),
new SwitchPort(5L, 2) },
d.getAttachmentPoints());
assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 2),
new SwitchPort(5L, 2)},
d.getAttachmentPoints(true));
c.add(Calendar.MILLISECOND, 1);
entity1.setLastSeenTimestamp(c.getTime());
d = deviceManager.learnDeviceByEntity(entity1);
// all entities are active, so entities 2,4 should win
assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
new SwitchPort(5L, 2) },
d.getAttachmentPoints());
assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
new SwitchPort(5L, 2),
new SwitchPort(1L, 2, ErrorStatus.DUPLICATE_DEVICE)},
d.getAttachmentPoints(true));
c.add(Calendar.MILLISECOND, Entity.ACTIVITY_TIMEOUT+1);
entity1.setLastSeenTimestamp(c.getTime());
d = deviceManager.learnDeviceByEntity(entity1);
// entities 3,4 are still in conflict, but 1 should be resolved
assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
new SwitchPort(5L, 2) },
d.getAttachmentPoints());
assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
new SwitchPort(5L, 2)},
d.getAttachmentPoints(true));
entity3.setLastSeenTimestamp(c.getTime());
d = deviceManager.learnDeviceByEntity(entity3);
// no conflicts, 1 and 3 will win
assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
new SwitchPort(5L, 1) },
d.getAttachmentPoints());
assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
new SwitchPort(5L, 1) },
d.getAttachmentPoints(true));
}