use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method sendFileUploadMessageSuccessWithModule.
// 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 sendFileUploadMessageSuccessWithModule() throws TransportException, IOException, URISyntaxException {
// arrange
final HttpsTransportManager transportManager = new HttpsTransportManager(mockConfig);
final String expectedDeviceId = "myDevice";
final String expectedModuleId = "myModule";
// assert
new Expectations(HttpsTransportManager.class) {
{
mockConfig.getDeviceId();
result = expectedDeviceId;
mockConfig.getModuleId();
result = expectedModuleId;
mockedTransportMessage.setUriPath("/devices/" + expectedDeviceId + "/modules/" + expectedModuleId + "/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 sendFileUploadNotificationMessageSuccessWithModule.
// Tests_SRS_HTTPSTRANSPORTMANAGER_34_029 [This function shall set the uri path of the provided message to the
// format devices/<deviceid>/modules/<moduleid>/files/notifications if a moduleId is present or
// devices/<deviceid>/modules/<moduleid>/files/notifications otherwise, and then send it.]
@Test
public void sendFileUploadNotificationMessageSuccessWithModule() throws TransportException, IOException, URISyntaxException {
// arrange
final HttpsTransportManager transportManager = new HttpsTransportManager(mockConfig);
final String expectedDeviceId = "myDevice";
final String expectedModuleId = "myModule";
// assert
new Expectations(HttpsTransportManager.class) {
{
mockConfig.getDeviceId();
result = expectedDeviceId;
mockConfig.getModuleId();
result = expectedModuleId;
mockedTransportMessage.setUriPath("/devices/" + expectedDeviceId + "/modules/" + expectedModuleId + "/files/notifications");
transportManager.send(mockedTransportMessage, (Map) any);
result = mockResponseMessage;
}
};
// act
transportManager.sendFileUploadNotification(mockedTransportMessage);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method sendParseHttpsJsonMessageThrows.
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_008: [If send failed to parse the message, it shall bypass the exception.] */
@Test(expected = IllegalArgumentException.class)
public void sendParseHttpsJsonMessageThrows() {
// 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 = new IllegalArgumentException();
}
};
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 sendSucceed.
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_012: [The send shall set the httpsPath with the uriPath in the message.] */
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_013: [The send shall call `sendHttpsMessage` from `HttpsIotHubConnection` to send the message.] */
@Test
public void sendSucceed() throws IOException, TransportException {
// 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 = IotHubMethod.POST;
mockTransportMsg.getUriPath();
result = uriPath;
httpsIotHubConnection.sendHttpsMessage(mockHttpsMessage, (HttpsMethod) any, (String) any, (Map) any);
result = mockResponseMessage;
}
};
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>());
// assert
new Verifications() {
{
httpsIotHubConnection.sendHttpsMessage(mockHttpsMessage, HttpsMethod.POST, uriPath, (Map) any);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method sendMethodPOSTSucceed.
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_010: [If the IotHubMethod is `POST`, the send shall set the httpsMethod as `POST`.] */
@Test
public void sendMethodPOSTSucceed() throws IOException, TransportException {
// 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 = IotHubMethod.POST;
mockTransportMsg.getUriPath();
result = uriPath;
httpsIotHubConnection.sendHttpsMessage(mockHttpsMessage, (HttpsMethod) any, (String) any, (Map) any);
result = mockResponseMessage;
}
};
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>());
// assert
new Verifications() {
{
httpsIotHubConnection.sendHttpsMessage(mockHttpsMessage, HttpsMethod.POST, (String) any, (Map) any);
times = 1;
}
};
}
Aggregations