Search in sources :

Example 16 with DataValue

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

the class TestUtils method checkAasPropertyFile.

/**
 * Checks the File Property with the given Name.
 *
 * @param client The OPC UA Client
 * @param node The Node where the desired property is located
 * @param aasns The namespace index of the AAS namespace
 * @param name The name of the desired property
 * @param kind The expected ModelingKind
 * @param category The expected Category
 * @param mimeType The expected MimeType
 * @param propValue The expected Value
 * @param fileSize the expected File Size.
 * @throws ServiceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws StatusException If the operation fails
 */
public static void checkAasPropertyFile(UaClient client, NodeId node, int aasns, String name, AASModelingKindDataType kind, String category, String mimeType, String propValue, int fileSize) 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, name)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(node, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkAasPropertyFile Browse Property Result Null", bpres);
    Assert.assertTrue("checkAasPropertyFile Browse Property Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("checkAasPropertyFile Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkAasPropertyFile Property Null", targets);
    Assert.assertTrue("checkAasPropertyFile Property empty", targets.length > 0);
    NodeId propertyNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    checkDisplayName(client, propertyNode, name);
    checkCategoryNode(client, propertyNode, aasns, category);
    checkModelingKindNode(client, propertyNode, aasns, kind);
    checkDataSpecificationNode(client, propertyNode, aasns);
    checkQualifierNode(client, propertyNode, aasns, new ArrayList<>());
    relPath.clear();
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_MIME_TYPE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HasAddIn, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_FILE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(0, TestDefines.PROPERTY_SIZE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(propertyNode, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkAasPropertyFile Browse Value & Type Result Null", bpres);
    Assert.assertTrue("checkAasPropertyFile Browse Value & Type Result: size doesn't match", bpres.length == 3);
    // MimeType
    targets = bpres[0].getTargets();
    Assert.assertNotNull("checkAasPropertyFile MimeType Null", targets);
    Assert.assertTrue("checkAasPropertyFile MimeType empty", targets.length > 0);
    DataValue value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals(mimeType, value.getValue().toString());
    // Value
    targets = bpres[1].getTargets();
    Assert.assertNotNull("checkAasPropertyFile Value Null", targets);
    Assert.assertTrue("checkAasPropertyFile value empty", targets.length > 0);
    value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(propValue, value.getValue().toString());
    if (fileSize > 0) {
        // File Size
        if (bpres[2].getStatusCode().isBad()) {
            System.out.println("checkAasPropertyFile File Status " + bpres[2].getStatusCode());
        }
        targets = bpres[2].getTargets();
        Assert.assertNotNull("checkAasPropertyFile File Null", targets);
        Assert.assertTrue("checkAasPropertyFile File empty", targets.length > 0);
        value = client.readValue(targets[0].getTargetId());
        Assert.assertEquals(fileSize, value.getValue().intValue());
    }
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) 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) ExpandedNodeId(com.prosysopc.ua.stack.builtintypes.ExpandedNodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Example 17 with DataValue

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

the class TestUtils method checkModelingKind.

/**
 * Checks the ModelingKind value in the given Node. The Node must already be
 * the ModelingKind Node.
 *
 * @param client The OPC UA Client
 * @param kindNode The ModelingKind Node
 * @param modelingKind The expected ModelingKind value.
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
private static void checkModelingKind(UaClient client, NodeId kindNode, AASModelingKindDataType modelingKind) throws ServiceException, AddressSpaceException, StatusException, ServiceResultException {
    checkDisplayName(client, kindNode, TestDefines.MODELING_KIND_NAME);
    checkType(client, kindNode, Identifiers.PropertyType);
    DataValue value = client.readValue(kindNode);
    Assert.assertEquals(modelingKind.ordinal(), value.getValue().intValue());
}
Also used : DataValue(com.prosysopc.ua.stack.builtintypes.DataValue)

Example 18 with DataValue

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

the class TestUtils method checkIdentifierKeyValuePairNode.

/**
 * Checks the given IdentifierKeyValuePair Node
 *
 * @param client The OPC UA Client
 * @param node The desired node
 * @param aasns The namespace index of the AAS namespace.
 * @param map The expected values
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws StatusException If the operation fails
 */
private static void checkIdentifierKeyValuePairNode(UaClient client, NodeId node, int aasns, Map<String, String> map) throws ServiceException, AddressSpaceException, ServiceResultException, StatusException {
    checkType(client, node, new NodeId(aasns, TestDefines.AAS_ID_KEY_VALUE_PAIR_ID));
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.ID_KEY_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.ID_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(node, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkIdentifierKeyValuePairNode Browse Result Null", bpres);
    Assert.assertTrue("checkIdentifierKeyValuePairNode Browse Result: size doesn't match", bpres.length == 2);
    // Key
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkIdentifierKeyValuePairNode Browse Key Null", targets);
    Assert.assertTrue("checkIdentifierKeyValuePairNode Browse Key empty", targets.length > 0);
    DataValue dataValue = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, dataValue.getStatusCode());
    String key = dataValue.getValue().toString();
    // Value
    targets = bpres[1].getTargets();
    Assert.assertNotNull("checkIdentifierKeyValuePairNode Browse Value Null", targets);
    Assert.assertTrue("checkIdentifierKeyValuePairNode Browse Value empty", targets.length > 0);
    dataValue = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, dataValue.getStatusCode());
    String value = dataValue.getValue().toString();
    Assert.assertTrue("Key not found in Map", map.containsKey(key));
    Assert.assertEquals("Value not equal", map.get(key), value);
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ExpandedNodeId(com.prosysopc.ua.stack.builtintypes.ExpandedNodeId) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Example 19 with DataValue

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

the class TestUtils method checkIdentification.

/**
 * Checks the Identification values in the given node.
 *
 * @param client The OPC UA Client.
 * @param identificationNode the desired Identification Node.
 * @param aasns The namespace index of the AAS namespace.
 * @param idType The expected IdType
 * @param id The expected ID
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
private static void checkIdentification(UaClient client, NodeId identificationNode, int aasns, AASIdentifierTypeDataType idType, String id) throws ServiceException, StatusException, AddressSpaceException, ServiceResultException {
    checkType(client, identificationNode, new NodeId(aasns, TestDefines.AAS_IDENTIFIER_TYPE_ID));
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, "IdType")));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, "Id")));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(identificationNode, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkIdentification Browse Result Null", bpres);
    Assert.assertTrue("checkIdentification Browse Result: size doesn't match", bpres.length == 2);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkIdentification IdType Null", targets);
    Assert.assertTrue("checkIdentification IdType empty", targets.length > 0);
    DataValue value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals(idType.ordinal(), value.getValue().intValue());
    targets = bpres[1].getTargets();
    Assert.assertNotNull("checkIdentification Id Null", targets);
    Assert.assertTrue("checkIdentification Id empty", targets.length > 0);
    value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals(id, value.getValue().toString());
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ExpandedNodeId(com.prosysopc.ua.stack.builtintypes.ExpandedNodeId) ArrayList(java.util.ArrayList) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Example 20 with DataValue

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

the class TestUtils method checkCategoryNode.

/**
 * Searches for the Category Node in the given Node and checks the Category
 * value.
 *
 * @param client The OPC UA client
 * @param node The desired node
 * @param aasns The namespace index of the AAS namespace
 * @param category The expected category value
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
public static void checkCategoryNode(UaClient client, NodeId node, int aasns, String category) throws ServiceException, StatusException, AddressSpaceException, ServiceResultException {
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.CATEGORY_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(node, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("Category Result Null", bpres);
    Assert.assertTrue("Category Result: size doesn't match", bpres.length == 1);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("Browse Category Null", targets);
    Assert.assertTrue("Category targets empty", targets.length > 0);
    checkType(client, targets[0].getTargetId(), Identifiers.PropertyType);
    DataValue value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    String str = "";
    if (!value.getValue().isEmpty()) {
        str = value.getValue().toString();
    }
    Assert.assertEquals(category.isEmpty(), str.isEmpty());
    if (!category.isEmpty()) {
        Assert.assertEquals(category, value.getValue().toString());
    }
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Aggregations

DataValue (com.prosysopc.ua.stack.builtintypes.DataValue)20 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)13 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)13 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)13 ArrayList (java.util.ArrayList)13 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)12 RelativePath (com.prosysopc.ua.stack.core.RelativePath)12 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)11 ExpandedNodeId (com.prosysopc.ua.stack.builtintypes.ExpandedNodeId)7 UaClient (com.prosysopc.ua.client.UaClient)6 Test (org.junit.Test)6 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)4 AASKeyDataType (opc.i4aas.AASKeyDataType)4 Variant (com.prosysopc.ua.stack.builtintypes.Variant)3 ReferenceDescription (com.prosysopc.ua.stack.core.ReferenceDescription)3 LangString (io.adminshell.aas.v3.model.LangString)3 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)3 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)2 ValueChangeEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ValueChangeEventMessage)2 Key (io.adminshell.aas.v3.model.Key)2