use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method invoke_succeed.
/* Tests_SRS_DEVICEMETHOD_21_015: [If the HttpStatus represents success, the invoke shall return the status and payload using the `MethodResult` class.] */
@Test
public void invoke_succeed(@Mocked final MethodParser methodParser, @Mocked final DeviceOperations request, @Mocked final IotHubServiceSasToken iotHubServiceSasToken, @Mocked final IotHubConnectionStringBuilder mockedConnectionStringBuilder) throws Exception {
//arrange
DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
new NonStrictExpectations() {
{
iotHubConnectionString.getUrlMethod(STANDARD_DEVICEID);
result = STANDARD_URL;
methodParser.toJson();
result = STANDARD_JSON;
methodParser.getPayload();
result = STANDARD_PAYLOAD_STR;
methodParser.getStatus();
result = 123;
}
};
//act
MethodResult result = testMethod.invoke(STANDARD_DEVICEID, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP);
//assert
assertThat(result.getStatus(), is(123));
assertThat(result.getPayload().toString(), is(STANDARD_PAYLOAD_STR));
new Verifications() {
{
methodParser.toJson();
times = 1;
iotHubConnectionString.getUrlMethod(STANDARD_DEVICEID);
times = 1;
methodParser.getPayload();
times = 1;
methodParser.getStatus();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.
the class MethodResultTest method constructorCreatesNewMethodResult_NullPayload.
@Test
public void constructorCreatesNewMethodResult_NullPayload() {
//act
MethodResult methodResult = new MethodResult(123, null);
//assert
assertNotNull(methodResult);
assertThat(methodResult.getStatus(), is(123));
assertNull(methodResult.getPayload());
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.
the class DeviceMethodIT method invokeMethod_nullPayload_succeed.
@Test
public void invokeMethod_nullPayload_succeed() throws Exception {
// Arrange
TestDevice testDevice = devices.get(0);
// Act
MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_LOOPBACK, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, null);
testDevice.waitIotHub(1, 10);
// Assert
assertNotNull(result);
assertEquals((long) METHOD_SUCCESS, (long) result.getStatus());
assertEquals(METHOD_LOOPBACK + ":null", result.getPayload());
assertEquals(0, testDevice.getStatusError());
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.
the class DeviceMethodIT method invokeMethod_defaultConnectionTimeout_succeed.
@Test
public void invokeMethod_defaultConnectionTimeout_succeed() throws Exception {
// Arrange
TestDevice testDevice = devices.get(0);
// Act
MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_DELAY_IN_MILLISECONDS, RESPONSE_TIMEOUT, null, "100");
testDevice.waitIotHub(1, 10);
// Assert
assertNotNull(result);
assertEquals((long) METHOD_SUCCESS, (long) result.getStatus());
assertEquals(METHOD_DELAY_IN_MILLISECONDS + ":succeed", result.getPayload());
assertEquals(0, testDevice.getStatusError());
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.
the class DeviceMethodIT method invokeMethod_invokeParallel_succeed.
@Test
public void invokeMethod_invokeParallel_succeed() throws Exception {
// Arrange
TestDevice testDevice = devices.get(0);
CountDownLatch cdl = new CountDownLatch(NUMBER_INVOKES_PARALLEL);
List<RunnableInvoke> runs = new LinkedList<>();
for (int i = 0; i < NUMBER_INVOKES_PARALLEL; i++) {
RunnableInvoke runnableInvoke = new RunnableInvoke(testDevice.getDeviceId(), "Thread" + i, cdl);
new Thread(runnableInvoke).start();
runs.add(runnableInvoke);
}
cdl.await();
for (RunnableInvoke run : runs) {
MethodResult result = run.getResult();
assertNotNull(result);
assertEquals((long) METHOD_SUCCESS, (long) result.getStatus());
assertEquals(run.getExpectedPayload(), result.getPayload().toString());
}
}
Aggregations