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);
}
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);
}
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);
}
}
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);
}
Aggregations