use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method sendInvalidMethodThrows.
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_011: [If the IotHubMethod is not `GET` or `POST`, the send shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void sendInvalidMethodThrows() {
// arrange
final HttpsIotHubConnection httpsIotHubConnection = mockConn;
final String uriPath = "/files/notifications";
new NonStrictExpectations() {
{
Deencapsulation.newInstance(HttpsIotHubConnection.class, new Class[] { DeviceClientConfig.class }, mockConfig);
result = httpsIotHubConnection;
Deencapsulation.invoke(HttpsSingleMessage.class, "parseHttpsJsonMessage", new Class[] { Message.class }, mockTransportMsg);
result = mockHttpsMessage;
mockTransportMsg.getIotHubMethod();
result = null;
}
};
HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
Deencapsulation.invoke(httpsTransportManager, "open");
// act
Deencapsulation.invoke(httpsTransportManager, "send", new Class[] { IotHubTransportMessage.class, Map.class }, mockTransportMsg, new HashMap<String, String>());
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method invokeMethodThrowsForNullUri.
// Tests_SRS_HTTPSTRANSPORTMANAGER_34_020: [If the provided uri is null or empty, this function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void invokeMethodThrowsForNullUri() throws TransportException, IOException, URISyntaxException {
// arrange
final HttpsTransportManager transportManager = new HttpsTransportManager(mockConfig);
final String expectedDeviceId = "myDevice";
// act
Deencapsulation.invoke(transportManager, "invokeMethod", new Class[] { MethodRequest.class, URI.class }, mockedMethodRequest, (URI) null);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method receiveReceiveMessageThrows.
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_016: [If `receiveMessage` failed, the receive shall bypass the exception.] */
@Test(expected = IOException.class)
public void receiveReceiveMessageThrows() throws TransportException {
// arrange
final HttpsIotHubConnection httpsIotHubConnection = mockConn;
final String uriPath = "/files/notifications";
new NonStrictExpectations() {
{
Deencapsulation.newInstance(HttpsIotHubConnection.class, new Class[] { DeviceClientConfig.class }, mockConfig);
result = httpsIotHubConnection;
httpsIotHubConnection.receiveMessage();
result = new IOException();
}
};
HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
Deencapsulation.invoke(httpsTransportManager, "open");
// act
Deencapsulation.invoke(httpsTransportManager, "receive");
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method sendFileUploadMessageSuccessWithoutModule.
// Tests_SRS_HTTPSTRANSPORTMANAGER_34_028 [This function shall set the uri path of the provided message to the
// format devices/<deviceid>/modules/<moduleid>/files if a moduleId is present or
// devices/<deviceid>/modules/<moduleid>/files otherwise, and then send it.]
@Test
public void sendFileUploadMessageSuccessWithoutModule() throws TransportException, IOException, URISyntaxException {
// arrange
final HttpsTransportManager transportManager = new HttpsTransportManager(mockConfig);
final String expectedDeviceId = "myDevice";
// assert
new Expectations(HttpsTransportManager.class) {
{
mockConfig.getDeviceId();
result = expectedDeviceId;
mockConfig.getModuleId();
result = "";
mockedTransportMessage.setUriPath("/devices/" + expectedDeviceId + "/files");
transportManager.send(mockedTransportMessage, (Map) any);
result = mockResponseMessage;
}
};
// act
transportManager.getFileUploadSasUri(mockedTransportMessage);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method invokeMethodThrowsForNullRequest.
// Tests_SRS_HTTPSTRANSPORTMANAGER_34_019: [If the provided method request is null, this function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void invokeMethodThrowsForNullRequest() throws TransportException, IOException, URISyntaxException {
// arrange
final HttpsTransportManager transportManager = new HttpsTransportManager(mockConfig);
final String expectedDeviceId = "myDevice";
// act
transportManager.invokeMethod(null, expectedDeviceId, "");
}
Aggregations