use of org.eclipse.milo.opcua.stack.core.NamespaceTable in project milo by eclipse.
the class BinaryDecoderTest method testDecodeNullArray.
@Test(description = "a null array, once encoded, should decode to a null array")
public void testDecodeNullArray() {
Argument argument = new Argument("test", Identifiers.Int16, 1, null, LocalizedText.NULL_VALUE);
@SuppressWarnings("unchecked") OpcUaBinaryDataTypeCodec<Argument> codec = (OpcUaBinaryDataTypeCodec<Argument>) OpcUaDataTypeManager.getInstance().getCodec(OpcUaDefaultBinaryEncoding.ENCODING_NAME, Argument.TYPE_ID.toNodeId(new NamespaceTable()).get());
assertNotNull(codec);
codec.encode(new TestSerializationContext(), writer, argument);
Argument decoded = codec.decode(new TestSerializationContext(), reader);
assertEquals(decoded.getName(), argument.getName());
assertNull(decoded.getArrayDimensions());
}
use of org.eclipse.milo.opcua.stack.core.NamespaceTable in project milo by eclipse.
the class NodeIdTest method testExpandedWithNamespaceTable.
@Test
public void testExpandedWithNamespaceTable() {
NamespaceTable namespaceTable = new NamespaceTable();
namespaceTable.addUri("urn:test");
NodeId nodeId = new NodeId(1, "foo");
ExpandedNodeId xni = nodeId.expanded(namespaceTable);
assertEquals(xni.getNamespaceUri(), "urn:test");
}
use of org.eclipse.milo.opcua.stack.core.NamespaceTable in project milo by eclipse.
the class DataTypeTreeBuilder method addChildren.
private static CompletableFuture<Unit> addChildren(Tree<DataTypeTree.DataType> tree, UaStackClient client, OpcUaSession session, NamespaceTable namespaceTable) {
CompletableFuture<List<ReferenceDescription>> subtypes = browseSafe(client, session, new BrowseDescription(tree.getValue().getNodeId(), BrowseDirection.Forward, Identifiers.HasSubtype, false, uint(NodeClass.DataType.getValue()), uint(BrowseResultMask.All.getValue())));
CompletableFuture<List<DataTypeTree.DataType>> dataTypesFuture = subtypes.thenCompose(references -> {
Stream<CompletableFuture<DataTypeTree.DataType>> dataTypeFutures = references.stream().map(dataTypeReference -> {
NodeId dataTypeId = dataTypeReference.getNodeId().toNodeId(namespaceTable).orElse(NodeId.NULL_VALUE);
CompletableFuture<List<ReferenceDescription>> encodings = browseSafe(client, session, new BrowseDescription(dataTypeId, BrowseDirection.Forward, Identifiers.HasEncoding, false, uint(NodeClass.Object.getValue()), uint(BrowseResultMask.All.getValue())));
return encodings.thenApply(encodingReferences -> {
NodeId binaryEncodingId = null;
NodeId xmlEncodingId = null;
for (ReferenceDescription r : encodingReferences) {
if (r.getBrowseName().equals(OpcUaDefaultBinaryEncoding.ENCODING_NAME)) {
binaryEncodingId = r.getNodeId().toNodeId(namespaceTable).orElse(null);
} else if (r.getBrowseName().equals(OpcUaDefaultXmlEncoding.ENCODING_NAME)) {
xmlEncodingId = r.getNodeId().toNodeId(namespaceTable).orElse(null);
}
}
return new DataTypeTree.DataType(dataTypeReference.getBrowseName(), dataTypeId, binaryEncodingId, xmlEncodingId);
});
});
return FutureUtils.sequence(dataTypeFutures);
});
return dataTypesFuture.thenCompose(dataTypes -> {
Stream<CompletableFuture<Unit>> futures = dataTypes.stream().map(tree::addChild).map(childNode -> addChildren(childNode, client, session, namespaceTable));
return FutureUtils.sequence(futures);
}).thenApply(v -> Unit.VALUE);
}
use of org.eclipse.milo.opcua.stack.core.NamespaceTable in project milo by eclipse.
the class OpcUaClient method readNamespaceTableAsync.
/**
* Read the server's NamespaceTable and update the local copy.
* <p>
* This call completes asynchronously.
*
* @return a {@link CompletableFuture} that completes successfully with the updated
* {@link NamespaceTable} or completes exceptionally if a service- or operation-level error
* occurs.
*/
public CompletableFuture<NamespaceTable> readNamespaceTableAsync() {
return getSession().thenCompose(session -> {
RequestHeader requestHeader = newRequestHeader(session.getAuthenticationToken());
ReadRequest readRequest = new ReadRequest(requestHeader, 0.0, TimestampsToReturn.Neither, new ReadValueId[] { new ReadValueId(Identifiers.Server_NamespaceArray, AttributeId.Value.uid(), null, QualifiedName.NULL_VALUE) });
CompletableFuture<String[]> namespaceArray = sendRequest(readRequest).thenApply(ReadResponse.class::cast).thenApply(response -> Objects.requireNonNull(response.getResults())).thenApply(results -> (String[]) results[0].getValue().getValue());
return namespaceArray.thenAccept(this::updateNamespaceTable).thenApply(v -> getNamespaceTable());
});
}
use of org.eclipse.milo.opcua.stack.core.NamespaceTable 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);
}
Aggregations