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();
}
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());
}
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());
}
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());
}
Aggregations