use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class Switch method testWithNotEnoughParameters.
@Test
public void testWithNotEnoughParameters() throws Exception {
FunctionInterface fi = fff.getInstance(cl, "Switch");
fi.reset();
Navajo n = createTestNavajo();
fi.setInMessage(n);
fi.insertOperand(Expression.evaluate("[/Single/Vuur]", n));
fi.insertIntegerOperand(20);
fi.insertIntegerOperand(-20);
try {
Object result = fi.evaluate();
} catch (TMLExpressionException tmle) {
assertTrue(tmle.getMessage().indexOf("Not enough") != -1);
}
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class Switch method testWithOnlyPropertyParameter.
@Test
public void testWithOnlyPropertyParameter() throws Exception {
FunctionInterface fi = fff.getInstance(cl, "Switch");
fi.reset();
Navajo n = createTestNavajo();
fi.setInMessage(n);
fi.insertOperand(Expression.evaluate("[/Single/Vuur]", n));
try {
Object result = fi.evaluate();
} catch (TMLExpressionException tmle) {
assertTrue(tmle.getMessage().indexOf("Not enough") != -1);
}
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class Zip method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
if (getOperands().size() != 2) {
return new TMLExpressionException(this, "Wrong number of arguments");
}
if (!(getOperand(0) instanceof Binary)) {
return new TMLExpressionException(this, "Binary content expected");
}
if (!(getOperand(1) instanceof String)) {
return new TMLExpressionException(this, "String expected");
}
Binary i = (Binary) getOperand(0);
String f = (String) getOperand(1);
File tempFile = null;
try {
tempFile = File.createTempFile("zip_function", "navajo");
System.err.println("Created tempfile: " + tempFile.getAbsolutePath());
FileOutputStream fos = new FileOutputStream(tempFile);
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zo = new ZipOutputStream(fos);
ZipEntry entry = new ZipEntry(f);
zo.putNextEntry(entry);
// zo.write( i.getData() );
i.write(zo, false);
fos.flush();
zo.closeEntry();
zo.close();
// byte [] result = baos.toByteArray();
fos.close();
Binary b = new Binary(tempFile, false);
return b;
} catch (Exception e) {
throw new TMLExpressionException(this, e.getMessage(), e);
} finally {
if (tempFile != null) {
tempFile.delete();
}
}
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class TestCompiledExpression method parseIntAddition.
@Test
public void parseIntAddition() throws ParseException, TMLExpressionException {
List<String> problems = new ArrayList<>();
String expression = "1+1";
ContextExpression ss = ExpressionCache.getInstance().parse(problems, expression, fn -> FunctionClassification.DEFAULT);
ContextExpression ss2 = ExpressionCache.getInstance().parse(problems, expression, fn -> FunctionClassification.DEFAULT);
if (!problems.isEmpty()) {
throw new TMLExpressionException(problems, expression);
}
Assert.assertEquals(2, ss.apply().value);
Assert.assertEquals(2, ss2.apply().value);
Assert.assertTrue(ss.isLiteral());
Assert.assertTrue(ss2.isLiteral());
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class TestCompiledExpression method testParseTmlConditionalComplex.
@Test
@Ignore
public void testParseTmlConditionalComplex() throws ParseException, TMLExpressionException {
String expression = "{request@.:!?[/NewMemberFunction/FromUnion]} AND {response@.:!?[/ExistingClubFunction/PersonId]}";
StringReader sr = new StringReader(expression);
CompiledParser cp = new CompiledParser(sr);
cp.Expression();
List<String> problems = new ArrayList<>();
ContextExpression ss = cp.getJJTree().rootNode().interpretToLambda(problems, sr.toString(), fn -> FunctionClassification.DEFAULT, name -> Optional.empty());
if (!problems.isEmpty()) {
throw new TMLExpressionException(problems, expression);
}
ss.apply();
}
Aggregations