Search in sources :

Example 1 with MethodCallStatusException

use of com.prosysopc.ua.MethodCallStatusException 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();
}
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) UaClient(com.prosysopc.ua.client.UaClient) Variant(com.prosysopc.ua.stack.builtintypes.Variant) MethodCallStatusException(com.prosysopc.ua.MethodCallStatusException) StatusException(com.prosysopc.ua.StatusException) 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)

Aggregations

MethodCallStatusException (com.prosysopc.ua.MethodCallStatusException)1 StatusException (com.prosysopc.ua.StatusException)1 UaClient (com.prosysopc.ua.client.UaClient)1 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)1 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)1 Variant (com.prosysopc.ua.stack.builtintypes.Variant)1 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)1 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)1 RelativePath (com.prosysopc.ua.stack.core.RelativePath)1 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1