use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method openSucceed.
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_003: [The open shall create and store a new transport connection `HttpsIotHubConnection`.] */
@Test
public void openSucceed() {
// arrange
final HttpsIotHubConnection httpsIotHubConnection = mockConn;
HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
new NonStrictExpectations() {
{
Deencapsulation.newInstance(HttpsIotHubConnection.class, new Class[] { DeviceClientConfig.class }, mockConfig);
result = httpsIotHubConnection;
times = 1;
}
};
// act
Deencapsulation.invoke(httpsTransportManager, "open");
// assert
assertNotNull(Deencapsulation.getField(httpsTransportManager, "httpsIotHubConnection"));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method invokeMethodOnModuleSuccess.
// Tests_SRS_HTTPSTRANSPORTMANAGER_34_017: [This function shall call invokeMethod with the provided request and
// a uri in the format twins/<device id>/modules/<module id>/methods?api-version=<api_version>.]
@Test
public void invokeMethodOnModuleSuccess() throws TransportException, IOException, URISyntaxException {
// arrange
final HttpsTransportManager transportManager = new HttpsTransportManager(mockConfig);
final String expectedDeviceId = "myDevice";
final String expectedModuleId = "myModule";
final String expectedSenderDeviceId = "mySenderDevice";
final String expectedSenderModuleId = "mySenderModule";
final String expectedMethodRequestJson = "someJson";
final String expectedResponseBody = "some body";
// assert
new Expectations(HttpsTransportManager.class) {
{
mockedMethodRequest.toJson();
result = expectedMethodRequestJson;
new IotHubTransportMessage(expectedMethodRequestJson);
result = mockedTransportMessage;
mockedTransportMessage.setIotHubMethod(IotHubMethod.POST);
mockedTransportMessage.setUriPath("/twins/" + expectedDeviceId + "/modules/" + expectedModuleId + "/methods");
mockConfig.getDeviceId();
result = expectedSenderDeviceId;
mockConfig.getModuleId();
result = expectedSenderModuleId;
transportManager.send(mockedTransportMessage, (Map) any);
result = mockResponseMessage;
mockResponseMessage.getStatus();
result = IotHubStatusCode.OK_EMPTY;
mockResponseMessage.getBytes();
result = expectedResponseBody.getBytes(StandardCharsets.UTF_8);
new MethodResult(expectedResponseBody);
}
};
// act
transportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, expectedModuleId);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method invokeMethodOnDeviceThrowsIfIotHubRespondsWithErrorCode.
// Tests_SRS_HTTPSTRANSPORTMANAGER_34_026 [If the http response contains an error code, this function shall throw the associated exception.]
@Test(expected = HubOrDeviceIdNotFoundException.class)
public void invokeMethodOnDeviceThrowsIfIotHubRespondsWithErrorCode() throws TransportException, IOException, URISyntaxException {
// arrange
final HttpsTransportManager transportManager = new HttpsTransportManager(mockConfig);
final String expectedDeviceId = "myDevice";
final String expectedSenderDeviceId = "mySenderDevice";
final String expectedSenderModuleId = "mySenderModule";
final String expectedMethodRequestJson = "someJson";
final String expectedResponseBody = "some body";
// assert
new Expectations(HttpsTransportManager.class) {
{
mockedMethodRequest.toJson();
result = expectedMethodRequestJson;
new IotHubTransportMessage(expectedMethodRequestJson);
result = mockedTransportMessage;
mockedTransportMessage.setIotHubMethod(IotHubMethod.POST);
mockedTransportMessage.setUriPath("/twins/" + expectedDeviceId + "/methods");
mockConfig.getDeviceId();
result = expectedSenderDeviceId;
mockConfig.getModuleId();
result = expectedSenderModuleId;
transportManager.send(mockedTransportMessage, (Map) any);
result = mockResponseMessage;
mockResponseMessage.getStatus();
result = IotHubStatusCode.HUB_OR_DEVICE_ID_NOT_FOUND;
mockResponseMessage.getBytes();
result = expectedResponseBody.getBytes(StandardCharsets.UTF_8);
}
};
// act
transportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, "");
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method openWithTopicsSucceed.
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_004: [The open shall create and store a new transport connection `HttpsIotHubConnection`.] */
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_005: [The open shall ignore the parameter `topics`.] */
@Test
public void openWithTopicsSucceed() {
// arrange
final HttpsIotHubConnection httpsIotHubConnection = mockConn;
final String[] topics = new String[] { "a", "b" };
HttpsTransportManager httpsTransportManager = Deencapsulation.newInstance(HttpsTransportManager.class, new Class[] { DeviceClientConfig.class }, mockConfig);
new NonStrictExpectations() {
{
Deencapsulation.newInstance(HttpsIotHubConnection.class, new Class[] { DeviceClientConfig.class }, mockConfig);
result = httpsIotHubConnection;
times = 1;
}
};
// act
Deencapsulation.invoke(httpsTransportManager, "open", new Class<?>[] { String[].class }, (Object) topics);
// assert
assertNotNull(Deencapsulation.getField(httpsTransportManager, "httpsIotHubConnection"));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.
the class HttpsTransportManagerTest method sendSendHttpsMessageThrows.
/* Tests_SRS_HTTPSTRANSPORTMANAGER_21_014: [If `sendHttpsMessage` failed, the send shall bypass the exception.] */
@Test(expected = IOException.class)
public void sendSendHttpsMessageThrows() 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 = new IOException();
}
};
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>());
}
Aggregations