Search in sources :

Example 26 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointFullTest method testOpcUaEndpointFull.

/**
 * Test method for testing the OPC UA Endpoint
 *
 * @throws InterruptedException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testOpcUaEndpointFull() throws InterruptedException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    Assert.assertTrue("client not connected", client.isConnected());
    System.out.println("client connected");
    DataValue value = client.readValue(Identifiers.Server_ServerStatus_State);
    System.out.println(value);
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals(ServerState.Running.ordinal(), value.getValue().intValue());
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    // browse for AAS Environment
    List<ReferenceDescription> refs = client.getAddressSpace().browse(Identifiers.ObjectsFolder);
    Assert.assertNotNull("Browse ObjectsFolder Refs Null", refs);
    Assert.assertFalse("Browse ObjectsFolder Refs empty", refs.isEmpty());
    NodeId envNode = null;
    for (ReferenceDescription ref : refs) {
        if (ref.getBrowseName().getName().equals(TestDefines.AAS_ENVIRONMENT_NAME)) {
            envNode = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
            break;
        }
    }
    Assert.assertNotNull("AASEnvironment Null", envNode);
    // browse AAS Environment
    refs = client.getAddressSpace().browse(envNode);
    Assert.assertNotNull("Browse Environment Refs Null", refs);
    Assert.assertTrue("Browse Environment Refs empty", !refs.isEmpty());
    NodeId submodel1Node = null;
    for (ReferenceDescription ref : refs) {
        NodeId rid = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
        switch(ref.getBrowseName().getName()) {
            case TestDefines.FULL_SUBMODEL_1_NAME:
                submodel1Node = rid;
                break;
        }
    }
    Assert.assertNotNull("Submodel 1 Node not found", submodel1Node);
    testSubmodel1(client, submodel1Node);
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) ReferenceDescription(com.prosysopc.ua.stack.core.ReferenceDescription) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) UaClient(com.prosysopc.ua.client.UaClient) Test(org.junit.Test)

Example 27 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointFullTest method testOrderedSubmodelElementCollection.

/**
 * Test method for an OrderedSubmodelElementCollection.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws AddressSpaceException If the operation fails
 */
@Test
public void testOrderedSubmodelElementCollection() throws SecureIdentityException, IOException, ServiceException, ServiceResultException, AddressSpaceException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SUBMODEL_6_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SM_ELEM_COLL_O_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testOrderedSubmodelElementCollection Browse Result Null", bpres);
    Assert.assertTrue("testOrderedSubmodelElementCollection Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testOrderedSubmodelElementCollection Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testOrderedSubmodelElementCollection ValueType Null", targets);
    Assert.assertTrue("testOrderedSubmodelElementCollection ValueType empty", targets.length > 0);
    NodeId smNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertNotNull("testOrderedSubmodelElementCollection Node Null", smNode);
    TestUtils.checkType(client, smNode, new NodeId(aasns, TestDefines.AAS_OREDER_SM_ELEM_COLL_TYPE_ID));
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) UaClient(com.prosysopc.ua.client.UaClient) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 28 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointFullTest method testWriteSubmodelElementCollectionValue2.

