Search in sources :

Example 1 with NodeFactory

use of org.eclipse.milo.opcua.sdk.server.nodes.factories.NodeFactory 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)

Aggregations

OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)1 UaNodeManager (org.eclipse.milo.opcua.sdk.server.UaNodeManager)1 NodeManager (org.eclipse.milo.opcua.sdk.server.api.NodeManager)1 AnalogItemTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.variables.AnalogItemTypeNode)1 NodeFactory (org.eclipse.milo.opcua.sdk.server.nodes.factories.NodeFactory)1 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)1 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1