X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2FStatisticsServletTest.java;h=1fe8d9b1e3645187e5c35dac998180e25b909481;hb=8552e04175c7091d0d748e0c0f4b14a0d9321b40;hp=64d13e94292f74b02b37c814d02c1f292d146224;hpb=1d9710279b4d9bffacc0f8e360922119bb12e347;p=dmaap%2Fdatarouter.git diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java index 64d13e94..1fe8d9b1 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java @@ -22,9 +22,8 @@ ******************************************************************************/ package org.onap.dmaap.datarouter.provisioning; -import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -35,22 +34,17 @@ import javax.persistence.Persistence; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.onap.dmaap.datarouter.provisioning.utils.DB; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.modules.junit4.PowerMockRunner; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; - - @RunWith(PowerMockRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*"}) public class StatisticsServletTest { private StatisticsServlet statisticsServlet; @@ -61,8 +55,6 @@ public class StatisticsServletTest { @Mock private HttpServletResponse response; - private DB db; - private static EntityManagerFactory emf; private static EntityManager em; @@ -85,7 +77,6 @@ public class StatisticsServletTest { @Before public void setUp() throws Exception { statisticsServlet = new StatisticsServlet(); - db = new DB(); buildRequestParameters(); } @@ -94,7 +85,7 @@ public class StatisticsServletTest { throws Exception { statisticsServlet.doDelete(request, response); verify(response).sendError(eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED), - argThat(notNullValue(String.class))); + anyString()); } @Test @@ -102,7 +93,7 @@ public class StatisticsServletTest { throws Exception { statisticsServlet.doPut(request, response); verify(response).sendError(eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED), - argThat(notNullValue(String.class))); + anyString()); } @Test @@ -110,7 +101,7 @@ public class StatisticsServletTest { throws Exception { statisticsServlet.doPost(request, response); verify(response).sendError(eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED), - argThat(notNullValue(String.class))); + anyString()); } @Test @@ -119,13 +110,12 @@ public class StatisticsServletTest { when(request.getParameter("type")).thenReturn("get"); statisticsServlet.doGet(request, response); verify(response) - .sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class))); + .sendError(eq(HttpServletResponse.SC_BAD_REQUEST), anyString()); } @Test public void Given_Request_Is_HTTP_GET_With_GroupId_But_No_FeedId_Parameters_Then_Request_Succeeds() throws Exception { - addAliasForSubstringIndex(); ServletOutputStream outStream = mock(ServletOutputStream.class); when(response.getOutputStream()).thenReturn(outStream); statisticsServlet.doGet(request, response); @@ -135,7 +125,6 @@ public class StatisticsServletTest { @Test public void Given_Request_Is_HTTP_GET_With_GroupId_And_FeedId_Parameters_Then_Request_Succeeds() throws Exception { - addAliasForSubstringIndex(); when(request.getParameter("feedid")).thenReturn("1"); when(request.getParameter("statusCode")).thenReturn("500"); ServletOutputStream outStream = mock(ServletOutputStream.class); @@ -158,10 +147,4 @@ public class StatisticsServletTest { when(request.getParameter("groupid")).thenReturn("1"); when(request.getParameter("subid")).thenReturn("1"); } - private void addAliasForSubstringIndex() throws SQLException { - String sql = "CREATE ALIAS IF NOT EXISTS `SUBSTRING_INDEX`AS $$ String Function(String one, String two, String three){ return \"url\"; }$$;"; - Connection conn = db.getConnection(); - PreparedStatement pst = conn.prepareStatement(sql); - pst.execute(); - } }