aboutsummaryrefslogtreecommitdiffstats
path: root/cloudify-client
diff options
context:
space:
mode:
authorTomasz Gwozdecki <tomasz.gwozdecki@nokia.com>2018-09-18 03:33:10 -0400
committerTomasz Gwozdecki <tomasz.gwozdecki@nokia.com>2018-09-18 03:33:10 -0400
commit44abe28675b5150e18c2f728401d781322b375c1 (patch)
treeefe1a592b246ef6f656da1f7f0b39dc014f53e49 /cloudify-client
parent3f706329895da64e9634864301bdbf12a0dc4a8d (diff)
junits for HttpClientRedirectStrategy
-Added new tests for HttpClientRedirectStrategy -Tests for method getRedirect Change-Id: Ica45eac1cbf65170b5b9c84f002b05884c36f5a0 Issue-ID: SO-814 Signed-off-by: Tomasz Gwozdecki <tomasz.gwozdecki@nokia.com>
Diffstat (limited to 'cloudify-client')
-rw-r--r--cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java
index bfe7f164b2..9a05602b34 100644
--- a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java
+++ b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java
@@ -20,7 +20,15 @@
package org.onap.so.cloudify.connector.http;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import java.net.URI;
+import java.net.URISyntaxException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolException;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
@@ -29,6 +37,8 @@ import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpTrace;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.protocol.HttpContext;
import org.junit.Test;
public class HttpClientRedirectStrategyTest {
@@ -50,4 +60,44 @@ public class HttpClientRedirectStrategyTest {
assertThat(httpClientRedirectStrategy.isRedirectable(HttpDelete.METHOD_NAME)).isTrue();
assertThat(httpClientRedirectStrategy.isRedirectable(HttpHead.METHOD_NAME)).isTrue();
}
+
+ @Test
+ public void getRedirect_shouldReturnHttpHeadUriRequest() throws URISyntaxException, ProtocolException {
+ assertHttpUriRequestFor(HttpHead.METHOD_NAME, HttpHead.class);
+ }
+
+ @Test
+ public void getRedirect_shouldReturnHttpGetUriRequest() throws URISyntaxException, ProtocolException {
+ assertHttpUriRequestFor(HttpGet.METHOD_NAME, HttpGet.class);
+ }
+
+ private void assertHttpUriRequestFor(String methodName, Class<? extends HttpUriRequest> expectedHttpMethodClass)
+ throws URISyntaxException, ProtocolException {
+ // GIVEN
+ HttpRequest request = mock(HttpRequest.class, RETURNS_DEEP_STUBS);
+ given(request.getRequestLine().getMethod()).willReturn(methodName);
+ HttpResponse response = null;
+ HttpContext context = null;
+ URI expectedUri = new URI("http://localhost/host");
+ // WHEN
+ HttpUriRequest httpUriRequest = new TestableHttpClientRedirectStrategy(expectedUri)
+ .getRedirect(request, response, context);
+ // THEN
+ assertThat(httpUriRequest).isInstanceOf(expectedHttpMethodClass);
+ assertThat(httpUriRequest.getURI()).isEqualTo(expectedUri);
+ }
+
+ private static class TestableHttpClientRedirectStrategy extends HttpClientRedirectStrategy {
+
+ private final URI expectedUri;
+
+ public TestableHttpClientRedirectStrategy(URI expectedUri) {
+ this.expectedUri = expectedUri;
+ }
+
+ @Override
+ public URI getLocationURI(HttpRequest request, HttpResponse response, HttpContext context) {
+ return expectedUri;
+ }
+ }
} \ No newline at end of file