From 5b593496b8f1b8e8be8d7d2dbcc223332e65a49b Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Sun, 29 Jul 2018 16:13:45 +0300 Subject: re base code Change-Id: I12a5ca14a6d8a87e9316b9ff362eb131105f98a5 Issue-ID: SDC-1566 Signed-off-by: Michael Lando --- .../java/org/openecomp/sdc/fe/GzipFilterTest.java | 36 ------------ .../openecomp/sdc/fe/impl/HttpRequestInfoTest.java | 32 ++++++----- .../sdc/fe/listen/MyObjectMapperProviderTest.java | 28 ---------- .../sdc/fe/servlets/PluginStatusBLTest.java | 17 +++--- .../openecomp/sdc/servlets/FeProxyServletTest.java | 23 ++++---- .../openecomp/sdc/servlets/PortalServletTest.java | 64 ++++++++++------------ 6 files changed, 65 insertions(+), 135 deletions(-) delete mode 100644 catalog-fe/src/test/java/org/openecomp/sdc/fe/GzipFilterTest.java delete mode 100644 catalog-fe/src/test/java/org/openecomp/sdc/fe/listen/MyObjectMapperProviderTest.java (limited to 'catalog-fe/src/test/java/org') diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/fe/GzipFilterTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/fe/GzipFilterTest.java deleted file mode 100644 index 685d6b3d8f..0000000000 --- a/catalog-fe/src/test/java/org/openecomp/sdc/fe/GzipFilterTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.openecomp.sdc.fe; - -import javax.servlet.FilterConfig; - -import org.junit.Test; - - -public class GzipFilterTest { - - private GzipFilter createTestSubject() { - return new GzipFilter(); - } - - - - - @Test - public void testInit() throws Exception { - GzipFilter testSubject; - FilterConfig filterConfig = null; - - // default test - testSubject = createTestSubject(); - testSubject.init(filterConfig); - } - - - @Test - public void testDestroy() throws Exception { - GzipFilter testSubject; - - // default test - testSubject = createTestSubject(); - testSubject.destroy(); - } -} \ No newline at end of file diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/HttpRequestInfoTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/HttpRequestInfoTest.java index c7a44c564e..3bb0006a26 100644 --- a/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/HttpRequestInfoTest.java +++ b/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/HttpRequestInfoTest.java @@ -1,5 +1,9 @@ package org.openecomp.sdc.fe.impl; +import org.junit.Test; + +import javax.servlet.*; +import javax.servlet.http.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -9,19 +13,6 @@ import java.util.Collection; import java.util.Enumeration; import java.util.Locale; import java.util.Map; -import javax.servlet.AsyncContext; -import javax.servlet.DispatcherType; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import javax.servlet.http.Part; -import org.junit.Test; public class HttpRequestInfoTest { @@ -146,6 +137,11 @@ public class HttpRequestInfoTest { return 0; } + @Override + public long getContentLengthLong() { + return 0; + } + @Override public String getContentType() { // TODO Auto-generated method stub @@ -458,6 +454,11 @@ public class HttpRequestInfoTest { return null; } + @Override + public String changeSessionId() { + return null; + } + @Override public boolean isRequestedSessionIdValid() { // TODO Auto-generated method stub @@ -510,5 +511,10 @@ public class HttpRequestInfoTest { return null; } + @Override + public T upgrade(Class aClass) throws IOException, ServletException { + return null; + } + } } \ No newline at end of file diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/fe/listen/MyObjectMapperProviderTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/fe/listen/MyObjectMapperProviderTest.java deleted file mode 100644 index c77206fb03..0000000000 --- a/catalog-fe/src/test/java/org/openecomp/sdc/fe/listen/MyObjectMapperProviderTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.openecomp.sdc.fe.listen; - -import org.junit.Test; - -import com.fasterxml.jackson.databind.ObjectMapper; - - -public class MyObjectMapperProviderTest { - - private MyObjectMapperProvider createTestSubject() { - return new MyObjectMapperProvider(); - } - - - @Test - public void testGetContext() throws Exception { - MyObjectMapperProvider testSubject; - Class type = null; - ObjectMapper result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getContext(type); - } - - - -} \ No newline at end of file diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/fe/servlets/PluginStatusBLTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/fe/servlets/PluginStatusBLTest.java index 25fef8968b..e1d93b702d 100644 --- a/catalog-fe/src/test/java/org/openecomp/sdc/fe/servlets/PluginStatusBLTest.java +++ b/catalog-fe/src/test/java/org/openecomp/sdc/fe/servlets/PluginStatusBLTest.java @@ -1,12 +1,7 @@ package org.openecomp.sdc.fe.servlets; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; @@ -21,8 +16,12 @@ import org.openecomp.sdc.fe.config.PluginsConfiguration; import org.openecomp.sdc.fe.config.PluginsConfiguration.Plugin; import org.openecomp.sdc.fe.impl.PluginStatusBL; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; public class PluginStatusBLTest { diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java index 7143e8776b..1e42fec42f 100644 --- a/catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java +++ b/catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java @@ -20,19 +20,6 @@ package org.openecomp.sdc.servlets; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; - import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.http.HttpFields; import org.junit.BeforeClass; @@ -43,6 +30,16 @@ import org.openecomp.sdc.fe.config.Configuration; import org.openecomp.sdc.fe.config.ConfigurationManager; import org.openecomp.sdc.fe.servlets.FeProxyServlet; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; + public class FeProxyServletTest { /* * Example Url Mappings: diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/servlets/PortalServletTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/servlets/PortalServletTest.java index 02f685302e..72d279d3e5 100644 --- a/catalog-fe/src/test/java/org/openecomp/sdc/servlets/PortalServletTest.java +++ b/catalog-fe/src/test/java/org/openecomp/sdc/servlets/PortalServletTest.java @@ -20,46 +20,39 @@ package org.openecomp.sdc.servlets; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import javax.ws.rs.core.Application; - import org.glassfish.jersey.internal.inject.AbstractBinder; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.fe.config.Configuration; import org.openecomp.sdc.fe.config.ConfigurationManager; import org.openecomp.sdc.fe.servlets.PortalServlet; +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.ws.rs.core.Application; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.glassfish.jersey.test.TestProperties.CONTAINER_PORT; +import static org.mockito.Mockito.*; + public class PortalServletTest extends JerseyTest { - final static HttpServletRequest request = Mockito.mock(HttpServletRequest.class); - final static HttpSession httpSession = Mockito.mock(HttpSession.class); - final static ServletContext servletContext = Mockito.mock(ServletContext.class); - final static ConfigurationManager configurationManager = Mockito.mock(ConfigurationManager.class); - final static Configuration configuration = Mockito.mock(Configuration.class); - final static HttpServletResponse response = Mockito.spy(HttpServletResponse.class); - final static RequestDispatcher rd = Mockito.spy(RequestDispatcher.class); + private final static HttpServletRequest request = Mockito.mock(HttpServletRequest.class); + private final static HttpSession httpSession = Mockito.mock(HttpSession.class); + private final static ServletContext servletContext = Mockito.mock(ServletContext.class); + private final static ConfigurationManager configurationManager = Mockito.mock(ConfigurationManager.class); + private final static Configuration configuration = Mockito.mock(Configuration.class); + private final static HttpServletResponse response = Mockito.spy(HttpServletResponse.class); + private final static RequestDispatcher rd = Mockito.spy(RequestDispatcher.class); @SuppressWarnings("serial") @BeforeClass @@ -69,7 +62,7 @@ public class PortalServletTest extends JerseyTest { when(httpSession.getServletContext()).thenReturn(servletContext); when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager); when(configurationManager.getConfiguration()).thenReturn(configuration); - List> mandatoryHeaders = new ArrayList>(); + List> mandatoryHeaders = new ArrayList<>(); mandatoryHeaders.add(new ArrayList() { { add("HTTP_IV_USER"); @@ -95,7 +88,7 @@ public class PortalServletTest extends JerseyTest { } }); - List> optionalHeaders = new ArrayList>(); + List> optionalHeaders = new ArrayList<>(); optionalHeaders.add(new ArrayList() { { add("HTTP_CSP_FIRSTNAME"); @@ -129,14 +122,11 @@ public class PortalServletTest extends JerseyTest { } @Test - public void testSuccesfulRequest() throws IOException, ServletException { - Mockito.doAnswer(new Answer() { - public Object answer(InvocationOnMock invocation) { - Object[] args = invocation.getArguments(); - String headerName = (String) args[0]; - return headerName; - } - }).when(request).getHeader(Mockito.anyString()); + public void testSuccessfulRequest() throws IOException, ServletException { + Mockito.doAnswer((Answer) invocation -> { + Object[] args = invocation.getArguments(); + return (String) args[0]; + }).when(request).getHeader(Mockito.anyString()); target().path("/portal").request().get(); verify(rd).forward(Mockito.any(ServletRequest.class), Mockito.any(ServletResponse.class)); Mockito.reset(response, rd); @@ -144,6 +134,8 @@ public class PortalServletTest extends JerseyTest { @Override protected Application configure() { + // Use any available port - this allows us to run the BE tests in parallel with this one. + forceSet(CONTAINER_PORT, "0"); ResourceConfig resourceConfig = new ResourceConfig(PortalServlet.class); resourceConfig.register(new AbstractBinder() { -- cgit 1.2.3-korg