Search in sources :

Example 1 with NodeLoader

use of org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader 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 2 with NodeLoader

use of org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader 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 3 with NodeLoader

use of org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader in project milo by eclipse.

the class OpcUaNamespace method loadNodes.

private void loadNodes() {
    try {
        long startTime = System.nanoTime();
        long startCount = getNodeManager().getNodes().size();
        new NodeLoader(getNodeContext(), getNodeManager()).loadNodes();
        long deltaMs = TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
        long deltaCount = getNodeManager().getNodes().size() - startCount;
        logger.info("Loaded {} nodes in {}ms.", deltaCount, deltaMs);
    } catch (Exception e) {
        logger.error("Error loading nodes.", e);
    }
}
Also used : NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) UaException(org.eclipse.milo.opcua.stack.core.UaException)

Example 4 with NodeLoader

use of org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader in project milo by eclipse.

the class NodeFactoryTest method setup.

@BeforeTest
public void setup() throws Exception {
    server = Mockito.mock(OpcUaServer.class);
    NamespaceTable namespaceTable = new NamespaceTable();
    Mockito.when(server.getNamespaceTable()).thenReturn(namespaceTable);
    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)));
    Mockito.when(server.getAddressSpaceManager()).thenReturn(addressSpaceManager);
    UaNodeContext context = new UaNodeContext() {

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

        @Override
        public NodeManager<UaNode> getNodeManager() {
            return nodeManager;
        }
    };
    new NodeLoader(context, nodeManager).loadNodes();
    ObjectTypeManager objectTypeManager = new ObjectTypeManager();
    ObjectTypeInitializer.initialize(server.getNamespaceTable(), objectTypeManager);
    VariableTypeManager variableTypeManager = new VariableTypeManager();
    VariableTypeInitializer.initialize(server.getNamespaceTable(), variableTypeManager);
    nodeFactory = new NodeFactory(context, objectTypeManager, variableTypeManager);
}
Also used : NodeManager(org.eclipse.milo.opcua.sdk.server.api.NodeManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.testng.annotations.Test) ObjectTypeInitializer(org.eclipse.milo.opcua.sdk.server.model.ObjectTypeInitializer) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) Answer(org.mockito.stubbing.Answer) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) BeforeTest(org.testng.annotations.BeforeTest) VariableTypeManager(org.eclipse.milo.opcua.sdk.server.VariableTypeManager) UaMethodNode(org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode) Reference(org.eclipse.milo.opcua.sdk.core.Reference) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ObjectTypeManager(org.eclipse.milo.opcua.sdk.server.ObjectTypeManager) VariableTypeInitializer(org.eclipse.milo.opcua.sdk.server.model.VariableTypeInitializer) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode) Assert.assertNotNull(org.testng.Assert.assertNotNull) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) Nullable(org.jetbrains.annotations.Nullable) Mockito(org.mockito.Mockito) 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) Assert.assertTrue(org.testng.Assert.assertTrue) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) AnalogItemTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.AnalogItemTypeNode) 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) ObjectTypeManager(org.eclipse.milo.opcua.sdk.server.ObjectTypeManager) 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) VariableTypeManager(org.eclipse.milo.opcua.sdk.server.VariableTypeManager) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

NodeLoader (org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader)4 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)3 UaNodeManager (org.eclipse.milo.opcua.sdk.server.UaNodeManager)3 AddressSpaceManager (org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager)3 NamespaceTable (org.eclipse.milo.opcua.stack.core.NamespaceTable)3 List (java.util.List)2 Optional (java.util.Optional)2 Reference (org.eclipse.milo.opcua.sdk.core.Reference)2 ObjectTypeManager (org.eclipse.milo.opcua.sdk.server.ObjectTypeManager)2 VariableTypeManager (org.eclipse.milo.opcua.sdk.server.VariableTypeManager)2 NodeManager (org.eclipse.milo.opcua.sdk.server.api.NodeManager)2 UaNode (org.eclipse.milo.opcua.sdk.server.nodes.UaNode)2 UaNodeContext (org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext)2 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)2 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)2 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)2 Mockito (org.mockito.Mockito)2 Answer (org.mockito.stubbing.Answer)2 Assert.assertNotNull (org.testng.Assert.assertNotNull)2 BeforeTest (org.testng.annotations.BeforeTest)2