use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class MqttDeviceTwinTest method sendDoesNotThrowsIoExceptionIfMessageIsEmpty.
@Test
public void sendDoesNotThrowsIoExceptionIfMessageIsEmpty(@Mocked final Mqtt mockMqtt, @Mocked final IotHubTransportMessage mockMessage) throws TransportException {
final byte[] actualPayload = {};
final String expectedTopic = "$iothub/twin/PATCH/properties/reported/?$rid=" + mockReqId;
try {
// arrange
MqttDeviceTwin testTwin = new MqttDeviceTwin("", mockedConnectOptions, new HashMap<Integer, Message>(), new ConcurrentLinkedQueue<Pair<String, byte[]>>());
testTwin.start();
new NonStrictExpectations() {
{
mockMessage.getBytes();
result = actualPayload;
mockMessage.getMessageType();
result = MessageType.DEVICE_TWIN;
mockMessage.getDeviceOperationType();
result = DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_REQUEST;
mockMessage.getRequestId();
result = mockReqId;
}
};
// act
testTwin.send(mockMessage);
} finally {
// assert
new Verifications() {
{
mockMessage.getBytes();
times = 1;
Deencapsulation.invoke(mockMqtt, "publish", expectedTopic, mockMessage);
times = 1;
}
};
}
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class IotHubTransportMessageTest method getVersionGetsTheVersion.
/*
**Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_005: [**The function shall return the value of the version either set by the setter or the default (null) if unset so far.**]**
*/
@Test
public void getVersionGetsTheVersion() {
// arrange
String versionStr = "abcdefg";
byte[] data = new byte[1];
MessageType messageType = MessageType.DEVICE_TWIN;
IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
iotHubTransportMessage.setVersion(versionStr);
// act
String version = iotHubTransportMessage.getVersion();
// assert
assertEquals(versionStr, version);
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class IotHubTransportMessageTest method setRequestIdSetsTheRequestId.
/*
**Tests_SRS_IOTHUBTRANSPORTMESSAGE_12_006: [**The function shall save the request id.**]**
*/
@Test
public void setRequestIdSetsTheRequestId() {
// arrange
String requestIdStr = "abcdefg";
byte[] data = new byte[1];
MessageType messageType = MessageType.DEVICE_TWIN;
IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(data, messageType);
// act
iotHubTransportMessage.setRequestId(requestIdStr);
// assert
assertEquals(requestIdStr, iotHubTransportMessage.getRequestId());
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class IotHubTransportMessageTest method setGetUriPathSuccess.
/* Tests_SRS_IOTHUBTRANSPORTMESSAGE_21_003: [The setUriPath shall store the uriPath. This function do not evaluates this parameter.] */
/* Tests_SRS_IOTHUBTRANSPORTMESSAGE_21_005: [The getUriPath shall return the stored uriPath.] */
@Test
public void setGetUriPathSuccess() {
// arrange
String uriPath = "valid/uri";
IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage("This is a valid body");
// act
iotHubTransportMessage.setUriPath(uriPath);
// assert
assertEquals(uriPath, iotHubTransportMessage.getUriPath());
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage in project azure-iot-sdk-java by Azure.
the class IotHubTransportMessageTest method constructorSuccess.
/* Tests_SRS_IOTHUBTRANSPORTMESSAGE_21_001: [The constructor shall call the supper class with the body. This function do not evaluates this parameter.] */
@Test
public void constructorSuccess() {
// arrange
String body = "This is a valid body";
// act
IotHubTransportMessage iotHubTransportMessage = new IotHubTransportMessage(body);
// assert
assertEquals(body, new String(iotHubTransportMessage.getBytes(), StandardCharsets.UTF_8));
}
Aggregations