use of org.eclipse.milo.opcua.sdk.server.OpcUaServer 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());
}
use of org.eclipse.milo.opcua.sdk.server.OpcUaServer 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.OpcUaServer 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.OpcUaServer in project milo by eclipse.
the class DefaultNodeManagementServiceSet method onDeleteReferences.
@Override
public void onDeleteReferences(ServiceRequest service) {
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
DeleteReferencesRequest request = (DeleteReferencesRequest) service.getRequest();
List<DeleteReferencesItem> referencesToDelete = l(request.getReferencesToDelete());
if (referencesToDelete.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (referencesToDelete.size() > server.getConfig().getLimits().getMaxNodesPerNodeManagement().longValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
DeleteReferencesContext context = new DeleteReferencesContext(server, session, new DiagnosticsContext<>());
server.getAddressSpaceManager().deleteReferences(context, referencesToDelete);
context.getFuture().thenAccept(results -> {
ResponseHeader header = service.createResponseHeader();
DeleteReferencesResponse response = new DeleteReferencesResponse(header, a(results, StatusCode.class), new DiagnosticInfo[0]);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.sdk.server.OpcUaServer in project milo by eclipse.
the class DefaultNodeManagementServiceSet method onAddReferences.
@Override
public void onAddReferences(ServiceRequest service) {
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
AddReferencesRequest request = (AddReferencesRequest) service.getRequest();
List<AddReferencesItem> referencesToAdd = l(request.getReferencesToAdd());
if (referencesToAdd.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (referencesToAdd.size() > server.getConfig().getLimits().getMaxNodesPerNodeManagement().longValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
AddReferencesContext context = new AddReferencesContext(server, session, new DiagnosticsContext<>());
server.getAddressSpaceManager().addReferences(context, referencesToAdd);
context.getFuture().thenAccept(results -> {
ResponseHeader header = service.createResponseHeader();
AddReferencesResponse response = new AddReferencesResponse(header, a(results, StatusCode.class), new DiagnosticInfo[0]);
service.setResponse(response);
});
}
Aggregations