From b8693b348fb97fba734c7070d0aef79f94bf2e41 Mon Sep 17 00:00:00 2001 From: elinuxhenrik Date: Wed, 24 Oct 2018 14:02:10 +0200 Subject: Add test for redirect Change-Id: Ic8cc9c6ba63267498c24ba05267301a6b499c9dc Issue-ID: DCAEGEN2-835 Signed-off-by: elinuxhenrik --- .../datafile/web/PublishRedirectStrategyTest.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'datafile-dmaap-client/src/test/java/org/onap') 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()); + } } -- cgit 1.2.3-korg