switched to strolch elements in tests and fixed mull pointer problem in chained method execution
This commit is contained in:
parent
353c1a35fb
commit
85499f60ae
|
@ -41,6 +41,10 @@
|
||||||
<groupId>li.strolch</groupId>
|
<groupId>li.strolch</groupId>
|
||||||
<artifactId>li.strolch.privilege</artifactId>
|
<artifactId>li.strolch.privilege</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>li.strolch</groupId>
|
||||||
|
<artifactId>li.strolch.model</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Test -->
|
<!-- Test -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -11,45 +11,46 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class ChainedMethodExpression extends AbstractObjectExpression {
|
public class ChainedMethodExpression extends AbstractObjectExpression {
|
||||||
|
|
||||||
private String objectKey;
|
private String objectKey;
|
||||||
|
|
||||||
private List<MethodExpression> methodExpressions = new ArrayList<>();
|
private List<MethodExpression> methodExpressions = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getType(final Map<String, Object> inputObjects, final Map<String, Object> queryParameter) {
|
public Class<?> getType(final Map<String, Object> inputObjects, final Map<String, Object> queryParameter) {
|
||||||
Object result = evaluate(inputObjects, queryParameter);
|
Object result = evaluate(inputObjects, queryParameter);
|
||||||
return result.getClass();
|
return result.getClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* evaluate by calling the method by name.
|
* evaluate by calling the method by name.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object evaluate(final Map<String, Object> inputObjects, final Map<String, Object> queryParameter) {
|
public Object evaluate(final Map<String, Object> inputObjects, final Map<String, Object> queryParameter) {
|
||||||
|
|
||||||
final Object inputObject = inputObjects.get(objectKey);
|
final Object inputObject = inputObjects.get(objectKey);
|
||||||
|
|
||||||
Object object = inputObject;
|
Object object = inputObject;
|
||||||
for (MethodExpression methodExpression : methodExpressions) {
|
for (MethodExpression methodExpression : methodExpressions) {
|
||||||
methodExpression.setObject(object);
|
methodExpression.setObject(object);
|
||||||
object = methodExpression.evaluate(inputObjects, queryParameter);
|
object = methodExpression.evaluate(inputObjects, queryParameter);
|
||||||
}
|
if (object == null) return null;
|
||||||
|
}
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setObjectKey(String entityKey) {
|
public void setObjectKey(String entityKey) {
|
||||||
this.objectKey = entityKey;
|
this.objectKey = entityKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMethodExpression(MethodExpression methodExpression) {
|
public void addMethodExpression(MethodExpression methodExpression) {
|
||||||
this.methodExpressions.add(methodExpression);
|
this.methodExpressions.add(methodExpression);
|
||||||
methodExpression.setParent(this);
|
methodExpression.setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ChainedMethodExpression [objectKey=" + objectKey + ", methodExpressions=" + methodExpressions + "]";
|
return "ChainedMethodExpression [objectKey=" + objectKey + ", methodExpressions=" + methodExpressions + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,130 +8,131 @@ import li.strolch.soql.core.SOQLEvaluationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares two or more expressions, for example 'a.name = "12345"'
|
* Compares two or more expressions, for example 'a.name = "12345"'
|
||||||
*
|
* <p>
|
||||||
* Currently only the following operators for equality check are supported:
|
* Currently only the following operators for equality check are supported:
|
||||||
*
|
* <p>
|
||||||
* '=' | '<>' | '>' | '>=' | '<' | '<=' ;
|
* '=' | '<>' | '>' | '>=' | '<' | '<=' ;
|
||||||
*
|
*
|
||||||
* @author msmock
|
* @author msmock
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ComparisonExpression extends AbstractBooleanExpression {
|
public class ComparisonExpression extends AbstractBooleanExpression {
|
||||||
|
|
||||||
private String operator;
|
private String operator;
|
||||||
private List<IObjectExpression> operands = new ArrayList<>();
|
private List<IObjectExpression> operands = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(Map<String, Object> inputObjects, Map<String, Object> queryParameter) {
|
public boolean evaluate(Map<String, Object> inputObjects, Map<String, Object> queryParameter) {
|
||||||
|
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case "=":
|
case "=":
|
||||||
result = evaluateEquals(inputObjects, queryParameter);
|
result = evaluateEquals(inputObjects, queryParameter);
|
||||||
break;
|
break;
|
||||||
case "<>":
|
case "<>":
|
||||||
result = !evaluateEquals(inputObjects, queryParameter);
|
result = !evaluateEquals(inputObjects, queryParameter);
|
||||||
break;
|
break;
|
||||||
case ">":
|
case ">":
|
||||||
result = evaluateMore(inputObjects, queryParameter);
|
result = evaluateMore(inputObjects, queryParameter);
|
||||||
break;
|
break;
|
||||||
case "<":
|
case "<":
|
||||||
result = evaluateLess(inputObjects, queryParameter);
|
result = evaluateLess(inputObjects, queryParameter);
|
||||||
break;
|
break;
|
||||||
case ">=":
|
case ">=":
|
||||||
result = !evaluateLess(inputObjects, queryParameter);
|
result = !evaluateLess(inputObjects, queryParameter);
|
||||||
break;
|
break;
|
||||||
case "<=":
|
case "<=":
|
||||||
result = !evaluateMore(inputObjects, queryParameter);
|
result = !evaluateMore(inputObjects, queryParameter);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new SOQLEvaluationException("Comparison with operator " + operator + " is not supported yet.");
|
throw new SOQLEvaluationException("Comparison with operator " + operator + " is not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: allow comparison, if the classes do not match. I.e. compare Integer with Double
|
* TODO: allow comparison, if the classes do not match. I.e. compare Integer with Double
|
||||||
*
|
*
|
||||||
* @param inputObjects
|
* @param inputObjects
|
||||||
* @param queryParameter
|
* @param queryParameter
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private boolean evaluateLess(final Map<String, Object> inputObjects, final Map<String, Object> queryParameter) {
|
private boolean evaluateLess(final Map<String, Object> inputObjects, final Map<String, Object> queryParameter) {
|
||||||
|
|
||||||
final Object result_1 = operands.get(0).evaluate(inputObjects, queryParameter);
|
final Object result_1 = operands.get(0).evaluate(inputObjects, queryParameter);
|
||||||
final Object result_2 = operands.get(1).evaluate(inputObjects, queryParameter);
|
final Object result_2 = operands.get(1).evaluate(inputObjects, queryParameter);
|
||||||
|
|
||||||
final Class<?> clazz_1 = result_1.getClass();
|
final Class<?> clazz_1 = result_1.getClass();
|
||||||
final Class<?> clazz_2 = result_2.getClass();
|
final Class<?> clazz_2 = result_2.getClass();
|
||||||
|
|
||||||
if (!clazz_1.equals(clazz_2)) {
|
if (!clazz_1.equals(clazz_2)) {
|
||||||
throw new SOQLEvaluationException("Operation < not defined for comparison of " + result_1 + " of class "
|
throw new SOQLEvaluationException("Operation < not defined for comparison of " + result_1 + " of class "
|
||||||
+ clazz_1 + " with " + result_2 + " of class " + clazz_2);
|
+ clazz_1 + " with " + result_2 + " of class " + clazz_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result_1 instanceof Integer && result_2 instanceof Integer) {
|
if (result_1 instanceof Integer && result_2 instanceof Integer) {
|
||||||
return ((Integer) result_1).compareTo((Integer) result_2) < 0;
|
return ((Integer) result_1).compareTo((Integer) result_2) < 0;
|
||||||
} else if (result_1 instanceof Long && result_2 instanceof Long) {
|
} else if (result_1 instanceof Long && result_2 instanceof Long) {
|
||||||
return ((Long) result_1).compareTo((Long) result_2) < 0;
|
return ((Long) result_1).compareTo((Long) result_2) < 0;
|
||||||
} else if (result_1 instanceof Double && result_2 instanceof Double) {
|
} else if (result_1 instanceof Float && result_2 instanceof Float) {
|
||||||
return ((Float) result_1).compareTo((Float) result_2) < 0;
|
return ((Float) result_1).compareTo((Float) result_2) < 0;
|
||||||
} else if (result_1 instanceof Double && result_2 instanceof Double) {
|
} else if (result_1 instanceof Double && result_2 instanceof Double) {
|
||||||
return ((Double) result_1).compareTo((Double) result_2) < 0;
|
return ((Double) result_1).compareTo((Double) result_2) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean evaluateMore(final Map<String, Object> inputObjects, final Map<String, Object> queryParameter) {
|
private boolean evaluateMore(final Map<String, Object> inputObjects, final Map<String, Object> queryParameter) {
|
||||||
|
|
||||||
final Object result_1 = operands.get(0).evaluate(inputObjects, queryParameter);
|
final Object result_1 = operands.get(0).evaluate(inputObjects, queryParameter);
|
||||||
final Object result_2 = operands.get(1).evaluate(inputObjects, queryParameter);
|
final Object result_2 = operands.get(1).evaluate(inputObjects, queryParameter);
|
||||||
|
|
||||||
final Class<?> clazz_1 = result_1.getClass();
|
final Class<?> clazz_1 = result_1.getClass();
|
||||||
final Class<?> clazz_2 = result_2.getClass();
|
final Class<?> clazz_2 = result_2.getClass();
|
||||||
|
|
||||||
if (!clazz_1.equals(clazz_2)) {
|
if (!clazz_1.equals(clazz_2)) {
|
||||||
throw new SOQLEvaluationException("Operation < not defined for comparison of " + result_1 + " of class "
|
throw new SOQLEvaluationException("Operation < not defined for comparison of " + result_1 + " of class "
|
||||||
+ clazz_1 + " with " + result_2 + " of class " + clazz_2);
|
+ clazz_1 + " with " + result_2 + " of class " + clazz_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result_1 instanceof Integer && result_2 instanceof Integer) {
|
if (result_1 instanceof Integer && result_2 instanceof Integer) {
|
||||||
return ((Integer) result_1).compareTo((Integer) result_2) > 0;
|
return ((Integer) result_1).compareTo((Integer) result_2) > 0;
|
||||||
} else if (result_1 instanceof Long && result_2 instanceof Long) {
|
} else if (result_1 instanceof Long && result_2 instanceof Long) {
|
||||||
return ((Long) result_1).compareTo((Long) result_2) > 0;
|
return ((Long) result_1).compareTo((Long) result_2) > 0;
|
||||||
} else if (result_1 instanceof Double && result_2 instanceof Double) {
|
} else if (result_1 instanceof Float && result_2 instanceof Float) {
|
||||||
return ((Float) result_1).compareTo((Float) result_2) > 0;
|
return ((Float) result_1).compareTo((Float) result_2) > 0;
|
||||||
} else if (result_1 instanceof Double && result_2 instanceof Double) {
|
} else if (result_1 instanceof Double && result_2 instanceof Double) {
|
||||||
return ((Double) result_1).compareTo((Double) result_2) > 0;
|
return ((Double) result_1).compareTo((Double) result_2) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the String representation of the operands match
|
* @return true if the String representation of the operands match
|
||||||
*/
|
*/
|
||||||
private boolean evaluateEquals(final Map<String, Object> inputObjects, final Map<String, Object> queryParameter) {
|
private boolean evaluateEquals(final Map<String, Object> inputObjects, final Map<String, Object> queryParameter) {
|
||||||
Object result_1 = operands.get(0).evaluate(inputObjects, queryParameter);
|
Object result_1 = operands.get(0).evaluate(inputObjects, queryParameter);
|
||||||
Object result_2 = operands.get(1).evaluate(inputObjects, queryParameter);
|
Object result_2 = operands.get(1).evaluate(inputObjects, queryParameter);
|
||||||
return result_1.equals(result_2);
|
if (result_1 == null || result_2 == null)
|
||||||
}
|
return false;
|
||||||
|
return result_1.equals(result_2);
|
||||||
|
}
|
||||||
|
|
||||||
public void setOperator(String operator) {
|
public void setOperator(String operator) {
|
||||||
this.operator = operator;
|
this.operator = operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addOperand(IObjectExpression operand) {
|
public void addOperand(IObjectExpression operand) {
|
||||||
operands.add(operand);
|
operands.add(operand);
|
||||||
operand.setParent(this);
|
operand.setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ComparisonExpression [operator=" + operator + ", operands=" + operands + "]";
|
return "ComparisonExpression [operator=" + operator + ", operands=" + operands + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ import li.strolch.soql.core.SOQLEvaluationException;
|
||||||
/**
|
/**
|
||||||
* extract state field value by reflection
|
* extract state field value by reflection
|
||||||
*
|
*
|
||||||
|
* TODO: interpret null pointer in chained expression as null !!
|
||||||
|
*
|
||||||
* @author msmock
|
* @author msmock
|
||||||
*/
|
*/
|
||||||
public class MethodExpression extends AbstractObjectExpression {
|
public class MethodExpression extends AbstractObjectExpression {
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
package li.strolch.soql.core;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class MockObject {
|
|
||||||
|
|
||||||
String id = "testId";
|
|
||||||
String name = "testName";
|
|
||||||
String type = "testType";
|
|
||||||
|
|
||||||
Map<String, MockParameter> parameter = new HashMap<>();
|
|
||||||
|
|
||||||
int number = 42;
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumber() {
|
|
||||||
return number;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getParameter(String key) {
|
|
||||||
return parameter.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getParameter(String key, String dummy) {
|
|
||||||
return parameter.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putParameter(String key, MockParameter value) {
|
|
||||||
this.parameter.put(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "MockObject [id=" + id + ", name=" + name + ", type=" + type + ", number=" + number + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package li.strolch.soql.core;
|
|
||||||
|
|
||||||
public class MockParameter {
|
|
||||||
|
|
||||||
String value = "testValue";
|
|
||||||
String type = "testType";
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "MockParameter [value=" + value + ", type=" + type + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,12 +1,12 @@
|
||||||
package li.strolch.soql.core;
|
package li.strolch.soql.core;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import li.strolch.model.ParameterBag;
|
||||||
import static org.junit.Assert.assertTrue;
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.model.StrolchElement;
|
||||||
import java.util.HashMap;
|
import li.strolch.model.parameter.FloatParameter;
|
||||||
import java.util.List;
|
import li.strolch.model.parameter.Parameter;
|
||||||
import java.util.Map;
|
import li.strolch.soql.antlr4.generated.SOQLLexer;
|
||||||
|
import li.strolch.soql.antlr4.generated.SOQLParser;
|
||||||
import org.antlr.v4.runtime.CharStream;
|
import org.antlr.v4.runtime.CharStream;
|
||||||
import org.antlr.v4.runtime.CharStreams;
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
import org.antlr.v4.runtime.CommonTokenStream;
|
import org.antlr.v4.runtime.CommonTokenStream;
|
||||||
|
@ -14,445 +14,439 @@ import org.antlr.v4.runtime.tree.ParseTree;
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import li.strolch.soql.antlr4.generated.SOQLLexer;
|
import java.util.HashMap;
|
||||||
import li.strolch.soql.antlr4.generated.SOQLParser;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class StatementTest {
|
public class StatementTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private ParseTree parseString(final String s) throws Exception {
|
private ParseTree parseString(final String s) throws Exception {
|
||||||
|
|
||||||
CharStream input = CharStreams.fromString(s);
|
CharStream input = CharStreams.fromString(s);
|
||||||
SOQLLexer lexer = new SOQLLexer(input); // create a buffer of tokens pulled from the lexer
|
SOQLLexer lexer = new SOQLLexer(input); // create a buffer of tokens pulled from the lexer
|
||||||
|
|
||||||
CommonTokenStream tokens = new CommonTokenStream(lexer); // create a parser that feeds off the tokens buffer
|
CommonTokenStream tokens = new CommonTokenStream(lexer); // create a parser that feeds off the tokens buffer
|
||||||
SOQLParser parser = new SOQLParser(tokens);
|
SOQLParser parser = new SOQLParser(tokens);
|
||||||
parser.addErrorListener(new VerboseListener());
|
parser.addErrorListener(new VerboseListener());
|
||||||
|
|
||||||
ParseTree tree = parser.select_statement(); // begin parsing at block
|
ParseTree tree = parser.select_statement(); // begin parsing at block
|
||||||
|
|
||||||
System.out.println(tree.toStringTree(parser)); // print LISP-style tree
|
System.out.println(tree.toStringTree(parser)); // print LISP-style tree
|
||||||
|
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tree
|
* @param tree
|
||||||
* @return CompiledSOQLStatement the compiled SOQL statement
|
* @return CompiledSOQLStatement the compiled SOQL statement
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private CompiledStatement compile(final ParseTree tree) throws Exception {
|
private CompiledStatement compile(final ParseTree tree) throws Exception {
|
||||||
|
|
||||||
final ParseTreeWalker walker = new ParseTreeWalker();
|
final ParseTreeWalker walker = new ParseTreeWalker();
|
||||||
final SOQLListener listener = new SOQLListener();
|
final SOQLListener listener = new SOQLListener();
|
||||||
walker.walk(listener, tree);
|
walker.walk(listener, tree);
|
||||||
|
|
||||||
final CompiledStatement soqlStatement = new CompiledStatement();
|
final CompiledStatement soqlStatement = new CompiledStatement();
|
||||||
soqlStatement.entities = listener.getEntities();
|
soqlStatement.entities = listener.getEntities();
|
||||||
soqlStatement.whereExpression = listener.getWhereExpression();
|
soqlStatement.whereExpression = listener.getWhereExpression();
|
||||||
soqlStatement.selectClause = listener.getSelectClause();
|
soqlStatement.selectClause = listener.getSelectClause();
|
||||||
|
|
||||||
return soqlStatement;
|
return soqlStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/**
|
||||||
public void test0() throws Exception {
|
* @return a test parameter with String value
|
||||||
|
*/
|
||||||
|
public StrolchElement getTestElement() {
|
||||||
|
final Resource resource = new Resource();
|
||||||
|
resource.setId("testId");
|
||||||
|
|
||||||
String s = "SELECT r FROM Resource r";
|
final ParameterBag bag = new ParameterBag();
|
||||||
|
bag.setId("testBag");
|
||||||
|
resource.addParameterBag(bag);
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
final Parameter parameter = new FloatParameter();
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
parameter.setId("testId");
|
||||||
|
parameter.setValue(100d);
|
||||||
|
|
||||||
// System.out.println(compiledStatement);
|
resource.addParameter("testBag", parameter);
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
@Test
|
||||||
inputObjects.put("r", new MockObject());
|
public void test0() throws Exception {
|
||||||
|
|
||||||
final Map<String, Object> queryParameter = new HashMap<>();
|
String s = "SELECT r FROM Resource r";
|
||||||
|
|
||||||
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
final ParseTree tree = parseString(s);
|
||||||
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
assertEquals(1, result.size());
|
// System.out.println(compiledStatement);
|
||||||
|
|
||||||
}
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
|
inputObjects.put("r", getTestElement());
|
||||||
|
|
||||||
@Test
|
final Map<String, Object> queryParameter = new HashMap<>();
|
||||||
public void test1() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT r, a, a.getId() FROM Resource r, Activity a";
|
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
assertEquals(1, result.size());
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
|
||||||
|
|
||||||
// System.out.println(compiledStatement);
|
}
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
@Test
|
||||||
inputObjects.put("r", new MockObject());
|
public void test1() throws Exception {
|
||||||
inputObjects.put("a", new MockObject());
|
|
||||||
|
|
||||||
final Map<String, Object> queryParameter = new HashMap<>();
|
String s = "SELECT r, a, a.getId() FROM Resource r, Activity a";
|
||||||
|
|
||||||
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
final ParseTree tree = parseString(s);
|
||||||
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
assertEquals(3, result.size());
|
// System.out.println(compiledStatement);
|
||||||
|
|
||||||
}
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
|
inputObjects.put("r", getTestElement());
|
||||||
|
inputObjects.put("a", getTestElement());
|
||||||
|
|
||||||
/**
|
final Map<String, Object> queryParameter = new HashMap<>();
|
||||||
* positive test of a comparison expression in a WHERE clause
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test2() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT r FROM Resource r WHERE r.getName() = \"testName\"";
|
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
assertEquals(3, result.size());
|
||||||
|
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
}
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
/**
|
||||||
inputObjects.put("r", new MockObject());
|
* positive test of a comparison expression in a WHERE clause
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test2() throws Exception {
|
||||||
|
|
||||||
final Map<String, Object> queryParameter = new HashMap<>();
|
String s = "SELECT r FROM Resource r WHERE r.getId() = \"testId\"";
|
||||||
|
|
||||||
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
final ParseTree tree = parseString(s);
|
||||||
|
|
||||||
assertEquals(1, result.size());
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
* negative test of a comparison expression in a WHERE clause
|
inputObjects.put("r", getTestElement());
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test3() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT r FROM Resource r WHERE r.getName() = \"testNameDiffering\"";
|
final Map<String, Object> queryParameter = new HashMap<>();
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
|
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
assertEquals(1, result.size());
|
||||||
|
}
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
/**
|
||||||
inputObjects.put("r", new MockObject());
|
* negative test of a comparison expression in a WHERE clause
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test3() throws Exception {
|
||||||
|
|
||||||
final Map<String, Object> queryParameter = new HashMap<>();
|
String s = "SELECT r FROM Resource r WHERE r.getId() = \"testIdNoMatch\"";
|
||||||
|
|
||||||
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
final ParseTree tree = parseString(s);
|
||||||
|
|
||||||
assertTrue(result.isEmpty());
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
}
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
|
inputObjects.put("r", getTestElement());
|
||||||
|
|
||||||
/**
|
final Map<String, Object> queryParameter = new HashMap<>();
|
||||||
* positive test of a AND combined comparison expressions in WHERE clause
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test4() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT r, a FROM Resource r, Activity a WHERE r.getType() = a.getType() AND r.getName() = \"testName\"";
|
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
assertTrue(result.isEmpty());
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
}
|
||||||
inputObjects.put("r", new MockObject());
|
|
||||||
inputObjects.put("a", new MockObject());
|
|
||||||
|
|
||||||
final Map<String, Object> parameter = new HashMap<>();
|
/**
|
||||||
|
* positive test of a AND combined comparison expressions in WHERE clause
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test4() throws Exception {
|
||||||
|
|
||||||
final List<Object> result = compiledStatement.evaluate(inputObjects, parameter);
|
String s = "SELECT r, a FROM Resource r, Activity a WHERE r.getId() = a.getId() AND r.getId() = \"testId\"";
|
||||||
|
|
||||||
assertEquals(2, result.size());
|
final ParseTree tree = parseString(s);
|
||||||
}
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
/**
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
* positive test of a comparison expression with query parameter
|
inputObjects.put("r", getTestElement());
|
||||||
*/
|
inputObjects.put("a", getTestElement());
|
||||||
@Test
|
|
||||||
public void test5() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT a FROM Activity a WHERE a.getName() = :outer_var";
|
final Map<String, Object> parameter = new HashMap<>();
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
final List<Object> result = compiledStatement.evaluate(inputObjects, parameter);
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
|
||||||
|
|
||||||
final Map<String, Object> queryParameter = new HashMap<>();
|
assertEquals(2, result.size());
|
||||||
queryParameter.put("outer_var", "testName");
|
}
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
/**
|
||||||
inputObjects.put("a", new MockObject());
|
* positive test of a comparison expression with query parameter
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test5() throws Exception {
|
||||||
|
|
||||||
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
String s = "SELECT a FROM Activity a WHERE a.getId() = :outer_var";
|
||||||
|
|
||||||
assertEquals(1, result.size());
|
final ParseTree tree = parseString(s);
|
||||||
}
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
/**
|
final Map<String, Object> queryParameter = new HashMap<>();
|
||||||
* positive test of a method call in comparison expression of a WHERE clause
|
queryParameter.put("outer_var", "testId");
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test6() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT a FROM Activity a WHERE a.getNumber() < :parameter";
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
|
inputObjects.put("a", getTestElement());
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
assertEquals(1, result.size());
|
||||||
inputObjects.put("a", new MockObject());
|
}
|
||||||
|
|
||||||
final Map<String, Object> queryParameter = new HashMap<>();
|
/**
|
||||||
queryParameter.put("parameter", 1234);
|
* positive test of a method call in comparison expression of a WHERE clause
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test6() throws Exception {
|
||||||
|
|
||||||
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
String s = "SELECT a FROM Activity a WHERE a.getParameter(:p_1, :p_2).getValue() < :parameter";
|
||||||
|
|
||||||
assertEquals(1, result.size());
|
final ParseTree tree = parseString(s);
|
||||||
}
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
/**
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
* negative test of a method call in comparison expression of a WHERE clause
|
inputObjects.put("a", getTestElement());
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test8() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT a FROM Activity a WHERE a.getNumber() > :parameter";
|
final Map<String, Object> queryParameter = new HashMap<>();
|
||||||
|
queryParameter.put("p_1", "testBag");
|
||||||
|
queryParameter.put("p_2", "testId");
|
||||||
|
queryParameter.put("parameter", 101d);
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
assertEquals(1, result.size());
|
||||||
inputObjects.put("a", new MockObject());
|
}
|
||||||
|
|
||||||
final Map<String, Object> queryParameter = new HashMap<>();
|
/**
|
||||||
queryParameter.put("parameter", 122);
|
* negative test of a method call in comparison expression of a WHERE clause
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test8() throws Exception {
|
||||||
|
|
||||||
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
String s = "SELECT a FROM Activity a WHERE a.getParameter(:p_1, :p_2).getValue() > :parameter";
|
||||||
|
|
||||||
assertEquals(0, result.size());
|
final ParseTree tree = parseString(s);
|
||||||
}
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
/**
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
* negative test of a method call in SELECT statement
|
inputObjects.put("a", getTestElement());
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test9() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT a.getParameter(:param_1) FROM Activity a";
|
final Map<String, Object> queryParameter = new HashMap<>();
|
||||||
|
queryParameter.put("p_1", "testBag");
|
||||||
|
queryParameter.put("p_2", "testId");
|
||||||
|
queryParameter.put("parameter", 101d);
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
final List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
assertEquals(0, result.size());
|
||||||
|
}
|
||||||
|
|
||||||
final MockObject a = new MockObject();
|
/**
|
||||||
|
* negative test of a method call in SELECT statement
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test9() throws Exception {
|
||||||
|
|
||||||
String matchingKey = "pid";
|
String s = "SELECT a.getParameterBag(:param_1) FROM Resource a";
|
||||||
a.putParameter(matchingKey, new MockParameter());
|
|
||||||
|
|
||||||
inputObjects.put("a", a);
|
final ParseTree tree = parseString(s);
|
||||||
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
Map<String, Object> queryParameter = new HashMap<>();
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
queryParameter.put("param_1", matchingKey);
|
|
||||||
|
|
||||||
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
inputObjects.put("a", getTestElement());
|
||||||
|
|
||||||
assertEquals(1, result.size());
|
Map<String, Object> queryParameter = new HashMap<>();
|
||||||
|
queryParameter.put("param_1", "testBag");
|
||||||
|
|
||||||
String nonMatchingKey = "noPid";
|
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
|
|
||||||
queryParameter = new HashMap<>();
|
assertEquals(1, result.size());
|
||||||
queryParameter.put("param_1", nonMatchingKey);
|
|
||||||
|
|
||||||
result = compiledStatement.evaluate(inputObjects, queryParameter);
|
String nonMatchingKey = "noPid";
|
||||||
|
|
||||||
assertTrue(result.isEmpty());
|
queryParameter = new HashMap<>();
|
||||||
}
|
queryParameter.put("param_1", nonMatchingKey);
|
||||||
|
|
||||||
/**
|
result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
* positive test of a method call with multiple method arguments
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test10() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT a.getParameter(:param_1,:param_2) FROM Activity a";
|
assertTrue(result.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
/**
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
* positive test of a method call with multiple method arguments
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test10() throws Exception {
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
String s = "SELECT a.getParameter(:param_1,:param_2) FROM Activity a";
|
||||||
|
|
||||||
final MockObject a = new MockObject();
|
final ParseTree tree = parseString(s);
|
||||||
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
String matchingKey = "pid";
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
a.putParameter(matchingKey, new MockParameter());
|
|
||||||
|
|
||||||
inputObjects.put("a", a);
|
inputObjects.put("a", getTestElement());
|
||||||
|
|
||||||
Map<String, Object> queryParameter = new HashMap<>();
|
Map<String, Object> queryParameter = new HashMap<>();
|
||||||
queryParameter.put("param_1", matchingKey);
|
queryParameter.put("param_1", "testBag");
|
||||||
queryParameter.put("param_2", matchingKey);
|
queryParameter.put("param_2", "testId");
|
||||||
|
|
||||||
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
|
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
|
|
||||||
String nonMatchingKey = "noPid";
|
queryParameter = new HashMap<>();
|
||||||
|
queryParameter.put("param_1", "nex");
|
||||||
|
queryParameter.put("param_2", "testId");
|
||||||
|
|
||||||
queryParameter = new HashMap<>();
|
result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
queryParameter.put("param_1", nonMatchingKey);
|
|
||||||
queryParameter.put("param_2", "");
|
|
||||||
|
|
||||||
result = compiledStatement.evaluate(inputObjects, queryParameter);
|
assertTrue(result.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
assertTrue(result.isEmpty());
|
/**
|
||||||
}
|
* positive test of a chained method call in SELECT clause
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test11() throws Exception {
|
||||||
|
|
||||||
/**
|
String s = "SELECT a.getParameterBag(:param_1).getId() FROM Activity a";
|
||||||
* positive test of a chained method call in SELECT clause
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test11() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT a.getParameter(:param_1).getType() FROM Activity a";
|
final ParseTree tree = parseString(s);
|
||||||
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
inputObjects.put("a", getTestElement());
|
||||||
|
|
||||||
final MockObject a = new MockObject();
|
final Map<String, Object> queryParameter = new HashMap<>();
|
||||||
|
queryParameter.put("param_1", "testBag");
|
||||||
|
|
||||||
String matchingKey = "pid";
|
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
a.putParameter(matchingKey, new MockParameter());
|
|
||||||
|
|
||||||
inputObjects.put("a", a);
|
assertEquals(1, result.size());
|
||||||
|
|
||||||
final Map<String, Object> queryParameter = new HashMap<>();
|
assertEquals("testBag", result.get(0));
|
||||||
queryParameter.put("param_1", matchingKey);
|
}
|
||||||
|
|
||||||
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
/**
|
||||||
|
* positive test of a chained method call in WHERE clause
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test12() throws Exception {
|
||||||
|
|
||||||
assertEquals(1, result.size());
|
String s = "SELECT a FROM Activity a WHERE a.getParameter(:p_1, :p_2).getType() = \"Float\"";
|
||||||
|
|
||||||
assertEquals("testType", result.get(0));
|
final ParseTree tree = parseString(s);
|
||||||
}
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
/**
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
* positive test of a chained method call in WHERE clause
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test12() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT a FROM Activity a WHERE a.getParameter(:param_1).getType() = \"testType\"";
|
inputObjects.put("a", getTestElement());
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
final Map<String, Object> queryParameter = new HashMap<>();
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
queryParameter.put("p_1", "testBag");
|
||||||
|
queryParameter.put("p_2", "testId");
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
|
|
||||||
final MockObject a = new MockObject();
|
assertEquals(1, result.size());
|
||||||
|
|
||||||
String matchingKey = "pid";
|
}
|
||||||
a.putParameter(matchingKey, new MockParameter());
|
|
||||||
|
|
||||||
inputObjects.put("a", a);
|
/**
|
||||||
|
* negative test of a chained method call in WHERE clause
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test14() throws Exception {
|
||||||
|
|
||||||
final Map<String, Object> queryParameter = new HashMap<>();
|
String s = "SELECT a FROM Activity a WHERE a.getParameter(:p_1, :p_2).getType() = :p_3";
|
||||||
queryParameter.put("param_1", matchingKey);
|
|
||||||
|
|
||||||
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
final ParseTree tree = parseString(s);
|
||||||
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
assertEquals(1, result.size());
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
|
|
||||||
}
|
inputObjects.put("a", getTestElement());
|
||||||
|
|
||||||
/**
|
final Map<String, Object> queryParameter = new HashMap<>();
|
||||||
* negative test of a chained method call in WHERE clause
|
queryParameter.put("p_1", "testBag");
|
||||||
*/
|
queryParameter.put("p_2", "testId");
|
||||||
@Test
|
queryParameter.put("p_3", "String");
|
||||||
public void test14() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT a FROM Activity a WHERE a.getParameter(:param_1).getType() = :param_2";
|
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
assertEquals(0, result.size());
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
}
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
/**
|
||||||
|
* test an where expression with a NOT inversion
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test15() throws Exception {
|
||||||
|
|
||||||
final MockObject a = new MockObject();
|
String s = "SELECT a FROM Activity a WHERE NOT a.getParameter(:p_1, :p_2).getType() = :p_3";
|
||||||
|
|
||||||
final String matchingKey = "pid";
|
final ParseTree tree = parseString(s);
|
||||||
a.putParameter(matchingKey, new MockParameter());
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
inputObjects.put("a", a);
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
|
|
||||||
final Map<String, Object> queryParameter = new HashMap<>();
|
inputObjects.put("a", getTestElement());
|
||||||
queryParameter.put("param_1", matchingKey);
|
|
||||||
queryParameter.put("param_2", "notMatchingString");
|
|
||||||
|
|
||||||
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
final Map<String, Object> queryParameter = new HashMap<>();
|
||||||
|
queryParameter.put("p_1", "testBag");
|
||||||
|
queryParameter.put("p_2", "testId");
|
||||||
|
queryParameter.put("p_3", "String");
|
||||||
|
|
||||||
assertEquals(0, result.size());
|
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
assertEquals(1, result.size());
|
||||||
* test an where expression with a NOT inversion
|
}
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test15() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT a FROM Activity a WHERE NOT a.getParameter(:param_1).getType() = :param_2";
|
/**
|
||||||
|
* test null pointer in chained method calls, when the first call returns null
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test16() throws Exception {
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
String s = "SELECT a FROM Activity a WHERE a.getParameter(:p_1, :p_2).getType() = :p_3";
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
final ParseTree tree = parseString(s);
|
||||||
|
final CompiledStatement compiledStatement = compile(tree);
|
||||||
|
|
||||||
final MockObject a = new MockObject();
|
final Map<String, Object> inputObjects = new HashMap<>();
|
||||||
|
|
||||||
final String matchingKey = "pid";
|
inputObjects.put("a", getTestElement());
|
||||||
a.putParameter(matchingKey, new MockParameter());
|
|
||||||
|
|
||||||
inputObjects.put("a", a);
|
final Map<String, Object> queryParameter = new HashMap<>();
|
||||||
|
queryParameter.put("p_1", "testBag");
|
||||||
|
queryParameter.put("p_2", "bullshitId");
|
||||||
|
queryParameter.put("p_3", "String");
|
||||||
|
|
||||||
final Map<String, Object> queryParameter = new HashMap<>();
|
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
||||||
queryParameter.put("param_1", matchingKey);
|
|
||||||
queryParameter.put("param_2", "notMatchingString");
|
|
||||||
|
|
||||||
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
assertEquals(0, result.size());
|
||||||
|
}
|
||||||
assertEquals(1, result.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test an where expression with a NOT inversion
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test16() throws Exception {
|
|
||||||
|
|
||||||
String s = "SELECT a FROM Activity a WHERE a.getParameter(:param_1).getType() = :param_2";
|
|
||||||
|
|
||||||
final ParseTree tree = parseString(s);
|
|
||||||
final CompiledStatement compiledStatement = compile(tree);
|
|
||||||
|
|
||||||
final Map<String, Object> inputObjects = new HashMap<>();
|
|
||||||
|
|
||||||
final MockObject a = new MockObject();
|
|
||||||
|
|
||||||
final String matchingKey = "pid";
|
|
||||||
a.putParameter(matchingKey, new MockParameter());
|
|
||||||
|
|
||||||
inputObjects.put("a", a);
|
|
||||||
|
|
||||||
final Map<String, Object> queryParameter = new HashMap<>();
|
|
||||||
queryParameter.put("param_1", matchingKey);
|
|
||||||
queryParameter.put("param_2", "testType");
|
|
||||||
|
|
||||||
List<Object> result = compiledStatement.evaluate(inputObjects, queryParameter);
|
|
||||||
|
|
||||||
assertEquals(1, result.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,13 @@ import static org.junit.Assert.assertEquals;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import li.strolch.model.ParameterBag;
|
||||||
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.model.StrolchElement;
|
||||||
|
import li.strolch.model.parameter.Parameter;
|
||||||
|
import li.strolch.model.parameter.StringParameter;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import li.strolch.soql.core.MockObject;
|
|
||||||
import li.strolch.soql.core.MockParameter;
|
|
||||||
import li.strolch.soql.core.expresssion.ChainedMethodExpression;
|
import li.strolch.soql.core.expresssion.ChainedMethodExpression;
|
||||||
import li.strolch.soql.core.expresssion.MethodArgumentDeclaration;
|
import li.strolch.soql.core.expresssion.MethodArgumentDeclaration;
|
||||||
import li.strolch.soql.core.expresssion.MethodExpression;
|
import li.strolch.soql.core.expresssion.MethodExpression;
|
||||||
|
@ -16,6 +19,25 @@ import li.strolch.soql.core.expresssion.ParameterReference;
|
||||||
|
|
||||||
public class ChainedMethodExpressionTest {
|
public class ChainedMethodExpressionTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a test parameter with String value
|
||||||
|
*/
|
||||||
|
public StrolchElement getTestElement() {
|
||||||
|
final Resource resource = new Resource();
|
||||||
|
resource.setId("testId");
|
||||||
|
|
||||||
|
final ParameterBag bag = new ParameterBag();
|
||||||
|
bag.setId("testBag");
|
||||||
|
resource.addParameterBag(bag);
|
||||||
|
|
||||||
|
final Parameter parameter = new StringParameter();
|
||||||
|
parameter.setId("testId");
|
||||||
|
parameter.setValue("testValue");
|
||||||
|
|
||||||
|
resource.addParameter("testBag", parameter);
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
|
|
||||||
|
@ -38,11 +60,9 @@ public class ChainedMethodExpressionTest {
|
||||||
chainedMethodExpression.addMethodExpression(methodExpression);
|
chainedMethodExpression.addMethodExpression(methodExpression);
|
||||||
|
|
||||||
// prepare the runtime objects
|
// prepare the runtime objects
|
||||||
MockObject mockObject = new MockObject();
|
|
||||||
mockObject.putParameter(matchingKey, new MockParameter());
|
|
||||||
|
|
||||||
Map<String, Object> inputObjects = new HashMap<>();
|
Map<String, Object> inputObjects = new HashMap<>();
|
||||||
inputObjects.put("a", mockObject);
|
inputObjects.put("a", getTestElement());
|
||||||
|
|
||||||
Map<String, Object> queryParameter = new HashMap<>();
|
Map<String, Object> queryParameter = new HashMap<>();
|
||||||
queryParameter.put("param_1", matchingKey);
|
queryParameter.put("param_1", matchingKey);
|
||||||
|
@ -50,7 +70,7 @@ public class ChainedMethodExpressionTest {
|
||||||
// evaluate the chained expression
|
// evaluate the chained expression
|
||||||
Object result = chainedMethodExpression.evaluate(inputObjects, queryParameter);
|
Object result = chainedMethodExpression.evaluate(inputObjects, queryParameter);
|
||||||
|
|
||||||
assertEquals(MockParameter.class, result.getClass());
|
assertEquals(StringParameter.class, result.getClass());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,11 +101,9 @@ public class ChainedMethodExpressionTest {
|
||||||
chainedMethodExpression.addMethodExpression(methodExpression_2);
|
chainedMethodExpression.addMethodExpression(methodExpression_2);
|
||||||
|
|
||||||
// prepare the runtime objects
|
// prepare the runtime objects
|
||||||
MockObject mockObject = new MockObject();
|
|
||||||
mockObject.putParameter(matchingKey, new MockParameter());
|
|
||||||
|
|
||||||
Map<String, Object> inputObjects = new HashMap<>();
|
Map<String, Object> inputObjects = new HashMap<>();
|
||||||
inputObjects.put("a", mockObject);
|
inputObjects.put("a", getTestElement());
|
||||||
|
|
||||||
Map<String, Object> queryParameter = new HashMap<>();
|
Map<String, Object> queryParameter = new HashMap<>();
|
||||||
queryParameter.put("param_1", matchingKey);
|
queryParameter.put("param_1", matchingKey);
|
||||||
|
|
|
@ -5,27 +5,47 @@ import static org.junit.Assert.assertEquals;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import li.strolch.model.ParameterBag;
|
||||||
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.model.StrolchElement;
|
||||||
|
import li.strolch.model.parameter.Parameter;
|
||||||
|
import li.strolch.model.parameter.StringListParameter;
|
||||||
|
import li.strolch.model.parameter.StringParameter;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import li.strolch.soql.core.MockObject;
|
|
||||||
import li.strolch.soql.core.MockParameter;
|
|
||||||
import li.strolch.soql.core.expresssion.MethodArgumentDeclaration;
|
import li.strolch.soql.core.expresssion.MethodArgumentDeclaration;
|
||||||
import li.strolch.soql.core.expresssion.MethodExpression;
|
import li.strolch.soql.core.expresssion.MethodExpression;
|
||||||
import li.strolch.soql.core.expresssion.ParameterReference;
|
import li.strolch.soql.core.expresssion.ParameterReference;
|
||||||
|
|
||||||
public class MethodExpressionTest {
|
public class MethodExpressionTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a test parameter with String value
|
||||||
|
*/
|
||||||
|
public StrolchElement getTestElement() {
|
||||||
|
final Resource resource = new Resource();
|
||||||
|
resource.setId("testId");
|
||||||
|
|
||||||
|
final ParameterBag bag = new ParameterBag();
|
||||||
|
bag.setId("testBag");
|
||||||
|
resource.addParameterBag(bag);
|
||||||
|
|
||||||
|
final Parameter parameter = new StringParameter();
|
||||||
|
parameter.setId("testId");
|
||||||
|
parameter.setValue("testValue");
|
||||||
|
|
||||||
|
resource.addParameter("testBag", parameter);
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
|
|
||||||
String matchingKey = "testString";
|
String matchingKey = "testString";
|
||||||
|
|
||||||
MockObject mockObject = new MockObject();
|
|
||||||
mockObject.putParameter(matchingKey, new MockParameter());
|
|
||||||
|
|
||||||
MethodExpression methodExpression = new MethodExpression();
|
MethodExpression methodExpression = new MethodExpression();
|
||||||
methodExpression.setMethodName("getParameter");
|
methodExpression.setMethodName("getParameter");
|
||||||
methodExpression.setObject(mockObject);
|
methodExpression.setObject(getTestElement());
|
||||||
|
|
||||||
ParameterReference parameterReference = new ParameterReference();
|
ParameterReference parameterReference = new ParameterReference();
|
||||||
parameterReference.varName = "param_1";
|
parameterReference.varName = "param_1";
|
||||||
|
@ -40,7 +60,7 @@ public class MethodExpressionTest {
|
||||||
|
|
||||||
Object result = methodExpression.evaluate(null, queryParameter);
|
Object result = methodExpression.evaluate(null, queryParameter);
|
||||||
|
|
||||||
assertEquals(MockParameter.class, result.getClass());
|
assertEquals(StringParameter.class, result.getClass());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue