Search in sources :

Example 6 with ResponseMessage

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

the class FileUploadTask method getFileUploadSasUri.

public FileUploadSasUriResponse getFileUploadSasUri(FileUploadSasUriRequest request) throws IOException {
    IotHubTransportMessage message = new IotHubTransportMessage(request.toJson());
    message.setIotHubMethod(IotHubMethod.POST);
    ResponseMessage responseMessage;
    httpsTransportManager.open();
    responseMessage = httpsTransportManager.getFileUploadSasUri(message);
    httpsTransportManager.close();
    String responseMessagePayload = validateServiceStatusCode(responseMessage, "Failed to get the file upload SAS URI");
    if (responseMessagePayload == null || responseMessagePayload.isEmpty()) {
        throw new IOException("Sas URI response message had no payload");
    }
    return new FileUploadSasUriResponse(responseMessagePayload);
}
Also used : ResponseMessage(com.microsoft.azure.sdk.iot.device.ResponseMessage) IOException(java.io.IOException) FileUploadSasUriResponse(com.microsoft.azure.sdk.iot.deps.serializer.FileUploadSasUriResponse) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)

Example 7 with ResponseMessage

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

the class ResponseMessageTest method constructorNullBodyThrows.

/* Tests_SRS_RESPONSEMESSAGE_21_002: [If the message body is null, the constructor shall throw an IllegalArgumentException thrown by base constructor.] */
@Test(expected = IllegalArgumentException.class)
public void constructorNullBodyThrows() {
    // arrange
    final byte[] body = null;
    final IotHubStatusCode status = IotHubStatusCode.OK;
    // 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 8 with ResponseMessage

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

the class ResponseMessageTest method constructorSetsRequiredPrivateMembers.

/* Tests_SRS_RESPONSEMESSAGE_21_001: [The constructor shall save the message body by calling super with the body as parameter.] */
/* Tests_SRS_RESPONSEMESSAGE_21_003: [The constructor shall save the status.] */
@Test
public void constructorSetsRequiredPrivateMembers() {
    // arrange
    final byte[] body = { 'A', 'B', 'C', '\0' };
    final IotHubStatusCode status = IotHubStatusCode.OK;
    // act
    ResponseMessage msg = new ResponseMessage(body, status);
    // assert
    assertEquals(status, Deencapsulation.getField(msg, "status"));
    assertEquals(body, Deencapsulation.getField(msg, "body"));
}
Also used : IotHubStatusCode(com.microsoft.azure.sdk.iot.device.IotHubStatusCode) ResponseMessage(com.microsoft.azure.sdk.iot.device.ResponseMessage) Test(org.junit.Test)

Example 9 with ResponseMessage

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

the class ResponseMessageTest method constructorNullBodyThrows.

/* Tests_SRS_RESPONSEMESSAGE_21_002: [If the message body is null, the constructor shall throw an IllegalArgumentException thrown by base constructor.] */
@Test(expected = IllegalArgumentException.class)
public void constructorNullBodyThrows() {
    // arrange
    final byte[] body = null;
    final IotHubStatusCode status = IotHubStatusCode.OK;
    // 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 10 with ResponseMessage

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

the class ResponseMessageTest method constructorSetsRequiredPrivateMembers.

/* Tests_SRS_RESPONSEMESSAGE_21_001: [The constructor shall save the message body by calling super with the body as parameter.] */
/* Tests_SRS_RESPONSEMESSAGE_21_003: [The constructor shall save the status.] */
@Test
public void constructorSetsRequiredPrivateMembers() {
    // arrange
    final byte[] body = { 'A', 'B', 'C', '\0' };
    final IotHubStatusCode status = IotHubStatusCode.OK;
    // act
    ResponseMessage msg = new ResponseMessage(body, status);
    // assert
    assertEquals(status, Deencapsulation.getField(msg, "status"));
    assertEquals(body, Deencapsulation.getField(msg, "body"));
}
Also used : IotHubStatusCode(com.microsoft.azure.sdk.iot.device.IotHubStatusCode) ResponseMessage(com.microsoft.azure.sdk.iot.device.ResponseMessage) Test(org.junit.Test)

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