Search in sources :

Example 1 with AddressSpace

use of org.eclipse.milo.opcua.sdk.client.AddressSpace in project milo by eclipse.

the class UaMethodTest method callMethodWithNoInputsOrOutputs.

@Test
public void callMethodWithNoInputsOrOutputs() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaObjectNode objectsNode = addressSpace.getObjectNode(Identifiers.ObjectsFolder);
    Variant[] outputs = objectsNode.callMethod(new QualifiedName(2, "hasNoInputsOrOutputs()"), new Variant[0]);
    assertEquals(0, outputs.length);
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 2 with AddressSpace

use of org.eclipse.milo.opcua.sdk.client.AddressSpace in project milo by eclipse.

the class UaMethodTest method findMethodNotFound.

@Test
public void findMethodNotFound() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaObjectNode serverNode = addressSpace.getObjectNode(Identifiers.Server);
    assertThrows(UaException.class, () -> serverNode.getMethod("foo"));
}
Also used : AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 3 with AddressSpace

use of org.eclipse.milo.opcua.sdk.client.AddressSpace in project milo by eclipse.

the class UaMethodTest method throwsUaMethodException.

@Test
public void throwsUaMethodException() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaObjectNode objectsNode = addressSpace.getObjectNode(Identifiers.ObjectsFolder);
    assertThrows(UaMethodException.class, () -> {
        try {
            objectsNode.callMethod(new QualifiedName(2, "onlyAcceptsPositiveInputs()"), new Variant[] { new Variant(-1) });
        } catch (UaMethodException e) {
            System.out.println("result: " + e.getStatusCode());
            System.out.println("inputArgumentResults: " + Arrays.toString(e.getInputArgumentResults()));
            throw e;
        }
    });
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 4 with AddressSpace

use of org.eclipse.milo.opcua.sdk.client.AddressSpace in project milo by eclipse.

the class UaMethodTest method callMethodWithHasComponentReference.

@Test
public void callMethodWithHasComponentReference() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaObjectNode objectsNode = addressSpace.getObjectNode(Identifiers.ObjectsFolder);
    Variant[] outputs = objectsNode.callMethod(new QualifiedName(2, "sqrt(x)"), new Variant[] { new Variant(16.0) });
    assertEquals(4.0, outputs[0].getValue());
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 5 with AddressSpace

use of org.eclipse.milo.opcua.sdk.client.AddressSpace in project milo by eclipse.

the class AbstractMethodInvocationHandlerTest method implementationCanValidateArguments.

@Test
public void implementationCanValidateArguments() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaObjectNode objectsNode = addressSpace.getObjectNode(Identifiers.ObjectsFolder);
    try {
        objectsNode.callMethod(new QualifiedName(2, "onlyAcceptsPositiveInputs()"), new Variant[] { new Variant(-1) });
    } catch (UaMethodException e) {
        System.out.println("result: " + e.getStatusCode());
        System.out.println("inputArgumentResults: " + Arrays.toString(e.getInputArgumentResults()));
        assertEquals(StatusCodes.Bad_InvalidArgument, e.getStatusCode().getValue());
        assertEquals(StatusCodes.Bad_OutOfRange, e.getInputArgumentResults()[0].getValue());
    }
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) UaMethodException(org.eclipse.milo.opcua.sdk.client.methods.UaMethodException) UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Aggregations

AddressSpace (org.eclipse.milo.opcua.sdk.client.AddressSpace)10 UaObjectNode (org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode)9 AbstractClientServerTest (org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)9 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)9 Test (org.junit.jupiter.api.Test)9 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)6 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)3 ManagedDataItem (org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedDataItem)2 ManagedSubscription (org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedSubscription)2 Argument (org.eclipse.milo.opcua.stack.core.types.structured.Argument)2 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 OpcUaClient (org.eclipse.milo.opcua.sdk.client.OpcUaClient)1 UaMethod (org.eclipse.milo.opcua.sdk.client.methods.UaMethod)1 UaMethodException (org.eclipse.milo.opcua.sdk.client.methods.UaMethodException)1 ObjectNode (org.eclipse.milo.opcua.sdk.core.nodes.ObjectNode)1 ObjectNodeProperties (org.eclipse.milo.opcua.sdk.core.nodes.ObjectNodeProperties)1