Search in sources :

Example 1 with AttributeFilter

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());
}
Also used : AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) Reference(org.eclipse.milo.opcua.sdk.core.Reference) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) AttributeFilterContext(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilterContext) UaVariableNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) AttributeFilter(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilter) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Aggregations

UaVariableNode (org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode)1 Reference (org.eclipse.milo.opcua.sdk.core.Reference)1 AttributeFilter (org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilter)1 AttributeFilterContext (org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilterContext)1 AbstractClientServerTest (org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)1 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)1 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)1 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)1 Test (org.junit.jupiter.api.Test)1