Search in sources :

Example 1 with DeviceMethodData

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.

the class DeviceMethodDataTest method setStatusSets.

/*
    **Tests_SRS_DEVICEMETHODDATA_25_007: [**The method shall set the status.**]**
     */
@Test
public void setStatusSets() {
    //arrange
    DeviceMethodData testData = new DeviceMethodData(0, "testMessage");
    //act
    testData.setStatus(200);
    //assert
    int testStatus = testData.getStatus();
    assertTrue(testStatus == 200);
}
Also used : DeviceMethodData(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData) Test(org.junit.Test)

Example 2 with DeviceMethodData

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.

the class DeviceMethodDataTest method constructorSucceeds.

/*
    **Tests_SRS_DEVICEMETHODDATA_25_001: [**The constructor shall save the status and reponse message provided by user.**]**
     */
@Test
public void constructorSucceeds() {
    //act
    DeviceMethodData testData = new DeviceMethodData(0, "testMessage");
    //assert
    int testStatus = testData.getStatus();
    String testResponse = testData.getResponseMessage();
    assertTrue(testStatus == 0);
    assertEquals(testResponse, "testMessage");
}
Also used : DeviceMethodData(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData) Test(org.junit.Test)

Example 3 with DeviceMethodData

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.

the class TokenCredentialTests method invokeMethodSucceedWithTokenCredential.

@Test
public void invokeMethodSucceedWithTokenCredential() throws Exception {
    // only run tests for standard tier hubs
    Assume.assumeFalse(isBasicTierHub);
    DeviceMethod methodServiceClient = buildDeviceMethodClientWithTokenCredential();
    RegistryManager registryManager = new RegistryManager(iotHubConnectionString);
    Device device = Device.createDevice("some-device-" + UUID.randomUUID(), AuthenticationType.SAS);
    registryManager.addDevice(device);
    DeviceClient deviceClient = new DeviceClient(registryManager.getDeviceConnectionString(device), MQTT);
    deviceClient.open();
    final int successStatusCode = 200;
    final AtomicBoolean methodsSubscriptionComplete = new AtomicBoolean(false);
    final AtomicBoolean methodsSubscribedSuccessfully = new AtomicBoolean(false);
    deviceClient.subscribeToDeviceMethod((methodName, methodData, context) -> new DeviceMethodData(successStatusCode, "success"), null, (responseStatus, callbackContext) -> {
        if (responseStatus == IotHubStatusCode.OK_EMPTY || responseStatus == IotHubStatusCode.OK) {
            methodsSubscribedSuccessfully.set(true);
        }
        methodsSubscriptionComplete.set(true);
    }, null);
    long startTime = System.currentTimeMillis();
    while (!methodsSubscriptionComplete.get()) {
        Thread.sleep(200);
        if (System.currentTimeMillis() - startTime > METHOD_SUBSCRIPTION_TIMEOUT_MILLISECONDS) {
            fail("Timed out waiting for device registration to complete.");
        }
    }
    assertTrue("Method subscription callback fired with non 200 status code", methodsSubscribedSuccessfully.get());
    MethodResult result = methodServiceClient.invoke(device.getDeviceId(), "someMethod", 5l, 5l, null);
    assertEquals((long) successStatusCode, (long) result.getStatus());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Device(com.microsoft.azure.sdk.iot.service.Device) DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) DeviceClient(com.microsoft.azure.sdk.iot.device.DeviceClient) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) DeviceMethodData(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData) DeviceMethod(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod) MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) Test(org.junit.Test)

Example 4 with DeviceMethodData

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.

the class DeviceMethodDataTest method constructorSucceeds.

/*
    **Tests_SRS_DEVICEMETHODDATA_25_001: [**The constructor shall save the status and response message provided by user.**]**
     */
@Test
public void constructorSucceeds() {
    // act
    DeviceMethodData testData = new DeviceMethodData(0, "testMessage");
    // assert
    int testStatus = testData.getStatus();
    String testResponse = testData.getResponseMessage();
    assertEquals(0, testStatus);
    assertEquals(testResponse, "testMessage");
}
Also used : DeviceMethodData(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData) Test(org.junit.Test)

Example 5 with DeviceMethodData

use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.

the class DeviceMethodDataTest method GetStatusGets.

/*
    **Tests_SRS_DEVICEMETHODDATA_25_003: [**This method shall return the status previously set.**]**
     */
@Test
public void GetStatusGets() {
    // arrange
    DeviceMethodData testData = new DeviceMethodData(0, "testMessage");
    // act
    int testStatus = testData.getStatus();
    // assert
    assertEquals(0, testStatus);
}
Also used : DeviceMethodData(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData) Test(org.junit.Test)

Aggregations

DeviceMethodData (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData)12 Test (org.junit.Test)12 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)2 Device (com.microsoft.azure.sdk.iot.service.Device)2 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)2 AzureSasCredential (com.azure.core.credential.AzureSasCredential)1 TokenCredential (com.azure.core.credential.TokenCredential)1 ClientOptions (com.microsoft.azure.sdk.iot.device.ClientOptions)1 DeviceMethodCallback (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodCallback)1 Pair (com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair)1 Property (com.microsoft.azure.sdk.iot.device.DeviceTwin.Property)1 TwinPropertyCallBack (com.microsoft.azure.sdk.iot.device.DeviceTwin.TwinPropertyCallBack)1 IotHubClientProtocol (com.microsoft.azure.sdk.iot.device.IotHubClientProtocol)1 IotHubEventCallback (com.microsoft.azure.sdk.iot.device.IotHubEventCallback)1 MultiplexingClient (com.microsoft.azure.sdk.iot.device.MultiplexingClient)1 MultiplexingClientException (com.microsoft.azure.sdk.iot.device.exceptions.MultiplexingClientException)1 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)1 IotHubConnectionStringBuilder (com.microsoft.azure.sdk.iot.service.IotHubConnectionStringBuilder)1 ProxyOptions (com.microsoft.azure.sdk.iot.service.ProxyOptions)1 RegistryManagerOptions (com.microsoft.azure.sdk.iot.service.RegistryManagerOptions)1