use of org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException in project alfresco-remote-api by Alfresco.
the class WhereTests method existClauseTest.
@Test
public void existClauseTest() {
Query theQuery = getWhereClause(null);
assertNotNull(theQuery);
assertTrue("Null passed in so nothing to theQuery.", theQuery.getTree() == null);
try {
theQuery = getWhereClause("fred");
fail("Should throw an InvalidQueryException");
} catch (InvalidQueryException error) {
// this is correct
}
try {
theQuery = getWhereClause("(noClosingBracket");
fail("Should throw an InvalidQueryException");
} catch (InvalidQueryException error) {
// this is correct
}
try {
theQuery = getWhereClause("noOpeningBracket)");
fail("Should throw an InvalidQueryException");
} catch (InvalidQueryException error) {
// this is correct
}
try {
theQuery = getWhereClause("(EXISTS(target.file))");
fail("Should throw an InvalidQueryException");
} catch (InvalidQueryException error) {
// this is correct
}
theQuery = getWhereClause("(exists(/target/file))");
assertExistsPropertyEquals("/target/file", theQuery, false);
theQuery = getWhereClause("(EXISTS(b))");
assertExistsPropertyEquals("b", theQuery, false);
theQuery = getWhereClause(" ( EXISTS ( whitespace ) ) ");
assertExistsPropertyEquals("whitespace", theQuery, false);
theQuery = getWhereClause("(exists ( folder ))");
assertExistsPropertyEquals("folder", theQuery, false);
theQuery = getWhereClause("(NOT EXISTS(b))");
assertExistsPropertyEquals("b", theQuery, true);
theQuery = getWhereClause(" (NOT EXISTS(b))");
assertExistsPropertyEquals("b", theQuery, true);
theQuery = getWhereClause("( NOT EXISTS(b))");
assertExistsPropertyEquals("b", theQuery, true);
theQuery = getWhereClause(" ( NOT EXISTS(b))");
assertExistsPropertyEquals("b", theQuery, true);
try {
theQuery = getWhereClause("(exists folder)");
fail("Should throw an InvalidQueryException, 'folder' should have a bracket around it");
} catch (InvalidQueryException error) {
// this is correct
}
theQuery = getWhereClause("(EXISTS(/target/folder) AND NOT EXISTS(/target/site))");
assertNotNull(theQuery);
CommonTree tree = theQuery.getTree();
assertNotNull(tree);
QueryHelper.walk(theQuery, new WalkerCallbackAdapter() {
int i = 0;
@Override
public void exists(String propertyName, boolean negated) {
if (i == 0) {
assertTrue("/target/folder".equals(propertyName));
} else {
assertTrue("/target/site".equals(propertyName));
}
i++;
}
@Override
public void and() {
// We don't need to do anything in this method. However, overriding the method indicates that AND is
// supported. OR is not supported at the same time.
}
});
try {
theQuery = getWhereClause("(EXISTS(/target/folder)OR EXISTS(/target/site))");
fail("Should throw an InvalidQueryException, the OR should have a space before it.");
} catch (InvalidQueryException error) {
// this is correct
}
theQuery = getWhereClause("(NOT EXISTS(/target/folder) OR EXISTS(/target/site))");
QueryHelper.walk(theQuery, new WalkerCallbackAdapter() {
@Override
public void exists(String propertyName, boolean negated) {
if (negated) {
assertTrue("/target/folder".equals(propertyName));
} else {
assertTrue("/target/site".equals(propertyName));
}
}
@Override
public void or() {
// We don't need to do anything in this method. However, overriding the method indicates that OR is
// supported. AND is not supported at the same time.
}
});
theQuery = getWhereClause("(EXISTS ( /target/folder ) OR EXISTS( /target/site ) )");
QueryHelper.walk(theQuery, new WalkerCallbackAdapter() {
int i = 0;
@Override
public void exists(String propertyName, boolean negated) {
if (i == 0) {
assertTrue("/target/folder".equals(propertyName));
} else {
assertTrue("/target/site".equals(propertyName));
}
i++;
}
@Override
public void or() {
// We don't need to do anything in this method. However, overriding the method indicates that OR is
// supported. AND is not supported at the same time.
}
});
theQuery = getWhereClause("(EXISTS(target/file) AND EXISTS(target/folder) AND EXISTS(target/site))");
QueryHelper.walk(theQuery, new WalkerCallbackAdapter() {
int i = 0;
@Override
public void exists(String propertyName, boolean negated) {
switch(i) {
case 0:
assertTrue("target/file".equals(propertyName));
break;
case 1:
assertTrue("target/folder".equals(propertyName));
break;
case 2:
assertTrue("target/site".equals(propertyName));
break;
default:
break;
}
i++;
}
@Override
public void and() {
// We don't need to do anything in this method. However, overriding the method indicates that AND is
// supported. OR is not supported at the same time.
}
});
}
Aggregations