summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-12-11 10:23:42 +0000
committerGerrit Code Review <gerrit@onap.org>2019-12-11 10:23:42 +0000
commitbfd3b59b7caef3c65d306727fc6fe25a85e68ca2 (patch)
tree5136723ddfe1d21530349a2c8ebac29f0fadffcd
parent2ed2a1a61fe0bccf215a8dc9cecbf4fdf55fd454 (diff)
parent43b5c48cbe4c9f6bbc6cc118bd00dba34da927ef (diff)
Merge "SyncRestClient for Http/s ServerTest to use 127.0.0.1 address"
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpServerTest.java38
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpsServerTest.java23
2 files changed, 41 insertions, 20 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpServerTest.java b/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpServerTest.java
index 5a2eb59d2..bf33eff94 100644
--- a/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpServerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpServerTest.java
@@ -42,10 +42,13 @@ import com.xebialabs.restito.semantics.Condition;
import com.xebialabs.restito.server.StubServer;
import io.joshworks.restclient.http.HttpResponse;
import io.joshworks.restclient.http.JsonNode;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Map;
import org.glassfish.grizzly.http.Method;
import org.glassfish.grizzly.http.util.HttpStatus;
+import org.jetbrains.annotations.NotNull;
import org.onap.vid.utils.Logging;
import org.springframework.http.HttpMethod;
import org.testng.annotations.AfterMethod;
@@ -76,11 +79,20 @@ public class SyncRestClientForHttpServerTest {
syncRestClient.destroy();
}
+ @NotNull
+ private String getTestUrl(String protocol) {
+ try {
+ return new URI(protocol, null, "127.0.0.1" , stubServer.getPort(), "/test", null, null).toString();
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
@Test
public void testJsonResponseFromGet() throws JsonProcessingException {
// given
stubGetCall();
- String url = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String url = getTestUrl("http");
// when
HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient
.get(url, Collections.emptyMap(), Collections.emptyMap());
@@ -97,7 +109,7 @@ public class SyncRestClientForHttpServerTest {
public void testObjectResponseFromGet() throws JsonProcessingException {
// given
stubGetCall();
- String url = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String url = getTestUrl("http");
// when
HttpResponse<SyncRestClientModel.TestModel> testModelHttpResponse = syncRestClient
.get(url, Collections.emptyMap(), Collections.emptyMap(), SyncRestClientModel.TestModel.class);
@@ -114,7 +126,7 @@ public class SyncRestClientForHttpServerTest {
public void testJsonResponseFromPost() throws JsonProcessingException {
// given
stubPostCall();
- String url = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String url = getTestUrl("http");
// when
HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient.post(url, Collections.emptyMap(), testObject);
// then
@@ -130,7 +142,7 @@ public class SyncRestClientForHttpServerTest {
public void test404JsonResponseFromPost() throws JsonProcessingException {
// given
stubPostCall();
- String url = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String url = getTestUrl("http");
// when
HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient
.post(url, Collections.emptyMap(), NOT_EXISTING_OBJECT);
@@ -146,7 +158,7 @@ public class SyncRestClientForHttpServerTest {
// given
stubPostCall();
Map headers = ImmutableMap.<String, String>builder().put("Authorization", "Basic anyHash").build();
- String url = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String url = getTestUrl("http");
// when
HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient.post(url, headers, testObject);
// then
@@ -160,7 +172,7 @@ public class SyncRestClientForHttpServerTest {
public void testFailedJsonResponseFromPost() throws JsonProcessingException {
// given
stubPostCall();
- String url = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String url = getTestUrl("http");
// when
stubServer.stop();
syncRestClient.post(url, Collections.emptyMap(), testObject);
@@ -170,7 +182,7 @@ public class SyncRestClientForHttpServerTest {
public void testObjectResponseFromPost() throws JsonProcessingException {
// given
stubPostCall();
- String url = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String url = getTestUrl("http");
// when
HttpResponse<SyncRestClientModel.TestModel> objectHttpResponse = syncRestClient
.post(url, Collections.emptyMap(), testObject, SyncRestClientModel.TestModel.class);
@@ -187,7 +199,7 @@ public class SyncRestClientForHttpServerTest {
public void testJsonResponseFromPut() throws JsonProcessingException {
// given
stubPutCall();
- String url = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String url = getTestUrl("http");
// when
HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient.put(url, Collections.emptyMap(), testObject);
// then
@@ -203,7 +215,7 @@ public class SyncRestClientForHttpServerTest {
public void testObjectResponseFromPut() throws JsonProcessingException {
// given
stubPutCall();
- String url = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String url = getTestUrl("http");
// when
HttpResponse<SyncRestClientModel.TestModel> modelHttpResponse = syncRestClient
.put(url, Collections.emptyMap(), testObject, SyncRestClientModel.TestModel.class);
@@ -220,7 +232,7 @@ public class SyncRestClientForHttpServerTest {
public void testJsonResponseFromDelete() throws JsonProcessingException {
// given
stubDeleteCall();
- String url = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String url = getTestUrl("http");
// when
HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient.delete(url, Collections.emptyMap());
// then
@@ -236,7 +248,7 @@ public class SyncRestClientForHttpServerTest {
public void testObjectResponseFromDelete() throws JsonProcessingException {
// given
stubDeleteCall();
- String url = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String url = getTestUrl("http");
// when
HttpResponse<SyncRestClientModel.TestModel> modelHttpResponse = syncRestClient
.delete(url, Collections.emptyMap(), SyncRestClientModel.TestModel.class);
@@ -253,8 +265,8 @@ public class SyncRestClientForHttpServerTest {
public void testRedirectToHttp() throws JsonProcessingException {
// given
stubGetCall();
- String secured_url = "https://0.0.0.0:" + stubServer.getPort() + "/test";
- String available_url = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String secured_url = getTestUrl("https");;
+ String available_url = getTestUrl("http");
// when
HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient
.get(secured_url, Collections.emptyMap(), Collections.emptyMap());
diff --git a/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpsServerTest.java b/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpsServerTest.java
index 645b5eac0..27cd81e70 100644
--- a/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpsServerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpsServerTest.java
@@ -42,8 +42,8 @@ import com.xebialabs.restito.semantics.Condition;
import com.xebialabs.restito.server.StubServer;
import io.joshworks.restclient.http.HttpResponse;
import io.joshworks.restclient.http.JsonNode;
-
-import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -55,13 +55,13 @@ import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.ssl.SSLContextBuilder;
import org.glassfish.grizzly.http.Method;
+import org.jetbrains.annotations.NotNull;
import org.onap.vid.utils.Logging;
import org.springframework.http.HttpMethod;
import org.testng.annotations.AfterMethod;
@@ -91,12 +91,21 @@ public class SyncRestClientForHttpsServerTest {
stubServer.stop();
}
+ @NotNull
+ private String getTestUrl(String protocol) {
+ try {
+ return new URI(protocol, null, "127.0.0.1" , stubServer.getPort(), "/test", null, null).toString();
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
@Test
public void testJsonResponseFromGet() throws JsonProcessingException {
// given
stubGetCall();
- String securedUrl = "https://0.0.0.0:" + stubServer.getPort() + "/test";
- String notSecuredUrl = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String securedUrl = getTestUrl("https");
+ String notSecuredUrl = getTestUrl("http");
// when
HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient
.get(securedUrl, Collections.emptyMap(), Collections.emptyMap());
@@ -115,8 +124,8 @@ public class SyncRestClientForHttpsServerTest {
// given
stubServer.run();
stubGetCall();
- String securedUrl = "https://0.0.0.0:" + stubServer.getPort() + "/test";
- String notSecuredUrl = "http://0.0.0.0:" + stubServer.getPort() + "/test";
+ String securedUrl = getTestUrl("https");
+ String notSecuredUrl = getTestUrl("http");
// when
HttpResponse<SyncRestClientModel.TestModel> testModelHttpResponse = syncRestClient
.get(securedUrl, Collections.emptyMap(), Collections.emptyMap(), SyncRestClientModel.TestModel.class);