@Test public void testQueryClauseWithLimit() { final Expression expr1 = TestBeanFactory.createExpressionBuilder() .setId(UUID.randomUUID()) .setService("my-test-service") .setCluster("my-test-cluster") .build(); final Expression expr2 = TestBeanFactory.createExpressionBuilder() .setId(UUID.randomUUID()) .setService("my-test-service") .setCluster("my-test-cluster") .build(); exprRepo.addOrUpdateExpression(expr1, Organization.DEFAULT); exprRepo.addOrUpdateExpression(expr2, Organization.DEFAULT); final ExpressionQuery query1 = new DefaultExpressionQuery(exprRepo, Organization.DEFAULT); query1.service(Optional.of("my-test-service")); query1.cluster(Optional.of("my-test-cluster")); query1.limit(1); final QueryResult<Expression> result1 = exprRepo.query(query1); Assert.assertEquals(1, result1.values().size()); final ExpressionQuery query2 = new DefaultExpressionQuery(exprRepo, Organization.DEFAULT); query2.service(Optional.of("my-test-service")); query2.cluster(Optional.of("my-test-cluster")); query2.limit(2); final QueryResult<Expression> result2 = exprRepo.query(query2); Assert.assertEquals(2, result2.values().size()); }
@Test public void testQueryClauseWithOffsetAndLimit() { final Expression expr1 = TestBeanFactory.createExpressionBuilder() .setId(UUID.randomUUID()) .setService("my-test-service") .setCluster("my-test-cluster") .build(); final Expression expr2 = TestBeanFactory.createExpressionBuilder() .setId(UUID.randomUUID()) .setService("my-test-service") .setCluster("my-test-cluster") .build(); final Expression expr3 = TestBeanFactory.createExpressionBuilder() .setId(UUID.randomUUID()) .setService("my-test-service") .setCluster("my-test-cluster") .build(); exprRepo.addOrUpdateExpression(expr1, Organization.DEFAULT); exprRepo.addOrUpdateExpression(expr2, Organization.DEFAULT); exprRepo.addOrUpdateExpression(expr3, Organization.DEFAULT); final ExpressionQuery query = new DefaultExpressionQuery(exprRepo, Organization.DEFAULT); query.service(Optional.of("my-test-service")); query.cluster(Optional.of("my-test-cluster")); query.offset(Optional.of(2)); query.limit(2); final QueryResult<Expression> result = exprRepo.query(query); Assert.assertEquals(1, result.values().size()); Assert.assertEquals(expr3.getId(), result.values().get(0).getId()); }