Search in sources :

Example 1 with ResponseMessage

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

the class ResponseMessageTest method getStatusReturnStatus.

/* Tests_SRS_RESPONSEMESSAGE_21_005: [The getStatus shall return the stored status.] */
@Test
public void getStatusReturnStatus() {
    // arrange
    final byte[] body = { 'A', 'B', 'C', '\0' };
    final IotHubStatusCode status = IotHubStatusCode.OK;
    // act
    ResponseMessage msg = new ResponseMessage(body, status);
    // assert
    assertEquals(status, Deencapsulation.invoke(msg, "getStatus"));
}
Also used : IotHubStatusCode(com.microsoft.azure.sdk.iot.device.IotHubStatusCode) ResponseMessage(com.microsoft.azure.sdk.iot.device.ResponseMessage) Test(org.junit.Test)

Example 2 with ResponseMessage

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

the class ResponseMessageTest method constructorNullStatusThrows.

/* Tests_SRS_RESPONSEMESSAGE_21_004: [If the message status is null, the constructor shall throw an IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void constructorNullStatusThrows() {
    // arrange
    final byte[] body = { 'A', 'B', 'C', '\0' };
    final IotHubStatusCode status = null;
    // act
    ResponseMessage msg = new ResponseMessage(body, status);
}
Also used : IotHubStatusCode(com.microsoft.azure.sdk.iot.device.IotHubStatusCode) ResponseMessage(com.microsoft.azure.sdk.iot.device.ResponseMessage) Test(org.junit.Test)

Example 3 with ResponseMessage

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

the class IotHubCallbackPacketTest method getResponseCallbackReturnsNull.

// Tests_SRS_IOTHUBCALLBACKPACKET_11_001: [The constructor shall save the status, eventCallback, and callback context.]
// Tests_SRS_IOTHUBCALLBACKPACKET_21_007: [The constructor shall set message and responseCallback as null.]
@Test
public void getResponseCallbackReturnsNull() {
    final IotHubStatusCode status = IotHubStatusCode.HUB_OR_DEVICE_ID_NOT_FOUND;
    final Map<String, Object> context = new HashMap<>();
    IotHubCallbackPacket packet = new IotHubCallbackPacket(status, mockEventCallback, context);
    IotHubResponseCallback testCallback = packet.getResponseCallback();
    ResponseMessage testMessage = packet.getResponseMessage();
    assertNull(testCallback);
    assertNull(testMessage);
}
Also used : IotHubStatusCode(com.microsoft.azure.sdk.iot.device.IotHubStatusCode) HashMap(java.util.HashMap) IotHubCallbackPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket) IotHubResponseCallback(com.microsoft.azure.sdk.iot.device.IotHubResponseCallback) ResponseMessage(com.microsoft.azure.sdk.iot.device.ResponseMessage) Test(org.junit.Test)

Example 4 with ResponseMessage

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

the class IotHubCallbackPacketTest method getResponseCallbackReturnsCallback.

// Tests_SRS_IOTHUBCALLBACKPACKET_21_006: [The constructor shall save the responseMessage, responseCallback, and callback context.]
// Tests_SRS_IOTHUBCALLBACKPACKET_21_005: [The getResponseCallback shall return the responseCallback given in the constructor.]
@Test
public void getResponseCallbackReturnsCallback() {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    // act
    IotHubCallbackPacket packet = new IotHubCallbackPacket(mockMessage, mockResponseCallback, context);
    // assert
    IotHubResponseCallback testCallback = packet.getResponseCallback();
    assertThat(testCallback, is(mockResponseCallback));
    ResponseMessage testMessage = packet.getResponseMessage();
    assertThat(testMessage, is(mockMessage));
    Map<String, Object> testContext = (Map<String, Object>) packet.getContext();
    Set<Map.Entry<String, Object>> testEntrySet = testContext.entrySet();
    final Set<Map.Entry<String, Object>> expectedEntrySet = context.entrySet();
    assertThat(testEntrySet, everyItem(isIn(expectedEntrySet)));
}
Also used : HashMap(java.util.HashMap) IotHubCallbackPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket) IotHubResponseCallback(com.microsoft.azure.sdk.iot.device.IotHubResponseCallback) ResponseMessage(com.microsoft.azure.sdk.iot.device.ResponseMessage) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with ResponseMessage

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

the class FileUploadTask method sendNotification.

// Public method
@SuppressWarnings("UnusedReturnValue")
public IotHubStatusCode sendNotification(FileUploadCompletionNotification fileUploadStatusParser) throws IOException {
    IotHubTransportMessage message = new IotHubTransportMessage(fileUploadStatusParser.toJson());
    message.setIotHubMethod(IotHubMethod.POST);
    httpsTransportManager.open();
    ResponseMessage responseMessage = httpsTransportManager.sendFileUploadNotification(message);
    httpsTransportManager.close();
    validateServiceStatusCode(responseMessage, "Failed to complete the file upload notification");
    return responseMessage.getStatus();
}
Also used : ResponseMessage(com.microsoft.azure.sdk.iot.device.ResponseMessage) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)

Aggregations

ResponseMessage (com.microsoft.azure.sdk.iot.device.ResponseMessage)12 Test (org.junit.Test)10 IotHubStatusCode (com.microsoft.azure.sdk.iot.device.IotHubStatusCode)9 IotHubResponseCallback (com.microsoft.azure.sdk.iot.device.IotHubResponseCallback)2 IotHubCallbackPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket)2 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)2 HashMap (java.util.HashMap)2 FileUploadSasUriResponse (com.microsoft.azure.sdk.iot.deps.serializer.FileUploadSasUriResponse)1 IOException (java.io.IOException)1 Map (java.util.Map)1