Search in sources :

Example 1 with ConditionFunction

use of com.adaptris.core.services.conditional.conditions.ConditionFunction in project interlok by adaptris.

the class ConditionFunctionTest method testScriptCondition_WrongFunction.

@Test(expected = CoreException.class)
public void testScriptCondition_WrongFunction() throws Exception {
    ConditionFunction condition = new ConditionFunction("function wrongFunctionName(message) {return true;}");
    try {
        LifecycleHelper.initAndStart(condition);
        condition.evaluate(createMessage());
    } finally {
        LifecycleHelper.stopAndClose(condition);
    }
}
Also used : ConditionFunction(com.adaptris.core.services.conditional.conditions.ConditionFunction) Test(org.junit.Test)

Example 2 with ConditionFunction

use of com.adaptris.core.services.conditional.conditions.ConditionFunction in project interlok by adaptris.

the class ConditionFunctionTest method testScriptConditionAgainstMetadata.

@Test
public void testScriptConditionAgainstMetadata() throws Exception {
    ConditionFunction condition = new ConditionFunction("function evaluateScript(message) { return message.getMetadataValue('key').equals('value');}");
    try {
        LifecycleHelper.initAndStart(condition);
        assertTrue(condition.evaluate(createMessage()));
        assertFalse(condition.evaluate(createMessage("key", "anotherValue")));
    } finally {
        LifecycleHelper.stopAndClose(condition);
    }
}
Also used : ConditionFunction(com.adaptris.core.services.conditional.conditions.ConditionFunction) Test(org.junit.Test)

Example 3 with ConditionFunction

use of com.adaptris.core.services.conditional.conditions.ConditionFunction in project interlok by adaptris.

the class ConditionFunctionTest method testScriptCondition_BrokenFunction.

@Test(expected = CoreException.class)
public void testScriptCondition_BrokenFunction() throws Exception {
    ConditionFunction condition = new ConditionFunction("function evaluateScript(message) }");
    LifecycleHelper.initAndStart(condition);
}
Also used : ConditionFunction(com.adaptris.core.services.conditional.conditions.ConditionFunction) Test(org.junit.Test)

Example 4 with ConditionFunction

use of com.adaptris.core.services.conditional.conditions.ConditionFunction in project interlok by adaptris.

the class ConditionFunctionTest method testScriptCondition_False.

@Test
public void testScriptCondition_False() throws Exception {
    ConditionFunction condition = new ConditionFunction("function evaluateScript(message) { return false; }");
    try {
        LifecycleHelper.initAndStart(condition);
        assertFalse(condition.evaluate(createMessage()));
    } finally {
        LifecycleHelper.stopAndClose(condition);
    }
}
Also used : ConditionFunction(com.adaptris.core.services.conditional.conditions.ConditionFunction) Test(org.junit.Test)

Example 5 with ConditionFunction

use of com.adaptris.core.services.conditional.conditions.ConditionFunction in project interlok by adaptris.

the class IfElseTest method retrieveObjectForSampleConfig.

@Override
protected Object retrieveObjectForSampleConfig() {
    IfElse result = new IfElse();
    ConditionMetadata condition = new ConditionMetadata();
    condition.setMetadataKey("key1");
    condition.setOperator(new NotNull());
    Equals equals = new Equals();
    equals.setValue("myValue");
    ConditionMetadata condition2 = new ConditionMetadata();
    condition2.setMetadataKey("key2");
    condition2.setOperator(equals);
    ConditionOr conditionOr = new ConditionOr();
    ConditionExpression conditionExpression = new ConditionExpression();
    conditionExpression.setAlgorithm("(%message{key1} - 10) == %message{key2}");
    conditionOr.getConditions().add(conditionExpression);
    conditionOr.getConditions().add(condition2);
    ConditionAnd conditionAnd = new ConditionAnd();
    conditionAnd.getConditions().add(condition);
    conditionAnd.getConditions().add(conditionOr);
    conditionAnd.getConditions().add(new ConditionFunction("function evaluateScript(message) { return message.getMetadataValue('mykey').equals('myvalue');}"));
    ThenService thenSrvc = new ThenService();
    ElseService elseSrvc = new ElseService();
    thenSrvc.setService(new LogMessageService());
    elseSrvc.setService(new LogMessageService());
    result.setCondition(conditionAnd);
    result.setThen(thenSrvc);
    result.setOtherwise(elseSrvc);
    return result;
}
Also used : ConditionAnd(com.adaptris.core.services.conditional.conditions.ConditionAnd) ConditionFunction(com.adaptris.core.services.conditional.conditions.ConditionFunction) Equals(com.adaptris.core.services.conditional.operator.Equals) ConditionOr(com.adaptris.core.services.conditional.conditions.ConditionOr) ConditionExpression(com.adaptris.core.services.conditional.conditions.ConditionExpression) LogMessageService(com.adaptris.core.services.LogMessageService) ConditionMetadata(com.adaptris.core.services.conditional.conditions.ConditionMetadata) NotNull(com.adaptris.core.services.conditional.operator.NotNull)

Aggregations

ConditionFunction (com.adaptris.core.services.conditional.conditions.ConditionFunction)7 Test (org.junit.Test)6 LogMessageService (com.adaptris.core.services.LogMessageService)1 ConditionAnd (com.adaptris.core.services.conditional.conditions.ConditionAnd)1 ConditionExpression (com.adaptris.core.services.conditional.conditions.ConditionExpression)1 ConditionMetadata (com.adaptris.core.services.conditional.conditions.ConditionMetadata)1 ConditionOr (com.adaptris.core.services.conditional.conditions.ConditionOr)1 Equals (com.adaptris.core.services.conditional.operator.Equals)1 NotNull (com.adaptris.core.services.conditional.operator.NotNull)1