use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorSetsHttpsMethodCorrectly.
// Tests_SRS_HTTPSREQUEST_11_004: [The function shall use the given HTTPS method (i.e. GET) as the request method.]
@Test
public void constructorSetsHttpsMethodCorrectly(@Mocked final HttpsConnection mockConn) throws TransportException, MalformedURLException {
final HttpsMethod httpsMethod = HttpsMethod.GET;
final byte[] body = new byte[0];
final URL mockUrl = new URL("https://www.microsoft.com");
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, body, "");
request.send();
new Verifications() {
{
new HttpsConnection((URL) any, httpsMethod, null, true);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method connectStreamsRequestBody.
// Tests_SRS_HTTPSCONNECTION_11_004: [The function shall stream the request body, if present, through the connection.]
// Tests_SRS_HTTPSCONNECTION_11_009: [The function shall save the body to be sent with the request.]
@Test
public void connectStreamsRequestBody() throws IOException, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.PUT;
byte[] body = { 1, 2, 3 };
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
conn.writeOutput(body);
body[0] = 5;
conn.connect();
final byte[] expectedBody = { 1, 2, 3 };
new Verifications() {
{
mockUrl.openConnection().getOutputStream().write(expectedBody);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method setSSLContextThrowsOnNullContext.
// Tests_SRS_HTTPSCONNECTION_25_025: [The function shall throw IllegalArgumentException if the context is null value.**]**
@Test(expected = IllegalArgumentException.class)
public void setSSLContextThrowsOnNullContext(@Mocked final SSLContext mockedContext) throws IOException, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final String field = "test-field";
final String value = "test-value";
final int timeout = 1;
new Expectations() {
{
mockUrl.getProtocol();
result = "https";
}
};
final HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod);
Deencapsulation.invoke(conn, "setSSLContext", SSLContext.class);
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method setRequestMethodSetsRequestMethod.
// Tests_SRS_HTTPSCONNECTION_11_006: [The function shall set the request method.]
@Test
public void setRequestMethodSetsRequestMethod() 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.setRequestMethod(httpsMethod);
new Verifications() {
{
mockUrlConn.setRequestMethod(httpsMethod.name());
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection in project azure-iot-sdk-java by Azure.
the class HttpsConnectionTest method setSSLContextSetsContextWithProxy.
@Test
public void setSSLContextSetsContextWithProxy(@Mocked final SSLContext mockedContext, @Mocked final SSLSocketFactory mockedSocketFactory, @Mocked final HttpProxySocketFactory mockedHttpProxySocketFactory) throws IOException, TransportException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockedContext.getSocketFactory();
result = mockedSocketFactory;
new HttpProxySocketFactory(mockedSocketFactory, mockProxySettings);
result = mockedHttpProxySocketFactory;
}
};
final HttpsConnection conn = new HttpsConnection(mockUrl, httpsMethod, mockProxySettings);
Deencapsulation.invoke(conn, "setSSLContext", mockedContext);
new Verifications() {
{
mockUrlConn.setSSLSocketFactory(mockedHttpProxySocketFactory);
times = 1;
}
};
}
Aggregations