junits for HttpClientRedirectStrategy 42/70142/2
authorTomasz Gwozdecki <tomasz.gwozdecki@nokia.com>
Wed, 10 Oct 2018 07:12:54 +0000 (03:12 -0400)
committerRob Daugherty <rd472p@att.com>
Mon, 29 Oct 2018 13:38:11 +0000 (13:38 +0000)
-Added new test for HttpClientRedirectStrategy
-Tests for method getRedirect

Change-Id: Id3adf920c1e3e53d93aa3658f147d571cb631f94
Issue-ID: SO-814
Signed-off-by: Tomasz Gwozdecki <tomasz.gwozdecki@nokia.com>
cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java

index 9a05602..b631dab 100644 (file)
@@ -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,23 @@ 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);
+    }
+
     private static class TestableHttpClientRedirectStrategy extends HttpClientRedirectStrategy {
 
         private final URI expectedUri;