use of com.prosysopc.ua.stack.builtintypes.Variant in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method checkAasPropertyString.
/**
* Checks the String 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 valueType The expected ValueType
* @param propValue The expected Value
* @param qualifierList The list of qualifiers
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws StatusException If the operation fails
* @throws ServiceResultException If the operation fails
*/
public static void checkAasPropertyString(UaClient client, NodeId node, int aasns, String name, AASModelingKindDataType kind, String category, AASValueTypeDataType valueType, String propValue, List<Qualifier> qualifierList) throws ServiceException, AddressSpaceException, StatusException, ServiceResultException {
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("checkAasPropertyString Browse Property Result Null", bpres);
Assert.assertTrue("checkAasPropertyString Browse Property Result: size doesn't match", bpres.length == 1);
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("checkAasPropertyString Property Null", targets);
Assert.assertTrue("checkAasPropertyString 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, qualifierList);
relPath.clear();
browsePath.clear();
browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_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)));
bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(propertyNode, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("checkAasPropertyString Browse Value & Type Result Null", bpres);
Assert.assertTrue("checkAasPropertyString Browse Value & Type Result: size doesn't match", bpres.length == 2);
targets = bpres[0].getTargets();
Assert.assertNotNull("checkAasPropertyString ValueType Null", targets);
Assert.assertTrue("checkAasPropertyString ValueType empty", targets.length > 0);
DataValue value = client.readValue(targets[0].getTargetId());
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertEquals(valueType.ordinal(), value.getValue().intValue());
targets = bpres[1].getTargets();
Assert.assertNotNull("checkAasPropertyString Value Null", targets);
Assert.assertTrue("checkAasPropertyString value empty", targets.length > 0);
value = client.readValue(targets[0].getTargetId());
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
// Variant var;
// if (valueType == AASValueTypeDataType.LocalizedText) {
// var = new Variant(LocalizedText.english(propValue));
// }
// else {
// var = new Variant(propValue);
// }
Variant var = new Variant(propValue);
Assert.assertEquals(var, value.getValue());
}
use of com.prosysopc.ua.stack.builtintypes.Variant in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpointFullTest method testCallOperationArgsMissing.
/**
* Test method for calling an operation with not enough arguments.
*
* @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 MethodCallStatusException If the operation fails
*/
@Test
public void testCallOperationArgsMissing() throws SecureIdentityException, IOException, ServiceException, ServiceResultException, MethodCallStatusException {
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());
int serverns = client.getAddressSpace().getNamespaceTable().getIndex(AasServiceNodeManager.NAMESPACE_URI);
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_3_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_OPERATION_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
browsePath.clear();
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_3_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_OPERATION_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(serverns, TestDefines.FULL_OPERATION_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testCallOperationArgsMissing Browse Result Null", bpres);
Assert.assertEquals("testCallOperationArgsMissing Browse Result: size doesn't match", 2, bpres.length);
Assert.assertTrue("testCallOperationArgsMissing Browse Result Good", bpres[0].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testCallOperationArgsMissing Object Targets Null", targets);
Assert.assertTrue("testCallOperationArgsMissing Object Targets empty", targets.length > 0);
NodeId objectNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
Assert.assertNotNull("testCallOperationArgsMissing objectNode Null", objectNode);
targets = bpres[1].getTargets();
Assert.assertNotNull("testCallOperationArgsMissing Method Targets Null", targets);
Assert.assertTrue("testCallOperationArgsMissing Method Targets empty", targets.length > 0);
NodeId methodNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
Assert.assertNotNull("testCallOperationArgsMissing methodNode Null", methodNode);
Variant[] inputArguments = new Variant[0];
StatusException exception = Assert.assertThrows(StatusException.class, () -> {
client.call(objectNode, methodNode, inputArguments);
});
Assert.assertEquals(StatusCodes.Bad_ArgumentsMissing, exception.getStatusCode().getValue());
System.out.println("disconnect client");
client.disconnect();
}
use of com.prosysopc.ua.stack.builtintypes.Variant in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpointFullTest method testCallOperationSuccess.
/**
* Test method for successfully calling an operation.
*
* @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 MethodCallStatusException If the operation fails
*/
@Test
public void testCallOperationSuccess() throws SecureIdentityException, IOException, ServiceException, ServiceResultException, MethodCallStatusException {
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());
int serverns = client.getAddressSpace().getNamespaceTable().getIndex(AasServiceNodeManager.NAMESPACE_URI);
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_3_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_OPERATION_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
browsePath.clear();
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_3_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_OPERATION_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(serverns, TestDefines.FULL_OPERATION_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testCallOperationSuccess Browse Result Null", bpres);
Assert.assertEquals("testCallOperationSuccess Browse Result: size doesn't match", 2, bpres.length);
Assert.assertTrue("testCallOperationSuccess Browse Result Good", bpres[0].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testCallOperationSuccess Object Targets Null", targets);
Assert.assertTrue("testCallOperationSuccess Object Targets empty", targets.length > 0);
NodeId objectNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
Assert.assertNotNull("testCallOperationSuccess objectNode Null", objectNode);
targets = bpres[1].getTargets();
Assert.assertNotNull("testCallOperationSuccess Method Targets Null", targets);
Assert.assertTrue("testCallOperationSuccess Method Targets empty", targets.length > 0);
NodeId methodNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
Assert.assertNotNull("testCallOperationSuccess methodNode Null", methodNode);
Variant[] inputArguments = new Variant[1];
inputArguments[0] = new Variant("123454");
Variant[] outputs = client.call(objectNode, methodNode, inputArguments);
Assert.assertNotNull("testCallOperationSuccess output Arguments Null", outputs);
Assert.assertEquals("testCallOperationSuccess output Arguments length not equal", 1, outputs.length);
Assert.assertEquals("testCallOperationSuccess output Argument 0 not equal", new Variant("XYZ1"), outputs[0]);
System.out.println("disconnect client");
client.disconnect();
}
use of com.prosysopc.ua.stack.builtintypes.Variant in project FAAAST-Service by FraunhoferIOSB.
the class AASSubmodelTypeImplBase method getModelingKind.
@Mandatory
@Override
public AASModelingKindDataType getModelingKind() {
UaVariable node = getModelingKindNode();
if (node == null) {
return null;
}
Variant value = node.getValue().getValue();
return (AASModelingKindDataType) value.asEnum(AASModelingKindDataType.class);
}
use of com.prosysopc.ua.stack.builtintypes.Variant in project FAAAST-Service by FraunhoferIOSB.
the class AASPropertyTypeImplBase method getValueType.
@Mandatory
@Override
public AASValueTypeDataType getValueType() {
UaVariable node = getValueTypeNode();
if (node == null) {
return null;
}
Variant value = node.getValue().getValue();
return (AASValueTypeDataType) value.asEnum(AASValueTypeDataType.class);
}
Aggregations