diff options
author | Vijay Venkatesh Kumar <vv770d@att.com> | 2018-11-15 04:04:47 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-11-15 04:04:47 +0000 |
commit | 7302b143f94d825f198def8c3b22c2920e6323a6 (patch) | |
tree | e1b8e2d16e6c5070f6847f278eb385cb9489662d /datafile-dmaap-client | |
parent | 012315895fd072a8e9f2355231f930ce37cefdaf (diff) | |
parent | b8693b348fb97fba734c7070d0aef79f94bf2e41 (diff) |
Merge "Add test for redirect"
Diffstat (limited to 'datafile-dmaap-client')
-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()); + } } |