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);
}
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]);
}
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);
}
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);
}
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);
}
Aggregations