Для небольшого проекта я настроил клиента OPC UA с помощью Eclipse Milo. Я хочу проверить его с помощью некоторых модульных тестов. Я выяснил, как настроить сервер тестирования, но у меня возникли проблемы с настройкой некоторых узлов для чтения значений.import org.eclipse.milo.opcua.sdk.core.AccessLevel;
import org.eclipse.milo.opcua.sdk.server.OpcUaServer;
import org.eclipse.milo.opcua.sdk.server.api.*;
import org.eclipse.milo.opcua.sdk.server.api.config.OpcUaServerConfig;
import org.eclipse.milo.opcua.sdk.server.api.services.NodeManagementServices;
import org.eclipse.milo.opcua.sdk.server.nodes.UaNode;
import org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext;
import org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode;
import org.eclipse.milo.opcua.stack.core.Identifiers;
import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
import org.eclipse.milo.opcua.stack.core.types.builtin.*;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort;
import org.eclipse.milo.opcua.stack.core.types.enumerated.MessageSecurityMode;
import org.eclipse.milo.opcua.stack.core.types.structured.AddNodesItem;
import org.eclipse.milo.opcua.stack.server.EndpointConfiguration;
import org.junit.jupiter.api.*;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static org.eclipse.milo.opcua.sdk.core.WriteMask.UserAccessLevel;
import static org.junit.jupiter.api.Assertions.*;
class OPCUACommunicatorTest {
private static OpcUaServer server;
private static UShort namespaceId;
private static final String TEST_ENDPOINT = "opc.tcp://localhost:4840";
private static final String TEST_NAMESPACE = "urn:test:namespace";
@BeforeAll
static void setupServer() throws Exception {
server = new OpcUaServer(OpcUaServerConfig.builder()
.setApplicationUri("urn:test:server")
.setEndpoints(Set.of(
EndpointConfiguration.newBuilder()
.setBindPort(4840)
.setSecurityPolicy(SecurityPolicy.None)
.setSecurityMode(MessageSecurityMode.None)
.setHostname("localhost")
.setPath("/test")
.build()
))
.build()
);
server.startup().get(); // Server starten
namespaceId = server.getNamespaceTable().addUri(TEST_NAMESPACE); // Namespace hinzufügen
}
@AfterAll
static void shutdownServer() throws Exception {
server.shutdown().get();
}
@Test
void testOpcUaConnection() throws ExecutionException, InterruptedException {
OPCUACommunicator communicator = new OPCUACommunicator(TEST_ENDPOINT);
assertDoesNotThrow(() -> communicator.setConnectorString(TEST_ENDPOINT));
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... lipse-milo