use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method constructor_throwOnImproperCS_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_throwOnImproperCS_failed() throws Exception {
//arrange
new NonStrictExpectations() {
{
iotHubConnectionString.createConnectionString(STANDARD_CONNECTIONSTRING);
result = new IllegalArgumentException();
}
};
//act
DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method constructor_createMethod_succeed.
/* Tests_SRS_DEVICEMETHOD_21_002: [The constructor shall create an IotHubConnectionStringBuilder object from the given connection string.] */
/* Tests_SRS_DEVICEMETHOD_21_003: [The constructor shall create a new DeviceMethod instance and return it.] */
@Test
public void constructor_createMethod_succeed(@Mocked final IotHubConnectionStringBuilder mockedConnectionStringBuilder) throws Exception {
//arrange
//act
DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
//assert
assertNotNull(testMethod);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod in project azure-iot-sdk-java by Azure.
the class DeviceMethodTest method constructor_throwOnEmptyCS_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_throwOnEmptyCS_failed() throws Exception {
//arrange
final String connectionString = "";
//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_throwOnCreateMethodResponse_failed.
/* Tests_SRS_DEVICEMETHOD_21_013: [The invoke shall deserialize the payload using the `serializer.MethodParser`.] */
@Test(expected = IllegalArgumentException.class)
public void invoke_throwOnCreateMethodResponse_failed(@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;
}
};
new MockUp<MethodParser>() {
@Mock
void $init(String name, Long responseTimeoutInSeconds, Long connectTimeoutInSeconds, Object payload) throws IllegalArgumentException {
}
@Mock
void $init() {
}
@Mock
String toJson() {
return STANDARD_JSON;
}
@Mock
void fromJson(String json) {
throw 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_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;
}
};
}
Aggregations