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