public void test_Validate_Collect_Ok() {
final PuppetManifest pp = pf.createPuppetManifest();
final CollectExpression ce = pf.createCollectExpression();
pp.getStatements().add(ce);
ce.setClassReference(createNameOrReference("User"));
EqualityExpression predicate = pf.createEqualityExpression();
predicate.setLeftExpr(createNameOrReference("name"));
predicate.setOpName("==");
predicate.setRightExpr(createNameOrReference("Luke"));
VirtualCollectQuery q = pf.createVirtualCollectQuery();
q.setExpr(predicate);
ce.setQuery(q);
// -- test without attributes
tester.validator().checkCollectExpression(ce);
tester.diagnose().assertOK();
// -- add some attributes
AttributeOperations aos = pf.createAttributeOperations();
aos.getAttributes().add(createAttributeDefinition("x", "b"));
aos.getAttributes().add(createAttributeAddition("y", "b"));
ce.setAttributes(aos);
tester.validator().checkCollectExpression(ce);
tester.diagnose().assertOK();
// --test different class references
ce.setClassReference(createNameOrReference("::User"));
tester.validator().checkCollectExpression(ce);
tester.diagnose().assertOK();
ce.setClassReference(createNameOrReference("A::User::B"));
tester.validator().checkCollectExpression(ce);
tester.diagnose().assertOK();
// -- test exported query
ExportedCollectQuery eq = pf.createExportedCollectQuery();
eq.setExpr(predicate);
ce.setQuery(eq);
tester.validator().checkCollectExpression(ce);
tester.diagnose().assertOK();
// -- test non equality
predicate.setOpName("!=");
tester.validator().checkCollectExpression(ce);
tester.diagnose().assertOK();
// -- test and / or
AndExpression and = pf.createAndExpression();
and.setLeftExpr(predicate);
OrExpression or = pf.createOrExpression();
EqualityExpression predicate2 = pf.createEqualityExpression();
predicate2.setLeftExpr(createNameOrReference("name"));
predicate2.setOpName("!=");
predicate2.setRightExpr(createNameOrReference("Darth"));
EqualityExpression predicate3 = pf.createEqualityExpression();
predicate3.setLeftExpr(createNameOrReference("name"));
predicate3.setOpName("!=");
predicate3.setRightExpr(createNameOrReference("Vader"));
or.setLeftExpr(predicate2);
or.setRightExpr(predicate3);
ParenthesisedExpression pe = pf.createParenthesisedExpression();
pe.setExpr(or);