/**
 * Test method for writing a Value of a SubmodelElementCollection. Writes the property in the OPC UA
 * Server and checks the new value in the server.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws InterruptedException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
@Test
public void testWriteSubmodelElementCollectionValue2() throws SecureIdentityException, IOException, ServiceException, StatusException, InterruptedException, ServiceResultException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SUBMODEL_6_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SM_ELEM_COLL_O_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SMEC_RANGE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.RANGE_MIN_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testWriteSubmodelElementCollectionValue2 Browse Result Null", bpres);
    Assert.assertTrue("testWriteSubmodelElementCollectionValue2 Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWriteSubmodelElementCollectionValue2 Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteSubmodelElementCollectionValue2 ValueType Null", targets);
    Assert.assertTrue("testWriteSubmodelElementCollectionValue2 ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    TestUtils.writeNewValueIntern(client, writeNode, 0, 4);
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) UaClient(com.prosysopc.ua.client.UaClient) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 29 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointFullTest method testWriteSubmodelElementCollectionValue3.

/**
 * Test method for writing a Value of a SubmodelElementCollection. Writes the property in the OPC UA
 * Server and checks the new value in the server.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws InterruptedException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
@Test
public void testWriteSubmodelElementCollectionValue3() throws SecureIdentityException, IOException, ServiceException, StatusException, InterruptedException, ServiceResultException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SUBMODEL_7_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SM_ELEM_COLL_O_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_MULTI_LAN_PROP_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testWriteMultiLanguagePropertyValue Browse Result Null", bpres);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteMultiLanguagePropertyValue ValueType Null", targets);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    // The DataElementValueMapper changes the order of the elements in some cases
    List<LocalizedText> newValue = new ArrayList<>();
    newValue.add(new LocalizedText("english test element", "en-us"));
    newValue.add(new LocalizedText("deutsches Test-Element", "de"));
    TestUtils.writeNewValueArray(client, writeNode, new ArrayList<>().toArray(LocalizedText[]::new), newValue.toArray(LocalizedText[]::new));
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) UaClient(com.prosysopc.ua.client.UaClient) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 30 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointFullTest method testSubmodel1.

/**
 * Tests the submodel 1 (Identification).
 *
 * @param client The OPC UA Client.
 * @param submodelNode The desired Submodel
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
private void testSubmodel1(UaClient client, NodeId submodelNode) throws ServiceException, AddressSpaceException, ServiceResultException, StatusException {
    TestUtils.checkDisplayName(client, submodelNode, "Submodel:" + TestDefines.FULL_SUBMODEL_1_NAME);
    TestUtils.checkType(client, submodelNode, new NodeId(aasns, TestDefines.AAS_SUBMODEL_TYPE_ID));
    TestUtils.checkIdentificationNode(client, submodelNode, aasns, AASIdentifierTypeDataType.IRI, TestDefines.FULL_SUBMODEL_1_ID);
    TestUtils.checkAdministrationNode(client, submodelNode, aasns, "0.9", "0");
    TestUtils.checkModelingKindNode(client, submodelNode, aasns, AASModelingKindDataType.Instance);
    TestUtils.checkCategoryNode(client, submodelNode, aasns, "");
    TestUtils.checkDataSpecificationNode(client, submodelNode, aasns);
    TestUtils.checkQualifierNode(client, submodelNode, aasns, new ArrayList<>());
    ArrayList<Qualifier> list = new ArrayList<>();
    list.add(new DefaultQualifier.Builder().value("100").valueType("int").type("http://acplt.org/Qualifier/ExampleQualifier").build());
    list.add(new DefaultQualifier.Builder().value("50").valueType("int").type("http://acplt.org/Qualifier/ExampleQualifier2").build());
    TestUtils.checkAasPropertyString(client, submodelNode, aasns, "ManufacturerName", AASModelingKindDataType.Instance, "", AASValueTypeDataType.String, "http://acplt.org/ValueId/ACPLT", list);
}
Also used : NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ArrayList(java.util.ArrayList) Qualifier(io.adminshell.aas.v3.model.Qualifier) DefaultQualifier(io.adminshell.aas.v3.model.impl.DefaultQualifier) DefaultQualifier(io.adminshell.aas.v3.model.impl.DefaultQualifier)

Aggregations

NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)79 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)59 ArrayList (java.util.ArrayList)33 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)32 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)32 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)31 RelativePath (com.prosysopc.ua.stack.core.RelativePath)31 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)29 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)27 LangString (io.adminshell.aas.v3.model.LangString)27 UaClient (com.prosysopc.ua.client.UaClient)19 Test (org.junit.Test)19 Reference (io.adminshell.aas.v3.model.Reference)17 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)17 ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)16 ExpandedNodeId (com.prosysopc.ua.stack.builtintypes.ExpandedNodeId)15 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)12 DataValue (com.prosysopc.ua.stack.builtintypes.DataValue)10 PlainProperty (com.prosysopc.ua.server.nodes.PlainProperty)9 SubmodelElementData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)8