Skip to content

Commit

Permalink
update tests for AQ
Browse files Browse the repository at this point in the history
  • Loading branch information
domko17 committed Jan 9, 2024
1 parent b35ce7a commit 2f6b0a2
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Map<String, String> generateSuggestion() {
}
// value for @path
if (findNode(ctx).getChild(0).getText().equals(FilterNames.META_PATH)) {
suggestions = getAllPath().stream().collect(Collectors.toMap(x -> x, x -> x));
suggestions = getAllPath().stream().collect(Collectors.toMap(filterName -> filterName, alias -> alias));
}
// value for @relation
if (ctx.getText().equals(FilterNames.META_RELATION)) {
Expand All @@ -88,15 +88,17 @@ public Map<String, String> generateSuggestion() {
if (ctx.getText().equals(FilterNames.MATCHES.getLocalPart()) || ctx.getText().equals(FilterNames.REFERENCED_BY.getLocalPart())) {
suggestions.put("(", null);
}
} else if (lastNode instanceof AxiomQueryParser.GenFilterContext || lastNode instanceof AxiomQueryParser.DescendantPathContext) {
} else if (lastNode instanceof AxiomQueryParser.GenFilterContext) {
suggestions = getFilters(lastNode.getText());
suggestions.put(FilterNames.NOT.getLocalPart(), null);
} else if (lastNode instanceof AxiomQueryParser.DescendantPathContext ctx) {

} else if (lastNode instanceof AxiomQueryParser.SubfilterOrValueContext ctx) {
suggestions.put(FilterNames.AND.getLocalPart(), null);
suggestions.put(FilterNames.OR.getLocalPart(), null);
} else if (lastNode instanceof TerminalNode ctx) {
if (ctx.getSymbol().getType() == AxiomQueryParser.SEP || ctx.getSymbol().getType() == AxiomQueryParser.AND_KEYWORD || ctx.getSymbol().getType() == AxiomQueryParser.OR_KEYWORD) {
suggestions = getAllPath().stream().collect(Collectors.toMap(x -> x, x -> x));
suggestions = getAllPath().stream().collect(Collectors.toMap(filterName -> filterName, alias -> alias));
suggestions.put(".", null);
}
} else if (lastNode instanceof ErrorNode ctx) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.evolveum.midpoint.prism.query.lang;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.impl.query.lang.AxiomQueryLangServiceImpl;
import com.evolveum.midpoint.prism.schema.SchemaRegistry;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;

import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;
import org.testng.Assert;

import javax.xml.namespace.QName;
import java.io.IOException;
import java.util.*;

import static com.evolveum.midpoint.prism.PrismInternalTestUtil.DEFAULT_NAMESPACE_PREFIX;

/**
* Created by Dominik.
*/
public class TestQueryCompletion extends AbstractPrismTest {

private AxiomQueryLangServiceImpl axiomQueryLangServiceImpl;

private SchemaRegistry schemaRegistry;

@BeforeSuite
public void setupDebug() throws SchemaException, SAXException, IOException {
PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX);
PrismTestUtil.resetPrismContext(new PrismInternalTestUtil());
axiomQueryLangServiceImpl = new AxiomQueryLangServiceImpl(PrismContext.get());
schemaRegistry = PrismContext.get().getSchemaRegistry();
}


// Basic filters
@Test
public void testQueryCompletionDot() {
String query = ". ";
}

@Test
public void testQueryCompletionTypesOfUserType() {
String query = ". type ";
TypeDefinition typeDefinition = schemaRegistry.findTypeDefinitionByType(new QName("UserType"));
Map<String, String> suggestions = axiomQueryLangServiceImpl.queryCompletion(query);
List<String> objectTypes = schemaRegistry.getAllSubTypesByTypeDefinition(Collections.singletonList(typeDefinition)).stream().map(item -> item.getTypeName().getLocalPart()).sorted().toList();
Assert.assertEquals(suggestions.keySet().stream().sorted().toList(), objectTypes);
}

@Test
public void testQueryCompletionBasePathsOfUserType() {
String query = ". type UserType and ";
TypeDefinition typeDefinition = schemaRegistry.findTypeDefinitionByType(new QName("UserType"));
PrismObjectDefinition<?> objectDefinition = schemaRegistry.findObjectDefinitionByCompileTimeClass((Class) typeDefinition.getCompileTimeClass());
List<String> itemPaths = new ArrayList<>(objectDefinition.getItemNames().stream().map(QName::getLocalPart).toList());
itemPaths.add(".");
Map<String, String> suggestions = axiomQueryLangServiceImpl.queryCompletion(query);
Assert.assertEquals(suggestions.keySet().stream().sorted().toList(), itemPaths.stream().sorted().toList());
}

@Test
public void testQueryCompletionBaseFilterName() {
String query = ". type UserType and givenName ";

List<String> expected = new ArrayList<String>();
expected.add("levenshtein");
expected.add("greaterOrEqual");
expected.add("isRoot");
expected.add("inOrg");
expected.add("lessOrEqual");
expected.add("notEqual");
expected.add("fullText");
expected.add("less");
expected.add("type");
expected.add("equal");
expected.add("contains");
expected.add("ownedByOid");
expected.add("similarity");
expected.add("endsWith");
expected.add("exists");
expected.add("anyIn");
expected.add("greater");
expected.add("ownedBy");
expected.add("inOid");
expected.add("startsWith");
expected.add("not");

Map<String, String> suggestions = axiomQueryLangServiceImpl.queryCompletion(query);
Assert.assertEquals(suggestions.keySet().stream().sorted().toList(), expected.stream().sorted().toList());
}

@Test
public void testQueryCompletionBaseSubFilter() {
String query = ". type UserType and givenName equal \"Jack\" ";
Map<String, String> suggestions = axiomQueryLangServiceImpl.queryCompletion(query);
Assert.assertEquals(suggestions.keySet().stream().sorted().toList(), List.of("and", "or"));
}

// Advanced filters
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.List;

import static com.evolveum.midpoint.prism.PrismInternalTestUtil.DEFAULT_NAMESPACE_PREFIX;

import static org.testng.AssertJUnit.assertTrue;

/**
Expand Down Expand Up @@ -53,14 +52,14 @@ private boolean checkingAxiomQueryErrorList(List<AxiomQueryError> errorList, Lis
}

@Test
public void validateEasyQuery() {
public void testValidateEasyQuery() {
String query = ". type UserType and givenName equal \"Jack\"";
List<AxiomQueryError> errorList = this.axiomQueryLangService.validate(query);
Assert.assertEquals(errorList, new ArrayList<>(), "verified query\n");
}

@Test
public void invalidateBadFilterName() {
public void testInvalidateBadFilterName() {
String query = ". type UserType and givenName equal1 \"Jack\" and name = \"Jack\"";
List<AxiomQueryError> errorList = this.axiomQueryLangService.validate(query);

Expand All @@ -77,7 +76,7 @@ public void invalidateBadFilterName() {
}

@Test
public void invalidateReferencedByFilterName() {
public void testInvalidateReferencedByFilterName() {
String query = ". type UserType and givenName referencedBy \"Jack\"";
List<AxiomQueryError> errorList = this.axiomQueryLangService.validate(query);

Expand All @@ -94,7 +93,7 @@ public void invalidateReferencedByFilterName() {
}

@Test
public void invalidateMatchesFilterName() {
public void testInvalidateMatchesFilterName() {
String query = ". type UserType and givenName matches \"Jack\"";
List<AxiomQueryError> errorList = this.axiomQueryLangService.validate(query);

Expand All @@ -111,7 +110,7 @@ public void invalidateMatchesFilterName() {
}

@Test
public void invalidateFilterNameAlias() {
public void testInvalidateFilterNameAlias() {
String query = ". type UserType and activation = \"disabled\"";
List<AxiomQueryError> errorList = this.axiomQueryLangService.validate(query);

Expand All @@ -128,7 +127,7 @@ public void invalidateFilterNameAlias() {
}

@Test
public void invalidateItemPath() {
public void testInvalidateItemPath() {
String query = ". type UserType and givenName1 equal \"Jack\"";
List<AxiomQueryError> errorList = this.axiomQueryLangService.validate(query);

Expand All @@ -145,7 +144,7 @@ public void invalidateItemPath() {
}

@Test
public void invalidateObjectType() {
public void testInvalidateObjectType() {
String query = ". type UserType1 and givenName1 equal \"Jack\"";
List<AxiomQueryError> errorList = this.axiomQueryLangService.validate(query);

Expand All @@ -170,7 +169,7 @@ public void invalidateObjectType() {
}

@Test
public void invalidateComplexitiesQuery() {
public void testInvalidateComplexitiesQuery() {
String query = ". referencedBy (\n"
+ " @type = UserType\n"
+ " and @path = assignment/targetRef\n"
Expand Down

0 comments on commit 2f6b0a2

Please sign in to comment.