Search in sources :

Example 46 with QualifiedName

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

the class OpcUaEndpointTest method testSubmodelRefs.

/**
 * Searches for the Submodel reference node and checks the corresponding
 * values
 *
 * @param client The OPC UA Client.
 * @param baseNode The base node where the Node is searched.
 * @param aasns The namespace index of the AAS namespace.
 * @param submodelDocNode The Submodel Documentation Node
 * @param submodelOperDataNode The Submodel OperationalData Node
 * @param submodelTechDataNode The Submodel TechnicalData Node
 * @throws ServiceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws StatusException If the operation fails
 */
private void testSubmodelRefs(UaClient client, NodeId baseNode, int aasns, NodeId submodelDocNode, NodeId submodelOperDataNode, NodeId submodelTechDataNode) throws ServiceException, ServiceResultException, AddressSpaceException, StatusException {
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_REF_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(baseNode, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testSubmodelRefs Browse Result Null", bpres);
    Assert.assertTrue("testSubmodelRefs Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testSubmodelRefs Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testSubmodelRefs Target Null", targets);
    Assert.assertTrue("testSubmodelRefs Target empty", targets.length > 0);
    NodeId refNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertNotNull("testSubmodelRefs RefNode Null", refNode);
    TestUtils.checkType(client, refNode, new NodeId(aasns, TestDefines.AAS_REFERENCE_LIST_ID));
    TestUtils.checkSubmodelRef(client, refNode, aasns, TestDefines.SUBMODEL_DOC_NAME, submodelDocNode);
    TestUtils.checkSubmodelRef(client, refNode, aasns, TestDefines.SUBMODEL_OPER_DATA_NAME, submodelOperDataNode);
    TestUtils.checkSubmodelRef(client, refNode, aasns, TestDefines.SUBMODEL_TECH_DATA_NAME, submodelTechDataNode);
}
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) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Example 47 with QualifiedName

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

the class OpcUaEndpointTest method testWriteBlobValue.

