X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2FLogServletTest.java;h=e411bdc02599752d79d3694a132593d30ef06be8;hb=c2d7dbe30b30437f339e7c127ae2c0ba13222e7e;hp=9a55059360dd1c045ba5ac5737249e0e810c3043;hpb=8eaccebf3182fbc14942d0e9242d01b050caee65;p=dmaap%2Fdatarouter.git diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java index 9a550593..e411bdc0 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java @@ -24,30 +24,33 @@ package org.onap.dmaap.datarouter.provisioning; import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.onap.dmaap.datarouter.provisioning.beans.Subscription; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; import org.powermock.modules.junit4.PowerMockRunner; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.powermock.api.mockito.PowerMockito.when; + @RunWith(PowerMockRunner.class) -@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.provisioning.beans.Subscription"}) public class LogServletTest extends DrServletTestBase { + private static EntityManagerFactory emf; + private static EntityManager em; private static LogServlet logServlet; @Mock @@ -55,9 +58,24 @@ public class LogServletTest extends DrServletTestBase { @Mock private HttpServletResponse response; + @BeforeClass + public static void init() { + emf = Persistence.createEntityManagerFactory("dr-unit-tests"); + em = emf.createEntityManager(); + System.setProperty( + "org.onap.dmaap.datarouter.provserver.properties", + "src/test/resources/h2Database.properties"); + } + + @AfterClass + public static void tearDownClass() { + em.clear(); + em.close(); + emf.close(); + } + @Before public void setUp() throws Exception { - super.setUp(); logServlet = new LogServlet(true); setUpValidParameterValuesForMap(); } @@ -78,7 +96,7 @@ public class LogServletTest extends DrServletTestBase { } @Test - public void Given_Request_Is_HTTP_GET_And_Has_Bad_Type() + public void Given_Request_Is_HTTP_GET_And_Has_Bad_Type_Then_Bad_Request_Response_Is_Generated() throws Exception { when(request.getParameter("type")).thenReturn("bad_type"); logServlet.doGet(request, response); @@ -86,7 +104,7 @@ public class LogServletTest extends DrServletTestBase { } @Test - public void Given_Request_Is_HTTP_GET_And_Has_Bad_PublishID() + public void Given_Request_Is_HTTP_GET_And_Has_Bad_PublishID_Then_Bad_Request_Response_Is_Generated() throws Exception { when(request.getParameter("publishId")).thenReturn("bad_PublishID'"); logServlet.doGet(request, response); @@ -94,7 +112,7 @@ public class LogServletTest extends DrServletTestBase { } @Test - public void Given_Request_Is_HTTP_GET_And_Has_Bad_StatusCode() + public void Given_Request_Is_HTTP_GET_And_Has_Bad_StatusCode_Then_Bad_Request_Response_Is_Generated() throws Exception { when(request.getParameter("statusCode")).thenReturn("1'"); logServlet.doGet(request, response); @@ -126,22 +144,12 @@ public class LogServletTest extends DrServletTestBase { } @Test - public void Given_Request_Is_HTTP_GET_And_Is_FeedLog() + public void Given_Request_Is_HTTP_GET_And_Is_FeedLog_A_STATUS_OK_Response_Is_Generated() throws Exception { logServlet.doGet(request, response); verify(response).setStatus(eq(HttpServletResponse.SC_OK)); } - @Test - public void Given_Request_Is_HTTP_GET_And_Is_Not_FeedLog() - throws Exception { - LogServlet logServletNotFeedlog = new LogServlet(false); - PowerMockito.mockStatic(Subscription.class); - PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(mock(Subscription.class)); - logServletNotFeedlog.doGet(request, response); - verify(response).setStatus(eq(HttpServletResponse.SC_OK)); - } - @Test public void Given_Request_Is_HTTP_PUT_And_Is_Not_Allowed_Then_Forbidden_Response_Is_Generated() throws Exception { @@ -157,7 +165,7 @@ public class LogServletTest extends DrServletTestBase { } @Test - public void Given_Request_Is_GetPublishRecordsForFeed_And_Type_Is_Publish() + public void Given_Request_Is_GetPublishRecordsForFeed_And_Type_Is_Publish_A_STATUS_OK_Response_Is_Generated() throws Exception { when(request.getParameter("type")).thenReturn("pub"); when(request.getParameter("expiryReason")).thenReturn(null); @@ -166,7 +174,7 @@ public class LogServletTest extends DrServletTestBase { } @Test - public void Given_Request_Is_getDeliveryRecordsForFeed_And_Type_Is_Delivery() + public void Given_Request_Is_getDeliveryRecordsForFeed_And_Type_Is_Delivery_A_STATUS_OK_Response_Is_Generated() throws Exception { when(request.getParameter("type")).thenReturn("del"); when(request.getParameter("expiryReason")).thenReturn(null); @@ -175,7 +183,7 @@ public class LogServletTest extends DrServletTestBase { } @Test - public void Given_Request_Is_getExpiryRecordsForFeed_And_Type_Is_Expire() + public void Given_Request_Is_getExpiryRecordsForFeed_And_Type_Is_Expire_A_STATUS_OK_Response_Is_Generated() throws Exception { when(request.getParameter("type")).thenReturn("exp"); when(request.getParameter("statusCode")).thenReturn(null); @@ -187,27 +195,23 @@ public class LogServletTest extends DrServletTestBase { } @Test - public void Given_Request_Is_getDeliveryRecordsForSubscription_And_Type_Is_Delivery() + public void Given_Request_Is_getDeliveryRecordsForSubscription_And_Type_Is_Delivery_A_STATUS_OK_Response_Is_Generated() throws Exception { LogServlet logServletNotFeedlog = new LogServlet(false); when(request.getParameter("type")).thenReturn("del"); when(request.getParameter("statusCode")).thenReturn(null); when(request.getParameter("expiryReason")).thenReturn(null); - PowerMockito.mockStatic(Subscription.class); - PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(mock(Subscription.class)); logServletNotFeedlog.doGet(request, response); verify(response).setStatus(eq(HttpServletResponse.SC_OK)); } @Test - public void Given_Request_Is_getExpiryRecordsForSubscription_And_Type_Is_Expiry() + public void Given_Request_Is_getExpiryRecordsForSubscription_And_Type_Is_Expiry_A_STATUS_OK_Response_Is_Generated() throws Exception { LogServlet logServletNotFeedlog = new LogServlet(false); when(request.getParameter("type")).thenReturn("exp"); when(request.getParameter("statusCode")).thenReturn(null); when(request.getParameter("expiryReason")).thenReturn(null); - PowerMockito.mockStatic(Subscription.class); - PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(mock(Subscription.class)); logServletNotFeedlog.doGet(request, response); verify(response).setStatus(eq(HttpServletResponse.SC_OK)); }