Search in sources :

Example 1 with LiteralOperand

use of org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand in project milo by eclipse.

the class EqualsTest method testScalar.

@Test
public void testScalar() throws Exception {
    OperatorContext context = mock(OperatorContext.class);
    BaseEventTypeNode eventNode = mock(BaseEventTypeNode.class);
    FilterOperand op0 = new LiteralOperand(new Variant(42));
    FilterOperand op1 = new LiteralOperand(new Variant(42));
    when(context.resolve(op0, eventNode)).thenReturn(42);
    when(context.resolve(op1, eventNode)).thenReturn(42);
    Boolean result = Operators.EQUALS.apply(context, eventNode, new FilterOperand[] { op0, op1 });
    assertNotNull(result);
    assertTrue(result);
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) LiteralOperand(org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand) OperatorContext(org.eclipse.milo.opcua.sdk.server.events.OperatorContext) FilterOperand(org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand) Test(org.testng.annotations.Test)

Example 2 with LiteralOperand

use of org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand in project milo by eclipse.

the class EventContentFilter method validateFilterElement.

private static ContentFilterElementResult validateFilterElement(@NotNull FilterContext context, @NotNull ContentFilterElement filterElement) {
    FilterOperator filterOperator = filterElement.getFilterOperator();
    if (!Operators.SUPPORTED_OPERATORS.contains(filterOperator)) {
        return new ContentFilterElementResult(new StatusCode(StatusCodes.Bad_FilterOperatorUnsupported), new StatusCode[0], new DiagnosticInfo[0]);
    }
    ExtensionObject[] xos = filterElement.getFilterOperands();
    if (xos == null || xos.length == 0) {
        return new ContentFilterElementResult(new StatusCode(StatusCodes.Bad_FilterOperandCountMismatch), new StatusCode[0], new DiagnosticInfo[0]);
    }
    FilterOperand[] operands = new FilterOperand[xos.length];
    StatusCode[] operandStatusCodes = new StatusCode[xos.length];
    for (int i = 0; i < xos.length; i++) {
        Object operand = xos[i].decodeOrNull(context.getServer().getSerializationContext());
        if (operand instanceof FilterOperand) {
            operands[i] = (FilterOperand) operand;
            if (operand instanceof SimpleAttributeOperand) {
                try {
                    validateSimpleOperand(context, (SimpleAttributeOperand) operand);
                    operandStatusCodes[i] = StatusCode.GOOD;
                } catch (ValidationException e) {
                    operandStatusCodes[i] = e.getStatusCode();
                }
            } else if (operand instanceof ElementOperand) {
                operandStatusCodes[i] = StatusCode.GOOD;
            } else if (operand instanceof LiteralOperand) {
                operandStatusCodes[i] = StatusCode.GOOD;
            } else {
                // includes AttributeOperand and any unknown/unhandle subclasses
                operandStatusCodes[i] = new StatusCode(StatusCodes.Bad_FilterOperandInvalid);
            }
        } else {
            operandStatusCodes[i] = new StatusCode(StatusCodes.Bad_FilterOperandInvalid);
        }
    }
    StatusCode operatorStatus = StatusCode.GOOD;
    try {
        Operator<?> operator = getOperator(filterOperator);
        operator.validate(context, operands);
    } catch (ValidationException e) {
        operatorStatus = e.getStatusCode();
    }
    return new ContentFilterElementResult(operatorStatus, operandStatusCodes, new DiagnosticInfo[0]);
}
Also used : LiteralOperand(org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) ElementOperand(org.eclipse.milo.opcua.stack.core.types.structured.ElementOperand) FilterOperator(org.eclipse.milo.opcua.stack.core.types.enumerated.FilterOperator) SimpleAttributeOperand(org.eclipse.milo.opcua.stack.core.types.structured.SimpleAttributeOperand) FilterOperand(org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) ContentFilterElementResult(org.eclipse.milo.opcua.stack.core.types.structured.ContentFilterElementResult)

Example 3 with LiteralOperand

use of org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand in project milo by eclipse.

the class IsNullTest method testNonNullValue.

@Test
public void testNonNullValue() throws Exception {
    OperatorContext context = mock(OperatorContext.class);
    BaseEventTypeNode eventNode = mock(BaseEventTypeNode.class);
    FilterOperand op0 = new LiteralOperand(new Variant(42));
    when(context.resolve(op0, eventNode)).thenReturn(42);
    Boolean result = Operators.IS_NULL.apply(context, eventNode, new FilterOperand[] { op0 });
    assertNotNull(result);
    assertFalse(result);
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) LiteralOperand(org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand) OperatorContext(org.eclipse.milo.opcua.sdk.server.events.OperatorContext) FilterOperand(org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand) Test(org.testng.annotations.Test)

Example 4 with LiteralOperand

use of org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand in project milo by eclipse.

the class IsNullTest method testNullValue.

@Test
public void testNullValue() throws Exception {
    OperatorContext context = mock(OperatorContext.class);
    BaseEventTypeNode eventNode = mock(BaseEventTypeNode.class);
    FilterOperand op0 = new LiteralOperand(new Variant(null));
    when(context.resolve(op0, eventNode)).thenReturn(null);
    Boolean result = Operators.IS_NULL.apply(context, eventNode, new FilterOperand[] { op0 });
    assertNotNull(result);
    assertTrue(result);
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) LiteralOperand(org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand) OperatorContext(org.eclipse.milo.opcua.sdk.server.events.OperatorContext) FilterOperand(org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand) Test(org.testng.annotations.Test)

Example 5 with LiteralOperand

use of org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand in project milo by eclipse.

the class EqualsTest method testScalarNotEqual.

@Test
public void testScalarNotEqual() throws Exception {
    OperatorContext context = mock(OperatorContext.class);
    BaseEventTypeNode eventNode = mock(BaseEventTypeNode.class);
    FilterOperand op0 = new LiteralOperand(new Variant(1));
    FilterOperand op1 = new LiteralOperand(new Variant(2));
    when(context.resolve(op0, eventNode)).thenReturn(1);
    when(context.resolve(op1, eventNode)).thenReturn(2);
    Boolean result = Operators.EQUALS.apply(context, eventNode, new FilterOperand[] { op0, op1 });
    assertNotNull(result);
    assertFalse(result);
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) LiteralOperand(org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand) OperatorContext(org.eclipse.milo.opcua.sdk.server.events.OperatorContext) FilterOperand(org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand) Test(org.testng.annotations.Test)

Aggregations

FilterOperand (org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand)9 LiteralOperand (org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand)9 OperatorContext (org.eclipse.milo.opcua.sdk.server.events.OperatorContext)8 BaseEventTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode)8 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)8 Test (org.testng.annotations.Test)8 ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)1 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)1 FilterOperator (org.eclipse.milo.opcua.stack.core.types.enumerated.FilterOperator)1 ContentFilterElementResult (org.eclipse.milo.opcua.stack.core.types.structured.ContentFilterElementResult)1 ElementOperand (org.eclipse.milo.opcua.stack.core.types.structured.ElementOperand)1 SimpleAttributeOperand (org.eclipse.milo.opcua.stack.core.types.structured.SimpleAttributeOperand)1