use of com.microsoft.azure.sdk.iot.device.ProxySettings in project azure-iot-sdk-java by Azure.
the class ProxySettingsTest method getHostnameGetsHostnameFromAddress.
@Test
public void getHostnameGetsHostnameFromAddress() {
// arrange
final String expectedHostname = "127.0.0.1";
new Expectations() {
{
mockProxy.address();
result = mockInetSocketAddress;
mockInetSocketAddress.getHostName();
result = expectedHostname;
}
};
ProxySettings proxySettings = new ProxySettings(mockProxy);
// act
String actualHostname = proxySettings.getHostname();
// assert
assertEquals(expectedHostname, actualHostname);
}
use of com.microsoft.azure.sdk.iot.device.ProxySettings in project azure-iot-sdk-java by Azure.
the class ProxySettingsTest method constructorSavesProxy.
@Test
public void constructorSavesProxy() {
// act
ProxySettings proxySettings = new ProxySettings(mockProxy);
// assert
Proxy actualProxy = Deencapsulation.getField(proxySettings, "proxy");
assertEquals(mockProxy, actualProxy);
}
use of com.microsoft.azure.sdk.iot.device.ProxySettings in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method sendWritesBodyToOutputStream.
// Tests_SRS_HTTPSREQUEST_11_008: [The function shall send an HTTPS request as formatted in the constructor.]
@Test
public void sendWritesBodyToOutputStream() throws TransportException, MalformedURLException {
final HttpsMethod httpsMethod = HttpsMethod.POST;
final byte[] expectedBody = { 1, 2, 3 };
new MockUp<HttpsConnection>() {
byte[] testBody;
@Mock
public void $init(URL url, HttpsMethod method, ProxySettings proxySettings) {
}
@Mock
public void connect() {
assertThat(testBody, is(expectedBody));
}
@Mock
public void writeOutput(byte[] body) {
this.testBody = body;
}
// every method that is used must be manually mocked.
@Mock
public void setRequestHeader(String field, String value) {
}
@Mock
public void setRequestMethod(HttpsMethod method) {
}
@Mock
public byte[] readInput() {
return new byte[0];
}
@Mock
public byte[] readError() {
return new byte[0];
}
@Mock
public int getResponseStatus() {
return 0;
}
@Mock
public Map<String, List<String>> getResponseHeaders() {
return new HashMap<>();
}
};
URL mockUrl = new URL("https://www.microsoft.com");
HttpsRequest request = new HttpsRequest(mockUrl, httpsMethod, expectedBody, "");
request.send();
}
use of com.microsoft.azure.sdk.iot.device.ProxySettings in project azure-iot-sdk-java by Azure.
the class MultiplexingClientTests method sendMessagesWithProxy.
@Test
public void sendMessagesWithProxy() throws Exception {
if (testInstance.protocol != IotHubClientProtocol.AMQPS_WS) {
// only AMQPS_WS supports proxies
return;
}
Proxy testProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(testProxyHostname, testProxyPort));
ProxySettings proxySettings = new ProxySettings(testProxy, testProxyUser, testProxyPass);
// re-setup test instance to use proxy instead
testInstance.setup(DEVICE_MULTIPLEX_COUNT, MultiplexingClientOptions.builder().proxySettings(proxySettings).build(), false);
testInstance.multiplexingClient.open();
testSendingMessagesFromMultiplexedClients(testInstance.deviceClientArray);
testInstance.multiplexingClient.close();
}
use of com.microsoft.azure.sdk.iot.device.ProxySettings in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method sendSetsHeaderFieldsCorrectly.
// Tests_SRS_HTTPSREQUEST_11_008: [The function shall send an HTTPS request as formatted in the constructor.]
@Test
public void sendSetsHeaderFieldsCorrectly() throws TransportException, MalformedURLException {
final HttpsMethod expectedMethod = HttpsMethod.GET;
final byte[] body = new byte[0];
final String field0 = "test-field0";
final String value0 = "test-value0";
final String field1 = "test-field1";
final String value1 = "test-value1";
final String userAgent = "User-Agent";
final String userAgentValue = TransportUtils.USER_AGENT_STRING;
new MockUp<HttpsConnection>() {
final Map<String, String> testHeaderFields = new HashMap<>();
@Mock
public void $init(URL url, HttpsMethod method, ProxySettings proxySettings) {
}
@Mock
public void connect() {
assertThat(testHeaderFields.size(), is(4));
assertThat(testHeaderFields.get(field0), is(value0));
assertThat(testHeaderFields.get(field1), is(value1));
assertThat(testHeaderFields.get(userAgent), is(userAgentValue));
}
@Mock
public void setRequestHeader(String field, String value) {
testHeaderFields.put(field, value);
}
// every method that is used must be manually mocked.
@Mock
public void setRequestMethod(HttpsMethod method) {
}
@Mock
public void writeOutput(byte[] body) {
}
@Mock
public byte[] readInput() {
return new byte[0];
}
@Mock
public byte[] readError() {
return new byte[0];
}
@Mock
public int getResponseStatus() {
return 0;
}
@Mock
public Map<String, List<String>> getResponseHeaders() throws IOException {
return new HashMap<>();
}
};
URL mockUrl = new URL("Https://www.microsoft.com");
HttpsRequest request = new HttpsRequest(mockUrl, expectedMethod, body, userAgentValue);
request.setHeaderField(field0, value0);
request.setHeaderField(field1, value1);
request.send();
}
Aggregations