Entity entity2 = new Entity(2L, (short)2, 2, 1L, 2, new Date());
Entity entity3 = new Entity(3L, (short)3, 3, 5L, 1, new Date());
Entity entity4 = new Entity(4L, (short)4, 3, 5L, 2, new Date());
Entity entity5 = new Entity(1L, (short)4, 3, 5L, 2, new Date());
IDevice d1 = deviceManager.learnDeviceByEntity(entity1);
IDevice d2 = deviceManager.learnDeviceByEntity(entity2);
IDevice d3 = deviceManager.learnDeviceByEntity(entity3);
IDevice d4 = deviceManager.learnDeviceByEntity(entity4);
assertEquals(d1.getEntityClass(), d2.getEntityClass());
assertEquals(d1.getEntityClass(), d3.getEntityClass());
assertEquals(d1.getEntityClass(), d4.getEntityClass());
IDevice d;
Iterator<? extends IDevice> iter =
deviceManager.queryClassDevices(d1.getEntityClass(), null,
(short)1, 1, null, null);
int count = 0;
while (iter.hasNext()) {
count += 1;
d = iter.next();
assertEquals(d1.getDeviceKey(), d.getDeviceKey());
}
assertEquals(1, count);
iter = deviceManager.queryClassDevices(d1.getEntityClass(), null,
(short)3, 3, null, null);
count = 0;
while (iter.hasNext()) {
count += 1;
d = iter.next();
assertEquals(d3.getDeviceKey(), d.getDeviceKey());
}
assertEquals(1, count);
iter = deviceManager.queryClassDevices(d1.getEntityClass(), null,
(short)1, 3, null, null);
count = 0;
while (iter.hasNext()) {
count += 1;
iter.next();
}
assertEquals(0, count);
IDevice d5 = deviceManager.learnDeviceByEntity(entity5);
assertEquals(d1.getEntityClass(), d5.getEntityClass());
iter = deviceManager.queryClassDevices(d1.getEntityClass(), null,
(short)4, 3, null, null);
count = 0;
Set<Long> deviceKeysFromIterator = new HashSet<Long>();
while (iter.hasNext()) {
count += 1;
d = iter.next();
deviceKeysFromIterator.add(d.getDeviceKey());
}
Set<Long> expectedDeviceKeys = new HashSet<Long>();
expectedDeviceKeys.add(d4.getDeviceKey());
expectedDeviceKeys.add(d5.getDeviceKey());
assertEquals(expectedDeviceKeys, deviceKeysFromIterator);
assertEquals(2, count);
}