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;
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());
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);
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
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);
// 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
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);
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);
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
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);
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
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);
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());
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;
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;
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());
// 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);