Search in sources :

Example 1 with UaNodeManager

use of org.eclipse.milo.opcua.sdk.server.UaNodeManager in project milo by eclipse.

the class UaNodeTest method testCreateDeleteComplexInstance.

@Test
public void testCreateDeleteComplexInstance() throws UaException {
    NodeId nodeId = new NodeId(1, "TestAnalog");
    UaNodeManager nodeManager = new UaNodeManager();
    server.getAddressSpaceManager().register(nodeManager);
    assertFalse(nodeManager.containsNode(nodeId));
    assertEquals(0, nodeManager.getReferences(nodeId).size());
    NodeFactory nodeFactory = new NodeFactory(new UaNodeContext() {

        @Override
        public OpcUaServer getServer() {
            return server;
        }

        @Override
        public NodeManager<UaNode> getNodeManager() {
            return nodeManager;
        }
    });
    AnalogItemTypeNode analogItem = (AnalogItemTypeNode) nodeFactory.createNode(nodeId, Identifiers.AnalogItemType, new NodeFactory.InstantiationCallback() {

        @Override
        public boolean includeOptionalNode(NodeId typeDefinitionId, QualifiedName browseName) {
            return true;
        }
    });
    assertTrue(nodeManager.containsNode(nodeId));
    assertTrue(nodeManager.getReferences(nodeId).size() > 0);
    analogItem.delete();
    assertFalse(nodeManager.containsNode(nodeId));
    assertEquals(0, nodeManager.getReferences(nodeId).size());
}
Also used : NodeManager(org.eclipse.milo.opcua.sdk.server.api.NodeManager) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) AnalogItemTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.AnalogItemTypeNode) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) NodeFactory(org.eclipse.milo.opcua.sdk.server.nodes.factories.NodeFactory) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with UaNodeManager

use of org.eclipse.milo.opcua.sdk.server.UaNodeManager in project milo by eclipse.

the class InstanceDeclarationHierarchyTest method test.

@Test
public void test() throws Exception {
    NamespaceTable namespaceTable = new NamespaceTable();
    UaNodeManager nodeManager = new UaNodeManager();
    AddressSpaceManager addressSpaceManager = Mockito.mock(AddressSpaceManager.class);
    Mockito.when(addressSpaceManager.getManagedNode(Mockito.any(NodeId.class))).then((Answer<Optional<UaNode>>) invocationOnMock -> nodeManager.getNode(invocationOnMock.getArgument(0)));
    Mockito.when(addressSpaceManager.getManagedNode(Mockito.any(ExpandedNodeId.class))).then((Answer<Optional<UaNode>>) invocationOnMock -> nodeManager.getNode(invocationOnMock.getArgument(0), namespaceTable));
    Mockito.when(addressSpaceManager.getManagedReferences(Mockito.any(NodeId.class))).then((Answer<List<Reference>>) invocationOnMock -> nodeManager.getReferences(invocationOnMock.getArgument(0)));
    OpcUaServer server = Mockito.mock(OpcUaServer.class);
    Mockito.when(server.getAddressSpaceManager()).thenReturn(addressSpaceManager);
    Mockito.when(server.getNamespaceTable()).thenReturn(namespaceTable);
    UaNodeContext context = new UaNodeContext() {

        @Override
        public OpcUaServer getServer() {
            return server;
        }

        @Override
        public NodeManager<UaNode> getNodeManager() {
            return nodeManager;
        }
    };
    new NodeLoader(context, nodeManager).loadNodes();
    InstanceDeclarationHierarchy idh = InstanceDeclarationHierarchy.create(addressSpaceManager, namespaceTable, Identifiers.AnalogItemType);
    System.out.println(idh);
    assertNotNull(idh);
}
Also used : NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) NodeManager(org.eclipse.milo.opcua.sdk.server.api.NodeManager) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) Test(org.testng.annotations.Test) Assert.assertNotNull(org.testng.Assert.assertNotNull) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) List(java.util.List) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) Optional(java.util.Optional) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) Reference(org.eclipse.milo.opcua.sdk.core.Reference) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) Optional(java.util.Optional) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) List(java.util.List) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) Test(org.testng.annotations.Test)

Example 3 with UaNodeManager

use of org.eclipse.milo.opcua.sdk.server.UaNodeManager in project milo by eclipse.

the class UaNodeTest method setup.

@BeforeTest
public void setup() throws Exception {
    server = Mockito.mock(OpcUaServer.class);
    AddressSpaceManager addressSpaceManager = new AddressSpaceManager(server);
    NamespaceTable namespaceTable = new NamespaceTable();
    ObjectTypeManager objectTypeManager = new ObjectTypeManager();
    VariableTypeManager variableTypeManager = new VariableTypeManager();
    Mockito.when(server.getNamespaceTable()).thenReturn(namespaceTable);
    Mockito.when(server.getAddressSpaceManager()).thenReturn(addressSpaceManager);
    Mockito.when(server.getObjectTypeManager()).thenReturn(objectTypeManager);
    Mockito.when(server.getVariableTypeManager()).thenReturn(variableTypeManager);
    UaNodeManager nodeManager = new UaNodeManager();
    addressSpaceManager.register(nodeManager);
    UaNodeContext nodeContext = new UaNodeContext() {

        @Override
        public OpcUaServer getServer() {
            return server;
        }

        @Override
        public NodeManager<UaNode> getNodeManager() {
            return nodeManager;
        }
    };
    new NodeLoader(nodeContext, nodeManager).loadNodes();
    ObjectTypeInitializer.initialize(server.getNamespaceTable(), objectTypeManager);
    VariableTypeInitializer.initialize(server.getNamespaceTable(), variableTypeManager);
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) ObjectTypeManager(org.eclipse.milo.opcua.sdk.server.ObjectTypeManager) VariableTypeManager(org.eclipse.milo.opcua.sdk.server.VariableTypeManager) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) BeforeTest(org.testng.annotations.BeforeTest)

