aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2018-09-18 12:32:42 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-18 12:32:42 +0000
commit338b79e5372ffd2810ea08f19cc9de87946aa494 (patch)
treebb1638dfdb05cee57543d172d247ad1497ddc657
parentf3e6d8b99224f6abd672ff3f39da427484cd5726 (diff)
parent44abe28675b5150e18c2f728401d781322b375c1 (diff)
Merge "junits for HttpClientRedirectStrategy"
-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