diff options
author | elinuxhenrik <henrik.b.andersson@est.tech> | 2018-10-24 14:02:10 +0200 |
---|---|---|
committer | elinuxhenrik <henrik.b.andersson@est.tech> | 2018-10-24 14:02:41 +0200 |
commit | b8693b348fb97fba734c7070d0aef79f94bf2e41 (patch) | |
tree | 04f3f1e899763ccb81e3847d5b857b0fd976642d /datafile-dmaap-client/src/test/java/org | |
parent | 1099b80706087b90d5af40d700b19ae5205ba564 (diff) |
Add test for redirect
Change-Id: Ic8cc9c6ba63267498c24ba05267301a6b499c9dc
Issue-ID: DCAEGEN2-835
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Diffstat (limited to 'datafile-dmaap-client/src/test/java/org')
-rw-r--r-- | datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java index fb0cc294..0ed3c72e 100644 --- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java +++ b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java @@ -16,12 +16,27 @@ package org.onap.dcaegen2.collectors.datafile.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.http.Header; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolException; +import org.apache.http.RequestLine; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.protocol.HttpContext; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; class PublishRedirectStrategyTest { + private static final String URI = "sftp://localhost:80/"; + private static PublishRedirectStrategy publishRedirectStrategy; @@ -39,4 +54,22 @@ class PublishRedirectStrategyTest { void isRedirectable_shouldReturnFalse() { Assertions.assertFalse(publishRedirectStrategy.isRedirectable("not valid method")); } + + @Test + void getRedirect_shouldReturnCorrectUri() throws ProtocolException { + HttpRequest requestMock = mock(HttpRequest.class); + HttpResponse responseMock = mock(HttpResponse.class); + HttpContext contextMock = mock(HttpContext.class); + Header headerMock = mock(Header.class); + when(responseMock.getFirstHeader("location")).thenReturn(headerMock); + when(headerMock.getValue()).thenReturn(URI); + RequestConfig requestConfigMock = mock(RequestConfig.class); + when(contextMock.getAttribute(HttpClientContext.REQUEST_CONFIG)).thenReturn(requestConfigMock); + RequestLine requestLineMock = mock(RequestLine.class); + when(requestMock.getRequestLine()).thenReturn(requestLineMock); + when(requestLineMock.getUri()).thenReturn(URI); + + HttpUriRequest actualRedirect = publishRedirectStrategy.getRedirect(requestMock, responseMock, contextMock); + assertEquals(URI, actualRedirect.getURI().toString()); + } } |