Example 4 with UaNodeManager

use of org.eclipse.milo.opcua.sdk.server.UaNodeManager in project milo by eclipse.

the class UaNodeTest method testCreateDelete.

@Test
public void testCreateDelete() {
    NodeId nodeId = new NodeId(1, "TestObject");
    UaNodeManager nodeManager = new UaNodeManager();
    server.getAddressSpaceManager().register(nodeManager);
    UaNodeContext nodeContext = new UaNodeContext() {

        @Override
        public OpcUaServer getServer() {
            return server;
        }

        @Override
        public NodeManager<UaNode> getNodeManager() {
            return nodeManager;
        }
    };
    assertFalse(nodeManager.containsNode(nodeId));
    assertEquals(0, nodeManager.getReferences(nodeId).size());
    UaObjectNode objectNode = UaObjectNode.builder(nodeContext).setNodeId(nodeId).setBrowseName(new QualifiedName(1, "TestObject")).setDisplayName(LocalizedText.english("TestObject")).setTypeDefinition(Identifiers.FolderType).build();
    nodeManager.addNode(objectNode);
    objectNode.addReference(new Reference(nodeId, Identifiers.HasComponent, Identifiers.ObjectNode.expanded(), Reference.Direction.INVERSE));
    assertTrue(nodeManager.containsNode(nodeId));
    assertTrue(nodeManager.getReferences(nodeId).size() > 0);
    assertTrue(nodeManager.getReferences(Identifiers.ObjectNode).size() > 0);
    objectNode.delete();
    assertFalse(nodeManager.containsNode(nodeId));
    assertEquals(0, nodeManager.getReferences(nodeId).size());
    assertEquals(0, nodeManager.getReferences(Identifiers.ObjectNode).size());
}
Also used : UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) Reference(org.eclipse.milo.opcua.sdk.core.Reference) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 5 with UaNodeManager

use of org.eclipse.milo.opcua.sdk.server.UaNodeManager in project milo by eclipse.

the class AttributeDelegateChainTest method testCreate.

@Test
public void testCreate() throws Exception {
    List<String> list = new ArrayList<>();
    AttributeDelegate delegate = AttributeDelegateChain.create(new AttributeDelegate() {

        @Override
        public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
            list.add("root");
            return node.getValue();
        }
    }, parent -> new DelegatingAttributeDelegate(parent) {

        @Override
        public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
            list.add("child1");
            return super.getValue(context, node);
        }
    }, parent -> new DelegatingAttributeDelegate(parent) {

        @Override
        public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
            list.add("child2");
            return super.getValue(context, node);
        }
    }, parent -> new DelegatingAttributeDelegate(parent) {

        @Override
        public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
            list.add("child3");
            return super.getValue(context, node);
        }
    });
    UaNodeManager nodeManager = new UaNodeManager();
    UaNodeContext context = new UaNodeContext() {

        @Override
        public OpcUaServer getServer() {
            return null;
        }

        @Override
        public NodeManager<UaNode> getNodeManager() {
            return nodeManager;
        }

        @Override
        public NamespaceTable getNamespaceTable() {
            return new NamespaceTable();
        }
    };
    UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(context).setNodeId(NodeId.NULL_VALUE).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(QualifiedName.NULL_VALUE).setDisplayName(LocalizedText.NULL_VALUE).setDataType(Identifiers.String).setTypeDefinition(Identifiers.BaseDataVariableType).build();
    node.setValue(new DataValue(new Variant("foo")));
    DataValue value = delegate.getValue(new AttributeContext(null, null), node);
    assertEquals(value.getValue().getValue(), "foo");
    assertEquals(list.get(0), "child3");
    assertEquals(list.get(1), "child2");
    assertEquals(list.get(2), "child1");
    assertEquals(list.get(3), "root");
}
Also used : AttributeContext(org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaException(org.eclipse.milo.opcua.stack.core.UaException) ArrayList(java.util.ArrayList) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) VariableNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableNode) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) Test(org.testng.annotations.Test)

Aggregations

UaNodeManager (org.eclipse.milo.opcua.sdk.server.UaNodeManager)6 Test (org.testng.annotations.Test)5 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)4 NamespaceTable (org.eclipse.milo.opcua.stack.core.NamespaceTable)4 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)4 BeforeTest (org.testng.annotations.BeforeTest)4 Reference (org.eclipse.milo.opcua.sdk.core.Reference)3 AddressSpaceManager (org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager)3 NodeManager (org.eclipse.milo.opcua.sdk.server.api.NodeManager)3 NodeLoader (org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader)3 UaNode (org.eclipse.milo.opcua.sdk.server.nodes.UaNode)3 UaNodeContext (org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext)3 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)3 List (java.util.List)2 Optional (java.util.Optional)2 ObjectTypeManager (org.eclipse.milo.opcua.sdk.server.ObjectTypeManager)2 VariableTypeManager (org.eclipse.milo.opcua.sdk.server.VariableTypeManager)2 AnalogItemTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.variables.AnalogItemTypeNode)2 UaVariableNode (org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode)2 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)2