use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method constructorThrowsIoExceptionIfCannotOpenConnection.
// Tests_SRS_HTTPSCONNECTION_11_002: [The constructor shall throw a TransportException if the connection was unable to be opened.]
@Test(expected = TransportException.class)
public void constructorThrowsIoExceptionIfCannotOpenConnection() throws IOException, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.PUT;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = new IOException();
}
};
new HttpsConnection(mockUrl, httpsMethod);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method connectUsesCorrectUrl.
// Tests_SRS_HTTPSCONNECTION_11_003: [The function shall send a request to the URL given in the constructor.]
@Test
public void connectUsesCorrectUrl() throws IOException, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.PUT;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.connect();
new Verifications() {
{
mockUrl.openConnection().connect();
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method readInputClosesInputStream.
// Tests_SRS_HTTPSCONNECTION_11_019: [The function shall close the input stream after it has been completely read.]
@Test
public void readInputClosesInputStream(@Mocked final InputStream mockIs) throws IOException, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.getInputStream();
result = mockIs;
mockIs.read();
result = -1;
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.connect();
conn.readInput();
new Verifications() {
{
mockIs.close();
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method readErrorFailsIfCannotAccessErrorStream.
// Tests_SRS_HTTPSCONNECTION_11_014: [The function shall throw a TransportException if the error stream could not be accessed.]
@Test(expected = TransportException.class)
public void readErrorFailsIfCannotAccessErrorStream() throws IOException, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.getErrorStream();
result = new IOException();
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.connect();
conn.readError();
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method setReadTimeoutSetsRequestTimeout.
// Tests_SRS_HTTPSCONNECTION_11_023: [The function shall set the read timeout to the given value.]
@Test
public void setReadTimeoutSetsRequestTimeout() throws IOException, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final String field = "test-field";
final String value = "test-value";
final int timeout = 1;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.setReadTimeout(timeout);
new Verifications() {
{
mockUrl.openConnection().setReadTimeout(timeout);
}
};
}
Aggregations