Search in sources :

Example 1 with IotHubTransportPacket

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)));
}
Also used : IotHubTransportPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with IotHubTransportPacket

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);
}
Also used : IotHubTransportPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket) Test(org.junit.Test)

Example 3 with IotHubTransportPacket

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());
}
Also used : IotHubStatusCode(com.microsoft.azure.sdk.iot.device.IotHubStatusCode) IotHubTransportPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket) Test(org.junit.Test)

Example 4 with IotHubTransportPacket

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);
}
Also used : IotHubTransportPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket) Test(org.junit.Test)

Example 5 with IotHubTransportPacket

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());
}
Also used : IotHubEventCallback(com.microsoft.azure.sdk.iot.device.IotHubEventCallback) IotHubStatusCode(com.microsoft.azure.sdk.iot.device.IotHubStatusCode) IotHubTransportPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

IotHubTransportPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)4 IotHubStatusCode (com.microsoft.azure.sdk.iot.device.IotHubStatusCode)3 IotHubEventCallback (com.microsoft.azure.sdk.iot.device.IotHubEventCallback)2 Message (com.microsoft.azure.sdk.iot.device.Message)1 Map (java.util.Map)1