Improved JUnit test to properly verify context pagination
This commit is contained in:
parent
90e1ca1a28
commit
290cb44221
|
@ -548,8 +548,12 @@ public class ContextManagementTest extends ContextTest {
|
|||
@Test
|
||||
public void testLimitOffset() throws Exception {
|
||||
int limit = 2;
|
||||
int offset = limit * 0;
|
||||
|
||||
List<Context> contexts = getAll(offset, limit);
|
||||
|
||||
logger.info("Going to check {}s pagination validity", Context.NAME);
|
||||
|
||||
List<Context> contexts = getAll(0, limit);
|
||||
if(contexts.size()==0) {
|
||||
return;
|
||||
}
|
||||
|
@ -563,10 +567,11 @@ public class ContextManagementTest extends ContextTest {
|
|||
for(Context context : contexts) {
|
||||
UUID uuid = context.getID();
|
||||
uuids.add(uuid);
|
||||
logger.info("Found {} with UUID {} and name {}", Context.NAME, uuid, context.getName());
|
||||
logger.info("Using getAll({}, {}) found {} with UUID {} and name {}", offset, limit, Context.NAME, uuid, context.getName());
|
||||
}
|
||||
|
||||
contexts = getAll(limit, limit);
|
||||
offset = limit * 1;
|
||||
contexts = getAll(offset, limit);
|
||||
|
||||
if(contexts.size()>0) {
|
||||
Assert.assertTrue(contexts.size() <= limit);
|
||||
|
@ -575,7 +580,7 @@ public class ContextManagementTest extends ContextTest {
|
|||
UUID uuid = context.getID();
|
||||
Assert.assertFalse(uuids.contains(uuid));
|
||||
uuids.add(uuid);
|
||||
logger.info("Found {} with UUID {} and name {}", Context.NAME, uuid, context.getName());
|
||||
logger.info("Using getAll({}, {}) found {} with UUID {} and name {}", offset, limit, Context.NAME, uuid, context.getName());
|
||||
}
|
||||
|
||||
if(contexts.size()<limit) {
|
||||
|
@ -584,6 +589,7 @@ public class ContextManagementTest extends ContextTest {
|
|||
|
||||
|
||||
int doubleLimit = limit*2;
|
||||
offset = 0;
|
||||
|
||||
contexts = getAll(0, doubleLimit);
|
||||
|
||||
|
@ -591,19 +597,41 @@ public class ContextManagementTest extends ContextTest {
|
|||
|
||||
for(Context context : contexts) {
|
||||
UUID uuid = context.getID();
|
||||
logger.info("Checking if {} with UUID {} and name {} was contained in the previous queries", Context.NAME, uuid, context.getName());
|
||||
logger.info("Using getAll({}, {}) found {} with UUID {} and name {}", offset, doubleLimit, Context.NAME, uuid, context.getName());
|
||||
Assert.assertTrue(uuids.contains(uuid));
|
||||
logger.info("As expected got {} with UUID {} and name {}", Context.NAME, uuid, context.getName());
|
||||
}
|
||||
}
|
||||
|
||||
contexts = getAll();
|
||||
logger.info("Going to check all {}s", Context.NAME);
|
||||
|
||||
Assert.assertTrue(contexts.size()>=uuids.size());
|
||||
List<Context> all = getAll();
|
||||
|
||||
for(Context context : contexts) {
|
||||
UUID uuid = context.getID();
|
||||
logger.info("No limit listing: Got {} with UUID {} and name {}", Context.NAME, uuid, context.getName());
|
||||
uuids = new HashSet<>();
|
||||
|
||||
int i = -1;
|
||||
|
||||
while(true) {
|
||||
offset = ++i * limit;
|
||||
contexts = getAll(offset, limit);
|
||||
for(Context context : contexts) {
|
||||
UUID uuid = context.getID();
|
||||
logger.info("Using getAll({}, {}) found {} with UUID {} and name {}", offset, limit, Context.NAME, uuid, context.getName());
|
||||
uuids.add(uuid);
|
||||
}
|
||||
if(contexts.size()<limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.assertTrue(all.size()>=uuids.size());
|
||||
|
||||
for(Context context : all) {
|
||||
UUID uuid = context.getID();
|
||||
Assert.assertTrue(uuids.contains(uuid));
|
||||
logger.info("Using getAll() found {} with UUID {} and name {}", Context.NAME, uuid, context.getName());
|
||||
|
||||
}
|
||||
|
||||
logger.info("{} pagination seems properly working", Context.NAME);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue