use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.
the class DeviceMethodIT method invokeMethod_standardTimeout_succeed.
@Test
public void invokeMethod_standardTimeout_succeed() throws Exception {
// Arrange
TestDevice testDevice = devices.get(0);
// Act
MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_LOOPBACK, null, null, PAYLOAD_STRING);
testDevice.waitIotHub(1, 10);
// Assert
assertNotNull(result);
assertEquals((long) METHOD_SUCCESS, (long) result.getStatus());
assertEquals(METHOD_LOOPBACK + ":" + PAYLOAD_STRING, 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_responseTimeout_failed.
@Test(expected = IotHubGatewayTimeoutException.class)
public void invokeMethod_responseTimeout_failed() throws Exception {
// Arrange
TestDevice testDevice = devices.get(0);
// Act
MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_DELAY_IN_MILLISECONDS, (long) 5, CONNECTION_TIMEOUT, "7000");
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.
the class DeviceMethodSample method main.
/**
* @param args
* @throws IOException
* @throws URISyntaxException
*/
public static void main(String[] args) throws Exception {
System.out.println("Starting sample...");
DeviceMethod methodClient = DeviceMethod.createFromConnectionString(iotHubConnectionString);
try {
// Manage complete Method
System.out.println("Getting device Method");
MethodResult result = methodClient.invoke(deviceId, methodName, responseTimeout, connectTimeout, payload);
if (result == null) {
throw new IOException("Method invoke returns null");
}
System.out.println("Status=" + result.getStatus());
System.out.println("Payload=" + result.getPayload());
} catch (IotHubException e) {
System.out.println(e.getMessage());
}
System.out.println("Shutting down sample...");
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.
the class DeviceMethodIT method invokeMethod_number_succeed.
@Test
public void invokeMethod_number_succeed() throws Exception {
// Arrange
TestDevice testDevice = devices.get(0);
// Act
MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_DELAY_IN_MILLISECONDS, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, "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_resetDevice_failed.
@Test
public void invokeMethod_resetDevice_failed() throws Exception {
// Arrange
TestDevice testDevice = devices.get(0);
// Act
try {
MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_RESET, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, null);
testDevice.restartDevice();
throw new Exception("Reset device do not affect the method invoke on the service");
} catch (IotHubNotFoundException expected) {
// Don't do anything, expected throw.
}
testDevice.restartDevice();
}
Aggregations