/**
 * Test method for writing a range. 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 testWriteBlobValue() 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("testWriteBlobValue: 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.SUBMODEL_OPER_DATA_NODE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_BLOB_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("testWriteBlobValue Browse Result Null", bpres);
    Assert.assertTrue("testWriteBlobValue Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWriteBlobValue Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteBlobValue ValueType Null", targets);
    Assert.assertTrue("testWriteBlobValue ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    // byte[] oldValue = Base64.getDecoder().decode("AQIDBAU=");
    ByteString oldValue = ByteString.valueOf(Base64.getDecoder().decode("AQIDBAU="));
    ByteString newValue = ByteString.valueOf(Base64.getDecoder().decode("QUJDREU="));
    TestUtils.writeNewValueIntern(client, writeNode, oldValue, newValue);
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) 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 48 with QualifiedName

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

the class OpcUaEndpointTest method testWritePropertyValue.

/**
 * Test method for writing a property. 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 testWritePropertyValue() 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("testWritePropertyValue: 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.SUBMODEL_OPER_DATA_NODE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_PROPERTY_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("testWritePropertyValue Browse Result Null", bpres);
    Assert.assertTrue("testWritePropertyValue Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWritePropertyValue Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWritePropertyValue ValueType Null", targets);
    Assert.assertTrue("testWritePropertyValue ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    TestUtils.writeNewValueIntern(client, writeNode, 50, 222);
    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 49 with QualifiedName

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

the class OpcUaEndpointTest method testWriteRangeValue.

/**
 * Test method for writing a range. 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 testWriteRangeValue() 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("testWriteRangeValue: 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.SUBMODEL_OPER_DATA_NODE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_RANGE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.RANGE_MAX_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testWriteRangeValue Browse Result Null", bpres);
    Assert.assertTrue("testWriteRangeValue Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWriteRangeValue Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteRangeValue ValueType Null", targets);
    Assert.assertTrue("testWriteRangeValue ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    TestUtils.writeNewValueIntern(client, writeNode, 100, 111);
    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 50 with QualifiedName

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

the class OpcUaEndpointTest method testAddSubmodel.

/**
 * Test method for adding a complete submodel to an AAS.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testAddSubmodel() throws SecureIdentityException, IOException, ServiceException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testAddProperty: client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    String submodelName = "NewSubmodelTest1";
    // make sure the element doesn't exist yet
    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, submodelName)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_REL_ELEMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, AASRelationshipElementType.SECOND)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.KEYS_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testAddSubmodel Browse Result Null", bpres);
    Assert.assertTrue("testAddSubmodel Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testAddSubmodel Browse Result Bad", bpres[0].getStatusCode().isBad());
    // Send event to MessageBus
    ElementCreateEventMessage msg = new ElementCreateEventMessage();
    msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.ASSET_ADMINISTRATION_SHELL).value("http://customer.com/aas/9175_7013_7091_9168").build()).build());
    msg.setValue(new DefaultSubmodel.Builder().idShort(submodelName).identification(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("https://acplt.org/NewSubmodelTest1").build()).administration(new DefaultAdministrativeInformation.Builder().version("0.9").revision("0").build()).kind(ModelingKind.INSTANCE).submodelElement(new DefaultRelationshipElement.Builder().idShort("ExampleRelationshipElement").category("Parameter").description(new LangString("Example RelationshipElement object", "en-us")).description(new LangString("Beispiel RelationshipElement Element", "de")).semanticId(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.GLOBAL_REFERENCE).value("http://acplt.org/RelationshipElements/ExampleRelationshipElement").idType(KeyType.IRI).build()).build()).first(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.SUBMODEL).value("https://acplt.org/Test_Submodel").idType(KeyType.IRI).build()).key(new DefaultKey.Builder().type(KeyElements.SUBMODEL_ELEMENT_COLLECTION).value("ExampleSubmodelCollectionOrdered").idType(KeyType.ID_SHORT).build()).key(new DefaultKey.Builder().type(KeyElements.PROPERTY).value("ExampleProperty").idType(KeyType.ID_SHORT).build()).build()).second(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.SUBMODEL).value("http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial").idType(KeyType.IRI).build()).key(new DefaultKey.Builder().type(KeyElements.ENTITY).value("ExampleEntity").idType(KeyType.ID_SHORT).build()).key(new DefaultKey.Builder().type(KeyElements.PROPERTY).value("ExampleProperty2").idType(KeyType.ID_SHORT).build()).build()).build()).build());
    service.getMessageBus().publish(msg);
    Thread.sleep(DEFAULT_TIMEOUT);
    // check that the element is there now
    bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testAddSubmodel Browse Result Null", bpres);
    Assert.assertTrue("testAddSubmodel Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testAddSubmodel Browse Result Good", bpres[0].getStatusCode().isGood());
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) LangString(io.adminshell.aas.v3.model.LangString) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) DefaultRelationshipElement(io.adminshell.aas.v3.model.impl.DefaultRelationshipElement) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) UaClient(com.prosysopc.ua.client.UaClient) DefaultSubmodel(io.adminshell.aas.v3.model.impl.DefaultSubmodel) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) Test(org.junit.Test)

Aggregations

QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)74 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)60 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)46 ArrayList (java.util.ArrayList)46 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)45 RelativePath (com.prosysopc.ua.stack.core.RelativePath)45 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)40 StatusException (com.prosysopc.ua.StatusException)29 ServiceException (com.prosysopc.ua.ServiceException)28 AddressSpaceException (com.prosysopc.ua.client.AddressSpaceException)28 ServiceResultException (com.prosysopc.ua.stack.common.ServiceResultException)28 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)27 UaNodeFactoryException (com.prosysopc.ua.nodes.UaNodeFactoryException)27 MessageBusException (de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException)27 LangString (io.adminshell.aas.v3.model.LangString)27 UaClient (com.prosysopc.ua.client.UaClient)26 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)26 Test (org.junit.Test)26 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)24 Reference (io.adminshell.aas.v3.model.Reference)19