use of org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilter in project milo by eclipse.
the class UaVariableNodeTest method readAttributeWithIncorrectDataType.
@Test
public void readAttributeWithIncorrectDataType() throws UaException {
testNamespace.configureNode((nodeContext, nodeManager) -> {
org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode serverNode = new org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode.UaVariableNodeBuilder(nodeContext).setNodeId(new NodeId(testNamespace.getNamespaceIndex(), "IncorrectMinimumSamplingIntervalDataType")).setAccessLevel(AccessLevel.READ_WRITE).setUserAccessLevel(AccessLevel.READ_WRITE).setBrowseName(new QualifiedName(testNamespace.getNamespaceIndex(), "IncorrectMinimumSamplingIntervalDataType")).setDisplayName(LocalizedText.english("IncorrectMinimumSamplingIntervalDataType")).setDataType(Identifiers.Double).setTypeDefinition(Identifiers.BaseDataVariableType).build();
serverNode.getFilterChain().addLast(new AttributeFilter() {
@Override
public Object getAttribute(AttributeFilterContext.GetAttributeContext ctx, AttributeId attributeId) {
if (attributeId == AttributeId.MinimumSamplingInterval) {
// intentionally return the wrong datatype
return uint(100);
} else {
return ctx.getAttribute(attributeId);
}
}
});
serverNode.addReference(new Reference(serverNode.getNodeId(), Identifiers.HasComponent, Identifiers.ObjectsFolder.expanded(), Reference.Direction.INVERSE));
nodeManager.addNode(serverNode);
});
UaVariableNode variableNode = client.getAddressSpace().getVariableNode(new NodeId(2, "IncorrectMinimumSamplingIntervalDataType"));
assertNull(variableNode.getMinimumSamplingInterval());
}
Aggregations