use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method readErrorClosesErrorStream.
// Tests_SRS_HTTPSCONNECTION_11_020: [The function shall close the error stream after it has been completely read.]
@Test
public void readErrorClosesErrorStream(@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.getErrorStream();
result = mockIs;
mockIs.read();
result = -1;
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.connect();
conn.readError();
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 readErrorCompletelyReadsErrorStream.
// Tests_SRS_HTTPSCONNECTION_11_013: [The function shall read from the error stream and return the response.]
@Test
public void readErrorCompletelyReadsErrorStream(@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.getErrorStream();
result = mockIs;
mockIs.read();
returns(1, 2, 3, -1);
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.connect();
byte[] testError = conn.readError();
byte[] expectedError = { 1, 2, 3 };
assertThat(testError, is(expectedError));
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method constructorRejectsNonHttpsUrl.
// Tests_SRS_HTTPSCONNECTION_11_022: [If the URI given does not use the HTTPS or HTTP protocol, the constructor shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void constructorRejectsNonHttpsUrl() throws IOException, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.PUT;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "unix";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
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 setRequestHeaderSetsRequestHeader.
// Tests_SRS_HTTPSCONNECTION_11_008: [The function shall set the given request header field.]
@Test
public void setRequestHeaderSetsRequestHeader() throws IOException, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final String field = "test-field";
final String value = "test-value";
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.setRequestHeader(field, value);
new Verifications() {
{
mockUrl.openConnection().setRequestProperty(field, value);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method getResponseStatusFailsIfDidNotReceiveResponse.
// Tests_SRS_HTTPSCONNECTION_11_016: [The function shall throw a TransportException if no response was received.]
@Test(expected = TransportException.class)
public void getResponseStatusFailsIfDidNotReceiveResponse(@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.getResponseCode();
result = new IOException();
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.connect();
conn.getResponseStatus();
}
Aggregations