use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.
the class DeviceMethodDataTest method setResponseMessageSets.
/*
**Tests_SRS_DEVICEMETHODDATA_25_005: [**This method shall save the response message provided by the user.**]**
*/
@Test
public void setResponseMessageSets() {
// arrange
DeviceMethodData testData = new DeviceMethodData(0, "originalMessage");
// act
testData.setResponseMessage("testMessage");
// assert
String testResponse = testData.getResponseMessage();
assertEquals(testResponse, "testMessage");
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.
the class DigitalTwinClientTests method invokeRootLevelCommand.
@Test
@StandardTierHubOnlyTest
public void invokeRootLevelCommand() throws IOException {
// arrange
String commandName = "getMaxMinReport";
String commandInput = "\"" + ZonedDateTime.now(ZoneOffset.UTC).minusMinutes(5).format(DateTimeFormatter.ISO_DATE_TIME) + "\"";
String jsonStringInput = "{\"prop\":\"value\"}";
DigitalTwinInvokeCommandRequestOptions options = new DigitalTwinInvokeCommandRequestOptions();
options.setConnectTimeoutInSeconds(15);
options.setResponseTimeoutInSeconds(15);
// setup device callback
Integer deviceSuccessResponseStatus = 200;
Integer deviceFailureResponseStatus = 500;
// Device method callback
DeviceMethodCallback deviceMethodCallback = (methodName, methodData, context) -> {
String jsonRequest = new String((byte[]) methodData, StandardCharsets.UTF_8);
if (methodName.equalsIgnoreCase(commandName)) {
return new DeviceMethodData(deviceSuccessResponseStatus, jsonRequest);
} else {
return new DeviceMethodData(deviceFailureResponseStatus, jsonRequest);
}
};
// IotHub event callback
IotHubEventCallback iotHubEventCallback = (responseStatus, callbackContext) -> {
};
deviceClient.subscribeToDeviceMethod(deviceMethodCallback, commandName, iotHubEventCallback, commandName);
// act
DigitalTwinCommandResponse responseWithNoPayload = this.digitalTwinClient.invokeCommand(deviceId, commandName, null);
DigitalTwinCommandResponse responseWithJsonStringPayload = this.digitalTwinClient.invokeCommand(deviceId, commandName, jsonStringInput);
DigitalTwinCommandResponse responseWithDatePayload = this.digitalTwinClient.invokeCommand(deviceId, commandName, commandInput);
ServiceResponseWithHeaders<DigitalTwinCommandResponse, DigitalTwinInvokeCommandHeaders> datePayloadResponseWithHeaders = this.digitalTwinClient.invokeCommandWithResponse(deviceId, commandName, commandInput, options);
// assert
assertEquals(deviceSuccessResponseStatus, responseWithNoPayload.getStatus());
assertEquals("\"\"", responseWithNoPayload.getPayload());
assertEquals(deviceSuccessResponseStatus, responseWithJsonStringPayload.getStatus());
assertEquals(jsonStringInput, responseWithJsonStringPayload.getPayload());
assertEquals(deviceSuccessResponseStatus, responseWithDatePayload.getStatus());
assertEquals(commandInput, responseWithDatePayload.getPayload());
assertEquals(deviceSuccessResponseStatus, datePayloadResponseWithHeaders.body().getStatus());
assertEquals(commandInput, datePayloadResponseWithHeaders.body().getPayload());
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.
the class DeviceMethodDataTest method getResponseMessageGets.
/*
**Tests_SRS_DEVICEMETHODDATA_25_004: [**This method shall return the response message previously set.**]**
*/
@Test
public void getResponseMessageGets() {
//arrange
DeviceMethodData testData = new DeviceMethodData(0, "testMessage");
//act
String testResponse = testData.getResponseMessage();
//assert
assertEquals(testResponse, "testMessage");
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.
the class DeviceMethodDataTest method setResponseMessageSets.
/*
**Tests_SRS_DEVICEMETHODDATA_25_005: [**This method shall save the response message provided by the user.**]**
*/
@Test
public void setResponseMessageSets() {
//arrange
DeviceMethodData testData = new DeviceMethodData(0, "originalMessage");
//act
testData.setResponseMessage("testMessage");
//assert
String testResponse = testData.getResponseMessage();
assertEquals(testResponse, "testMessage");
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodData in project azure-iot-sdk-java by Azure.
the class DeviceMethodDataTest method GetStatusGets.
/*
**Tests_SRS_DEVICEMETHODDATA_25_003: [**This method shall return the status previously set.**]**
*/
@Test
public void GetStatusGets() {
//arrange
DeviceMethodData testData = new DeviceMethodData(0, "testMessage");
//act
int testStatus = testData.getStatus();
//assert
assertTrue(testStatus == 0);
}
Aggregations