Search in sources :

Example 1 with TestModuleIdentity

use of tests.integration.com.microsoft.azure.sdk.iot.helpers.TestModuleIdentity in project azure-iot-sdk-java by Azure.

the class ReceiveMessagesTests method receiveMessage.

public void receiveMessage(int messageSize) throws Exception {
    if (testInstance.protocol == HTTPS) {
        testInstance.identity.getClient().setOption(SET_MINIMUM_POLLING_INTERVAL, ONE_SECOND_POLLING_INTERVAL);
    }
    testInstance.identity.getClient().open();
    Message serviceMessage = createCloudToDeviceMessage(messageSize);
    com.microsoft.azure.sdk.iot.device.MessageCallback callback = new MessageCallback(serviceMessage);
    if (testInstance.protocol == MQTT || testInstance.protocol == MQTT_WS) {
        callback = new MessageCallbackMqtt(serviceMessage);
    }
    Success messageReceived = new Success();
    if (testInstance.identity.getClient() instanceof DeviceClient) {
        ((DeviceClient) testInstance.identity.getClient()).setMessageCallback(callback, messageReceived);
    } else if (testInstance.identity.getClient() instanceof ModuleClient) {
        ((ModuleClient) testInstance.identity.getClient()).setMessageCallback(callback, messageReceived);
    }
    if (testInstance.identity.getClient() instanceof DeviceClient) {
        testInstance.serviceClient.send(testInstance.identity.getDeviceId(), serviceMessage);
    } else if (testInstance.identity.getClient() instanceof ModuleClient) {
        testInstance.serviceClient.send(testInstance.identity.getDeviceId(), ((TestModuleIdentity) testInstance.identity).getModuleId(), serviceMessage);
    }
    waitForMessageToBeReceived(messageReceived, testInstance.protocol.toString());
    Thread.sleep(200);
    testInstance.identity.getClient().closeNow();
}
Also used : Message(com.microsoft.azure.sdk.iot.service.Message) DeviceClient(com.microsoft.azure.sdk.iot.device.DeviceClient) ModuleClient(com.microsoft.azure.sdk.iot.device.ModuleClient) Success(tests.integration.com.microsoft.azure.sdk.iot.helpers.Success) TestModuleIdentity(tests.integration.com.microsoft.azure.sdk.iot.helpers.TestModuleIdentity)

Example 2 with TestModuleIdentity

use of tests.integration.com.microsoft.azure.sdk.iot.helpers.TestModuleIdentity in project azure-iot-sdk-java by Azure.

the class DeviceMethodCommon method invokeMethodSucceed.

protected void invokeMethodSucceed() throws Exception {
    // Arrange
    DeviceTestManager deviceTestManger = this.testInstance.deviceTestManager;
    // Act
    MethodResult result;
    if (testInstance.identity instanceof TestModuleIdentity) {
        result = testInstance.methodServiceClient.invoke(testInstance.identity.getDeviceId(), ((TestModuleIdentity) testInstance.identity).getModule().getId(), DeviceEmulator.METHOD_LOOPBACK, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, PAYLOAD_STRING);
    } else {
        result = testInstance.methodServiceClient.invoke(testInstance.identity.getDeviceId(), DeviceEmulator.METHOD_LOOPBACK, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, PAYLOAD_STRING);
    }
    deviceTestManger.waitIotHub(1, 10);
    // Assert
    assertNotNull(result);
    assertEquals((long) DeviceEmulator.METHOD_SUCCESS, (long) result.getStatus());
    assertEquals(DeviceEmulator.METHOD_LOOPBACK + ":" + PAYLOAD_STRING, result.getPayload());
    Assert.assertEquals(0, deviceTestManger.getStatusError());
}
Also used : DeviceTestManager(tests.integration.com.microsoft.azure.sdk.iot.helpers.DeviceTestManager) MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) TestModuleIdentity(tests.integration.com.microsoft.azure.sdk.iot.helpers.TestModuleIdentity)

Example 3 with TestModuleIdentity

use of tests.integration.com.microsoft.azure.sdk.iot.helpers.TestModuleIdentity in project azure-iot-sdk-java by Azure.

the class DeviceMethodTests method invokeMethodNullPayloadSucceed.

