Search in sources :

Example 6 with IotHubTransportPacket

use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket in project azure-iot-sdk-java by Azure.

the class IotHubTransportPacketTest method getCallbackReturnsCallback.

// Tests_SRS_IOTHUBTRANSPORTPACKET_11_001: [The constructor shall save the message, callback, status, startTimeMillis, and callback context.]
// Tests_SRS_IOTHUBTRANSPORTPACKET_11_003: [The function shall return the event callback given in the constructor.]
@Test
public void getCallbackReturnsCallback() {
    // 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)

Example 7 with IotHubTransportPacket

use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket in project azure-iot-sdk-java by Azure.

the class IotHubTransportPacketTest method getMessageReturnsMessage.

// Tests_SRS_IOTHUBTRANSPORTPACKET_11_001: [The constructor shall save the message, callback, status, startTimeMillis, and callback context.]
// Tests_SRS_IOTHUBTRANSPORTPACKET_11_002: [The function shall return the message given in the constructor.]
@Test
public void getMessageReturnsMessage() {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    // act
    IotHubTransportPacket packet = new IotHubTransportPacket(mockMsg, mockCallback, context, IotHubStatusCode.OK_EMPTY, 10, null);
    Message testMsg = packet.getMessage();
    // assert
    final Message expectedMsg = mockMsg;
    assertThat(testMsg, is(expectedMsg));
}
Also used : IotHubTransportPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket) Message(com.microsoft.azure.sdk.iot.device.Message) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with IotHubTransportPacket

use of com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket in project azure-iot-sdk-java by Azure.

the class IotHubTransportPacketTest method getStartTimeMillisReturnsStartTime.

// Tests_SRS_IOTHUBTRANSPORTPACKET_11_001: [The constructor shall save the message, callback, status, startTimeMillis, and callback context.]
// Tests_SRS_IOTHUBTRANSPORTPACKET_34_007: [This function shall return the saved startTimeMillis.]
@Test
public void getStartTimeMillisReturnsStartTime() {
    // arrange
    long expectedStartTime = 1230;
    // act
    IotHubTransportPacket packet = new IotHubTransportPacket(mockMsg, mockCallback, new Object(), IotHubStatusCode.OK_EMPTY, expectedStartTime, null);
    long actualStartTime = packet.getStartTimeMillis();
    // assert
    assertEquals(expectedStartTime, actualStartTime);
}
Also used : IotHubTransportPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportPacket) 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