use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket in project azure-iot-sdk-java by Azure.
the class IotHubTransportPacketTest method getContextReturnsContext.
// Tests_SRS_IOTHUBTRANSPORTPACKET_11_001: [The constructor shall save the message, callback, status, startTimeMillis, and callback context.]
// Tests_SRS_IOTHUBTRANSPORTPACKET_11_004: [The function shall return the callback context given in the constructor.]
@Test
public void getContextReturnsContext() {
// arrange
final Map<String, Object> context = new HashMap<>();
final String key = "test-key";
final String value = "test-value";
context.put(key, value);
// act
IotHubTransportPacket packet = new IotHubTransportPacket(mockMsg, mockCallback, context, IotHubStatusCode.OK_EMPTY, 10, null);
Map<String, Object> testContext = (Map<String, Object>) packet.getContext();
// assert
Set<Map.Entry<String, Object>> testEntrySet = testContext.entrySet();
final Set<Map.Entry<String, Object>> expectedEntrySet = context.entrySet();
assertThat(testEntrySet, everyItem(isIn(expectedEntrySet)));
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket in project azure-iot-sdk-java by Azure.
the class IotHubTransportPacketTest method incrementRetryAttemptIncrementsByOne.
// Tests_SRS_IOTHUBTRANSPORTPACKET_34_009: [This function shall increment the saved retry attempt count by 1.]
@Test
public void incrementRetryAttemptIncrementsByOne() {
// arrange
final long expectedRetryAttempt = 1;
IotHubTransportPacket packet = new IotHubTransportPacket(mockMsg, mockCallback, new Object(), IotHubStatusCode.OK, 10, null);
Deencapsulation.setField(packet, "currentRetryAttempt", 0);
// act
packet.incrementRetryAttempt();
// assert
int actualRetryAttempt = Deencapsulation.getField(packet, "currentRetryAttempt");
assertEquals(expectedRetryAttempt, actualRetryAttempt);
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket in project azure-iot-sdk-java by Azure.
the class IotHubTransportPacketTest method setStatusSavesStatus.
// Tests_SRS_IOTHUBTRANSPORTPACKET_34_006: [This function shall save the provided status.]
@Test
public void setStatusSavesStatus() {
// arrange
IotHubStatusCode expectedStatus = IotHubStatusCode.ERROR;
IotHubTransportPacket packet = new IotHubTransportPacket(mockMsg, mockCallback, new Object(), IotHubStatusCode.MESSAGE_CANCELLED_ONCLOSE, 10, null);
// act
packet.setStatus(expectedStatus);
// assert
assertEquals(expectedStatus, packet.getStatus());
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket in project azure-iot-sdk-java by Azure.
the class IotHubTransportPacketTest method getRetryAttemptReturns.
// Tests_SRS_IOTHUBTRANSPORTPACKET_34_008: [This function shall return the saved current retry attempt.]
@Test
public void getRetryAttemptReturns() {
// arrange
final int expectedRetryAttempt = 123;
IotHubTransportPacket packet = new IotHubTransportPacket(mockMsg, mockCallback, new Object(), IotHubStatusCode.OK_EMPTY, 10, null);
Deencapsulation.setField(packet, "currentRetryAttempt", expectedRetryAttempt);
// act
long actualRetryAttempt = packet.getCurrentRetryAttempt();
// assert
assertEquals(expectedRetryAttempt, actualRetryAttempt);
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket in project azure-iot-sdk-java by Azure.
the class IotHubTransportPacketTest method getStatusReturnsStatus.
// Tests_SRS_IOTHUBTRANSPORTPACKET_11_001: [The constructor shall save the message, callback, status, startTimeMillis, and callback context.]
// Tests_SRS_IOTHUBTRANSPORTPACKET_34_005: [This function shall return the saved status.]
@Test
public void getStatusReturnsStatus() {
// arrange
final Map<String, Object> context = new HashMap<>();
IotHubStatusCode expectedStatus = IotHubStatusCode.MESSAGE_CANCELLED_ONCLOSE;
// act
IotHubTransportPacket packet = new IotHubTransportPacket(mockMsg, mockCallback, context, expectedStatus, 10, null);
IotHubEventCallback testCallback = packet.getCallback();
// assert
final IotHubEventCallback expectedCallback = mockCallback;
assertThat(testCallback, is(expectedCallback));
assertEquals(expectedStatus, packet.getStatus());
}
Aggregations