Skip to content

Commit 8a7eb05

Browse files
authored
DynamicType Tests and Polish (#1368)
1 parent 279c3fb commit 8a7eb05

File tree

51 files changed

+11593
-1081
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+11593
-1081
lines changed

milo-examples/client-examples/src/main/java/org/eclipse/milo/examples/client/UnifiedAutomationReadCustomDataTypeExample1.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 the Eclipse Milo Authors
2+
* Copyright (c) 2025 the Eclipse Milo Authors
33
*
44
* This program and the accompanying materials are made
55
* available under the terms of the Eclipse Public License 2.0
@@ -18,9 +18,10 @@
1818
import java.util.UUID;
1919
import java.util.concurrent.CompletableFuture;
2020
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
21-
import org.eclipse.milo.opcua.sdk.core.types.DynamicEnum;
22-
import org.eclipse.milo.opcua.sdk.core.types.DynamicOptionSet;
23-
import org.eclipse.milo.opcua.sdk.core.types.DynamicStruct;
21+
import org.eclipse.milo.opcua.sdk.core.types.DynamicEnumType;
22+
import org.eclipse.milo.opcua.sdk.core.types.DynamicOptionSetType;
23+
import org.eclipse.milo.opcua.sdk.core.types.DynamicStructType;
24+
import org.eclipse.milo.opcua.sdk.core.types.DynamicType;
2425
import org.eclipse.milo.opcua.stack.core.encoding.EncodingContext;
2526
import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
2627
import org.eclipse.milo.opcua.stack.core.types.builtin.ByteString;
@@ -64,40 +65,40 @@ public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throw
6465
private void readWriteReadPerson(OpcUaClient client) throws Exception {
6566
NodeId nodeId = NodeId.parse("ns=3;s=Person1");
6667

67-
DynamicStruct value = readScalarValue(client, nodeId);
68+
DynamicStructType value = (DynamicStructType) readScalarValue(client, nodeId);
6869
logger.info("Person1: {}", value);
6970

7071
Random r = new Random();
71-
DynamicEnum gender = (DynamicEnum) value.getMembers().get("Gender");
72+
DynamicEnumType gender = (DynamicEnumType) value.getMembers().get("Gender");
7273
value.getMembers().put("Name", "Fat Boy" + r.nextInt(100));
73-
value.getMembers().put("Gender", new DynamicEnum(gender.getDataType(), r.nextInt(2)));
74+
value.getMembers().put("Gender", new DynamicEnumType(gender.getDataType(), r.nextInt(2)));
7475

7576
StatusCode status = writeValue(client, nodeId, value);
7677
System.out.println("write status: " + status);
7778

78-
value = readScalarValue(client, nodeId);
79+
value = (DynamicStructType) readScalarValue(client, nodeId);
7980
logger.info("Person1': {}", value);
8081
}
8182

8283
private void readWriteReadWorkOrder(OpcUaClient client) throws Exception {
8384
NodeId nodeId = NodeId.parse("ns=3;s=Demo.Static.Scalar.WorkOrder");
8485

85-
DynamicStruct value = readScalarValue(client, nodeId);
86+
DynamicStructType value = (DynamicStructType) readScalarValue(client, nodeId);
8687
logger.info("WorkOrder: {}", value);
8788

8889
value.getMembers().put("ID", UUID.randomUUID());
8990

9091
StatusCode status = writeValue(client, nodeId, value);
9192
System.out.println("write status: " + status);
9293

93-
value = readScalarValue(client, nodeId);
94+
value = (DynamicStructType) readScalarValue(client, nodeId);
9495
logger.info("WorkOrder': {}", value);
9596
}
9697

9798
private void readWriteCarExtras(OpcUaClient client) throws Exception {
9899
NodeId nodeId = NodeId.parse("ns=3;s=Demo.Static.Scalar.CarExtras");
99100

100-
DynamicOptionSet value = (DynamicOptionSet) readScalarValue(client, nodeId);
101+
DynamicOptionSetType value = (DynamicOptionSetType) readScalarValue(client, nodeId);
101102
logger.info("CarExtras: {}", value);
102103

103104
byte b = requireNonNull(value.getValue().bytes())[0];
@@ -106,33 +107,32 @@ private void readWriteCarExtras(OpcUaClient client) throws Exception {
106107
StatusCode status = writeValue(client, nodeId, value);
107108
System.out.println("write status: " + status);
108109

109-
value = (DynamicOptionSet) readScalarValue(client, nodeId);
110+
value = (DynamicOptionSetType) readScalarValue(client, nodeId);
110111
logger.info("CarExtras': {}", value);
111112
}
112113

113114
private void readWorkOrderArray(OpcUaClient client) throws Exception {
114115
NodeId nodeId = NodeId.parse("ns=3;s=Demo.Static.Arrays.WorkOrder");
115116

116-
DynamicStruct[] value = readArrayValue(client, nodeId);
117+
DynamicType[] value = readArrayValue(client, nodeId);
117118

118119
logger.info("WorkOrderArray:");
119120
for (int i = 0; i < value.length; i++) {
120121
logger.info(" WorkOrder[{}]: {}", i, value[i]);
121122
}
122123
}
123124

124-
private static DynamicStruct readScalarValue(OpcUaClient client, NodeId nodeId) throws Exception {
125+
private static DynamicType readScalarValue(OpcUaClient client, NodeId nodeId) throws Exception {
125126
DataValue dataValue =
126127
client.readValues(0.0, TimestampsToReturn.Neither, List.of(nodeId)).get(0);
127128

128129
ExtensionObject xo = (ExtensionObject) dataValue.getValue().getValue();
129130
assert xo != null;
130131

131-
return (DynamicStruct) xo.decode(client.getDynamicEncodingContext());
132+
return (DynamicType) xo.decode(client.getDynamicEncodingContext());
132133
}
133134

134-
private static DynamicStruct[] readArrayValue(OpcUaClient client, NodeId nodeId)
135-
throws Exception {
135+
private static DynamicType[] readArrayValue(OpcUaClient client, NodeId nodeId) throws Exception {
136136
DataValue dataValue =
137137
client.readValues(0.0, TimestampsToReturn.Neither, List.of(nodeId)).get(0);
138138

@@ -141,13 +141,12 @@ private static DynamicStruct[] readArrayValue(OpcUaClient client, NodeId nodeId)
141141

142142
EncodingContext ctx = client.getDynamicEncodingContext();
143143

144-
return Arrays.stream(xos)
145-
.map(xo -> (DynamicStruct) xo.decode(ctx))
146-
.toArray(DynamicStruct[]::new);
144+
return Arrays.stream(xos).map(xo -> (DynamicType) xo.decode(ctx)).toArray(DynamicType[]::new);
147145
}
148146

149-
private static StatusCode writeValue(OpcUaClient client, NodeId nodeId, DynamicStruct value)
147+
private static StatusCode writeValue(OpcUaClient client, NodeId nodeId, DynamicType value)
150148
throws Exception {
149+
151150
ExtensionObject xo =
152151
ExtensionObject.encodeDefaultBinary(
153152
client.getDynamicEncodingContext(), value, value.getDataType().getBinaryEncodingId());

opc-ua-sdk/integration-tests/src/test/java/org/eclipse/milo/opcua/sdk/client/DynamicMatrixTestTypeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 the Eclipse Milo Authors
2+
* Copyright (c) 2025 the Eclipse Milo Authors
33
*
44
* This program and the accompanying materials are made
55
* available under the terms of the Eclipse Public License 2.0
@@ -14,7 +14,7 @@
1414
import static org.junit.jupiter.api.Assertions.assertNotNull;
1515

1616
import org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode;
17-
import org.eclipse.milo.opcua.sdk.core.types.DynamicStruct;
17+
import org.eclipse.milo.opcua.sdk.core.types.DynamicStructType;
1818
import org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest;
1919
import org.eclipse.milo.opcua.sdk.test.MatrixTestType;
2020
import org.eclipse.milo.opcua.stack.core.UaException;
@@ -38,7 +38,7 @@ public void read() throws UaException {
3838
ExtensionObject xo = (ExtensionObject) value.getValue().getValue();
3939
assert xo != null;
4040

41-
DynamicStruct decoded = (DynamicStruct) xo.decode(client.getDynamicEncodingContext());
41+
DynamicStructType decoded = (DynamicStructType) xo.decode(client.getDynamicEncodingContext());
4242
assertEquals(
4343
MatrixTestType.TYPE_ID,
4444
decoded.getTypeId().absolute(client.getNamespaceTable()).orElseThrow());

opc-ua-sdk/sdk-client/src/main/java/org/eclipse/milo/opcua/sdk/client/OpcUaClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 the Eclipse Milo Authors
2+
* Copyright (c) 2025 the Eclipse Milo Authors
33
*
44
* This program and the accompanying materials are made
55
* available under the terms of the Eclipse Public License 2.0
@@ -39,7 +39,7 @@
3939
import org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaSubscription;
4040
import org.eclipse.milo.opcua.sdk.client.subscriptions.PublishingManager;
4141
import org.eclipse.milo.opcua.sdk.client.typetree.DataTypeTreeBuilder;
42-
import org.eclipse.milo.opcua.sdk.core.types.DynamicCodecFactory;
42+
import org.eclipse.milo.opcua.sdk.core.types.codec.DynamicCodecFactory;
4343
import org.eclipse.milo.opcua.sdk.core.typetree.DataType;
4444
import org.eclipse.milo.opcua.sdk.core.typetree.DataTypeTree;
4545
import org.eclipse.milo.opcua.stack.core.AttributeId;

opc-ua-sdk/sdk-core/pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
~ Copyright (c) 2024 the Eclipse Milo Authors
3+
~ Copyright (c) 2025 the Eclipse Milo Authors
44
~
55
~ This program and the accompanying materials are made
66
~ available under the terms of the Eclipse Public License 2.0
@@ -51,6 +51,18 @@
5151
<version>${junit.version}</version>
5252
<scope>test</scope>
5353
</dependency>
54+
<dependency>
55+
<groupId>org.junit.jupiter</groupId>
56+
<artifactId>junit-jupiter-params</artifactId>
57+
<version>${junit.version}</version>
58+
<scope>test</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.mockito</groupId>
62+
<artifactId>mockito-core</artifactId>
63+
<version>5.11.0</version>
64+
<scope>test</scope>
65+
</dependency>
5466
</dependencies>
5567

5668
<build>

opc-ua-sdk/sdk-core/src/main/java/org/eclipse/milo/opcua/sdk/core/types/DynamicEnum.java

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)