@Test
@StandardTierHubOnlyTest
@ContinuousIntegrationTest
public void invokeMethodNullPayloadSucceed() throws Exception {
    // Arrange
    super.openDeviceClientAndSubscribeToMethods();
    DeviceTestManager deviceTestManger = this.testInstance.deviceTestManager;
    // Act
    MethodResult result;
    if (testInstance.identity instanceof TestModuleIdentity) {
        result = testInstance.methodServiceClient.invoke(testInstance.identity.getDeviceId(), ((TestModuleIdentity) testInstance.identity).getModuleId(), DeviceEmulator.METHOD_LOOPBACK, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, null);
    } else {
        result = testInstance.methodServiceClient.invoke(testInstance.identity.getDeviceId(), DeviceEmulator.METHOD_LOOPBACK, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, null);
    }
    deviceTestManger.waitIotHub(1, 10);
    // Assert
    assertNotNull(buildExceptionMessage("method result was null", testInstance.deviceTestManager.client), result);
    assertEquals(buildExceptionMessage("Expected SUCCESS but got " + result.getStatus(), testInstance.deviceTestManager.client), (long) DeviceEmulator.METHOD_SUCCESS, (long) result.getStatus());
    assertEquals(buildExceptionMessage("Expected " + DeviceEmulator.METHOD_LOOPBACK + ":null" + " but got " + result.getPayload(), deviceTestManger.client), DeviceEmulator.METHOD_LOOPBACK + ":null", result.getPayload());
    Assert.assertEquals(buildExceptionMessage("Unexpected status errors occurred", testInstance.deviceTestManager.client), 0, deviceTestManger.getStatusError());
}
Also used : DeviceTestManager(tests.integration.com.microsoft.azure.sdk.iot.helpers.DeviceTestManager) MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) TestModuleIdentity(tests.integration.com.microsoft.azure.sdk.iot.helpers.TestModuleIdentity) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)

Example 4 with TestModuleIdentity

use of tests.integration.com.microsoft.azure.sdk.iot.helpers.TestModuleIdentity in project azure-iot-sdk-java by Azure.

the class DeviceMethodTests method invokeMethodRecoverFromTimeoutSucceed.

@Test
@StandardTierHubOnlyTest
@ContinuousIntegrationTest
public void invokeMethodRecoverFromTimeoutSucceed() throws Exception {
    // Arrange
    super.openDeviceClientAndSubscribeToMethods();
    DeviceTestManager deviceTestManger = this.testInstance.deviceTestManager;
    try {
        if (testInstance.identity instanceof TestModuleIdentity) {
            testInstance.methodServiceClient.invoke(testInstance.identity.getDeviceId(), ((TestModuleIdentity) testInstance.identity).getModuleId(), DeviceEmulator.METHOD_DELAY_IN_MILLISECONDS, (long) 5, CONNECTION_TIMEOUT, "7000");
        } else {
            testInstance.methodServiceClient.invoke(testInstance.identity.getDeviceId(), DeviceEmulator.METHOD_DELAY_IN_MILLISECONDS, (long) 5, CONNECTION_TIMEOUT, "7000");
        }
        assert true;
    } catch (IotHubGatewayTimeoutException expected) {
    // Don't do anything. Expected throw.
    }
    // Act
    MethodResult result;
    if (testInstance.identity instanceof TestModuleIdentity) {
        result = testInstance.methodServiceClient.invoke(testInstance.identity.getDeviceId(), ((TestModuleIdentity) testInstance.identity).getModuleId(), DeviceEmulator.METHOD_DELAY_IN_MILLISECONDS, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, "100");
    } else {
        result = testInstance.methodServiceClient.invoke(testInstance.identity.getDeviceId(), DeviceEmulator.METHOD_DELAY_IN_MILLISECONDS, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, "100");
    }
    deviceTestManger.waitIotHub(1, 10);
    // Assert
    assertNotNull(buildExceptionMessage("method result was null", testInstance.deviceTestManager.client), result);
    assertEquals(buildExceptionMessage("Expected SUCCESS but got " + result.getStatus(), testInstance.deviceTestManager.client), (long) DeviceEmulator.METHOD_SUCCESS, (long) result.getStatus());
    assertEquals(buildExceptionMessage("Expected " + DeviceEmulator.METHOD_DELAY_IN_MILLISECONDS + ":succeed" + " But got " + result.getPayload(), testInstance.deviceTestManager.client), DeviceEmulator.METHOD_DELAY_IN_MILLISECONDS + ":succeed", result.getPayload());
    Assert.assertEquals(buildExceptionMessage("Unexpected status errors occurred", testInstance.deviceTestManager.client), 0, deviceTestManger.getStatusError());
}
Also used : DeviceTestManager(tests.integration.com.microsoft.azure.sdk.iot.helpers.DeviceTestManager) IotHubGatewayTimeoutException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubGatewayTimeoutException) TestModuleIdentity(tests.integration.com.microsoft.azure.sdk.iot.helpers.TestModuleIdentity) MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)

Aggregations

TestModuleIdentity (tests.integration.com.microsoft.azure.sdk.iot.helpers.TestModuleIdentity)4 MethodResult (com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult)3 DeviceTestManager (tests.integration.com.microsoft.azure.sdk.iot.helpers.DeviceTestManager)3 Test (org.junit.Test)2 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)2 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)2 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)2 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)1 ModuleClient (com.microsoft.azure.sdk.iot.device.ModuleClient)1 Message (com.microsoft.azure.sdk.iot.service.Message)1 IotHubGatewayTimeoutException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubGatewayTimeoutException)1 Success (tests.integration.com.microsoft.azure.sdk.iot.helpers.Success)1