use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method invoke_throwOnToJson_failed.
/* Tests_SRS_DEVICEMETHOD_21_011: [The invoke shall add a HTTP body with Json created by the `serializer.MethodParser`.] */
@Test(expected = IllegalArgumentException.class)
public void invoke_throwOnToJson_failed(@Mocked final MethodParser methodParser) throws Exception {
//arrange
DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
new NonStrictExpectations() {
{
methodParser.toJson();
result = new IllegalArgumentException();
}
};
//act
testMethod.invoke(STANDARD_DEVICEID, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method invoke_throwOnCreateMethod_failed.
/* Tests_SRS_DEVICEMETHOD_21_005: [The invoke shall throw IllegalArgumentException if the provided methodName is null, empty, or not valid.] */
/* Tests_SRS_DEVICEMETHOD_21_006: [The invoke shall throw IllegalArgumentException if the provided responseTimeoutInSeconds is negative.] */
/* Tests_SRS_DEVICEMETHOD_21_007: [The invoke shall throw IllegalArgumentException if the provided connectTimeoutInSeconds is negative.] */
/* Tests_SRS_DEVICEMETHOD_21_014: [The invoke shall bypass the Exception if one of the functions called by invoke failed.] */
@Test(expected = IllegalArgumentException.class)
public void invoke_throwOnCreateMethod_failed() throws Exception {
//arrange
new MockUp<MethodParser>() {
@Mock
void $init(String name, Long responseTimeoutInSeconds, Long connectTimeoutInSeconds, Object payload) throws IllegalArgumentException {
throw new IllegalArgumentException();
}
};
DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
//act
testMethod.invoke(STANDARD_DEVICEID, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod 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...");
}
Aggregations