aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Gwozdecki <tomasz.gwozdecki@nokia.com>2018-11-08 05:17:59 -0500
committerRob Daugherty <rd472p@att.com>2018-11-14 20:53:00 +0000
commitb957762763d4bd6fb0330eb4008e1b7527a59038 (patch)
tree69e350633372f1a5db6eacbb36379277e94182d2
parent78e9c0c84da529b26f25ab66c4d2e596fd180282 (diff)
junits for HttpClientRedirectStrategy
-Added new test for HttpClientRedirectStrategy -Tests for method getRedirect Change-Id: Ifb8cd2becc515ed349ecaed99b5b2f902b253b03 Issue-ID: SO-814 Signed-off-by: Tomasz Gwozdecki <tomasz.gwozdecki@nokia.com>
-rw-r--r--cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java28
1 files changed, 27 insertions, 1 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 b631dab999..87b51e9357 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
@@ -105,6 +105,33 @@ public class HttpClientRedirectStrategyTest {
assertThat(httpUriRequest.getURI()).isEqualTo(expectedUri);
}
+ @Test
+ public void getRedirect_shouldCopyHttpRequestAndSetNewUri_forMovedTemporarilyStatus() throws URISyntaxException, ProtocolException {
+ assertHttpRequestIsCopied(HttpStatus.SC_MOVED_TEMPORARILY);
+ }
+
+ @Test
+ public void getRedirect_shouldCopyHttpRequestAndSetNewUri_forTemporaryRedirectStatus() throws URISyntaxException, ProtocolException {
+ assertHttpRequestIsCopied(HttpStatus.SC_TEMPORARY_REDIRECT);
+ }
+
+ private void assertHttpRequestIsCopied(int expectedHttpStatus) throws URISyntaxException, ProtocolException {
+ // GIVEN
+ HttpRequest request = mock(HttpRequest.class, RETURNS_DEEP_STUBS);
+ given(request.getRequestLine().getMethod()).willReturn(HttpGet.METHOD_NAME);
+ given(request.getRequestLine().getUri()).willReturn("http://hostname");
+ HttpResponse response = mock(HttpResponse.class, RETURNS_DEEP_STUBS);
+ given(response.getStatusLine().getStatusCode()).willReturn(expectedHttpStatus);
+ URI expectedUri = new URI("http://localhost/host");
+ HttpContext context = null;
+ // WHEN
+ HttpUriRequest httpUriRequest = new TestableHttpClientRedirectStrategy(expectedUri)
+ .getRedirect(request, response, context);
+ // THEN
+ assertThat(httpUriRequest).isInstanceOf(HttpGet.class);
+ assertThat(httpUriRequest.getURI()).isEqualTo(expectedUri);
+ }
+
private static class TestableHttpClientRedirectStrategy extends HttpClientRedirectStrategy {
private final URI expectedUri;
@@ -112,7 +139,6 @@ public class HttpClientRedirectStrategyTest {
public TestableHttpClientRedirectStrategy(URI expectedUri) {
this.expectedUri = expectedUri;
}
-
@Override
public URI getLocationURI(HttpRequest request, HttpResponse response, HttpContext context) {
return expectedUri;