diff options
Diffstat (limited to 'cloudify-client')
-rw-r--r-- | cloudify-client/pom.xml | 4 | ||||
-rw-r--r-- | cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java | 46 |
2 files changed, 47 insertions, 3 deletions
diff --git a/cloudify-client/pom.xml b/cloudify-client/pom.xml index 38aff4c43d..44242e934f 100644 --- a/cloudify-client/pom.xml +++ b/cloudify-client/pom.xml @@ -4,7 +4,7 @@ <parent> <groupId>org.onap.so</groupId> <artifactId>so</artifactId> - <version>1.3.0-SNAPSHOT</version> + <version>1.4.0-SNAPSHOT</version> </parent> <groupId>org.onap.so</groupId> @@ -46,4 +46,4 @@ <version>2.6</version> </dependency> </dependencies> -</project>
\ No newline at end of file +</project> 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 9a05602b34..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 @@ -28,6 +28,7 @@ import java.net.URI; import java.net.URISyntaxException; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; import org.apache.http.ProtocolException; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; @@ -87,6 +88,50 @@ public class HttpClientRedirectStrategyTest { assertThat(httpUriRequest.getURI()).isEqualTo(expectedUri); } + @Test + public void getRedirect_shouldReturnHttpGetUri_byDefault() throws URISyntaxException, ProtocolException { + // GIVEN + HttpRequest request = mock(HttpRequest.class, RETURNS_DEEP_STUBS); + given(request.getRequestLine().getMethod()).willReturn(HttpPost.METHOD_NAME); + HttpResponse response = mock(HttpResponse.class, RETURNS_DEEP_STUBS); + given(response.getStatusLine().getStatusCode()).willReturn(HttpStatus.SC_ACCEPTED); + 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); + } + + @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; @@ -94,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; |