diff options
Diffstat (limited to 'datarouter-prov/src/test/java')
-rwxr-xr-x | datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java | 62 |
1 files changed, 33 insertions, 29 deletions
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,23 +144,13 @@ 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 { logServlet.doPut(request, response); @@ -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)); } |