use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method invoke_IllegalParameters_failed.
/* Tests_SRS_DEVICEMETHOD_21_004: [The invoke shall throw IllegalArgumentException if the provided deviceId is null or empty.] */
@Test
public void invoke_IllegalParameters_failed() throws Exception {
//arrange
DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
//act
for (TestMethod testCase : illegalParameter) {
try {
testMethod.invoke(testCase.deviceId, testCase.methodName, testCase.responseTimeoutInSeconds, testCase.connectTimeoutInSeconds, testCase.payload);
System.out.print("Negative case> DeviceId=" + testCase.deviceId + " MethodName=" + testCase.methodName + " responseTimeoutInSeconds=" + testCase.responseTimeoutInSeconds + " connectTimeoutInSeconds=" + testCase.connectTimeoutInSeconds + " payload=" + testCase.payload + "\r\n");
assert true;
} catch (IllegalArgumentException expected) {
//Don't do anything. Expected throw.
}
}
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method constructor_throwOnNullCS_failed.
/* Tests_SRS_DEVICEMETHOD_21_001: [The constructor shall throw IllegalArgumentException if the input string is null or empty.] */
@Test(expected = IllegalArgumentException.class)
public void constructor_throwOnNullCS_failed() throws Exception {
//arrange
final String connectionString = null;
//act
DeviceMethod testMethod = DeviceMethod.createFromConnectionString(connectionString);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method invoke_throwOnNullJson_failed.
/* Tests_SRS_DEVICEMETHOD_21_012: [If `MethodParser` return a null Json, the invoke shall throw IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void invoke_throwOnNullJson_failed(@Mocked final MethodParser methodParser) throws Exception {
//arrange
DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
new NonStrictExpectations() {
{
methodParser.toJson();
result = null;
}
};
//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_throwOnHttpRequester_failed.
/* Tests_SRS_DEVICEMETHOD_21_009: [The invoke shall send the created request and get the response using the HttpRequester.] */
/* Tests_SRS_DEVICEMETHOD_21_010: [The invoke shall create a new HttpRequest with http method as `POST`.] */
@Test(expected = IotHubException.class)
public void invoke_throwOnHttpRequester_failed(@Mocked final MethodParser methodParser, @Mocked final IotHubConnectionStringBuilder mockedConnectionStringBuilder) throws Exception {
//arrange
DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
new NonStrictExpectations() {
{
methodParser.toJson();
result = STANDARD_JSON;
iotHubConnectionString.getUrlMethod(STANDARD_DEVICEID);
result = STANDARD_URL;
}
};
new MockUp<DeviceOperations>() {
@Mock
HttpResponse request(IotHubConnectionString iotHubConnectionString, URL url, HttpMethod method, byte[] payload, String requestId, long timeoutInMs) throws IOException, IotHubException, IllegalArgumentException {
throw new IotHubException();
}
};
//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_throwOnGetUrlMethod_failed.
/* Tests_SRS_DEVICEMETHOD_21_008: [The invoke shall build the Method URL `{iot hub}/twins/{device id}/methods/` by calling getUrlMethod.] */
@Test(expected = IllegalArgumentException.class)
public void invoke_throwOnGetUrlMethod_failed(@Mocked final MethodParser methodParser, @Mocked final IotHubConnectionStringBuilder mockedConnectionStringBuilder) throws Exception {
//arrange
DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
new NonStrictExpectations() {
{
methodParser.toJson();
result = STANDARD_JSON;
iotHubConnectionString.getUrlMethod(STANDARD_DEVICEID);
result = new IllegalArgumentException();
}
};
//act
testMethod.invoke(STANDARD_DEVICEID, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP);
}
Aggregations