summaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-prov/src/test')
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java62
-rwxr-xr-xdatarouter-prov/src/test/resources/create.sql3
-rwxr-xr-xdatarouter-prov/src/test/resources/h2Database.properties1
3 files changed, 37 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));
}
diff --git a/datarouter-prov/src/test/resources/create.sql b/datarouter-prov/src/test/resources/create.sql
index 6e6af1d4..90484ab0 100755
--- a/datarouter-prov/src/test/resources/create.sql
+++ b/datarouter-prov/src/test/resources/create.sql
@@ -144,3 +144,6 @@ INSERT INTO PARAMETERS VALUES
INSERT INTO GROUPS(GROUPID, AUTHID, NAME, DESCRIPTION, CLASSIFICATION, MEMBERS)
VALUES (1, 'Basic dXNlcjE6cGFzc3dvcmQx', 'Group1', 'First Group for testing', 'Class1', 'Member1');
+
+INSERT INTO SUBSCRIPTIONS(SUBID, FEEDID, DELIVERY_URL, DELIVERY_USER, DELIVERY_PASSWORD, SUBSCRIBER, SELF_LINK, LOG_LINK)
+VALUES (23, 1, 'http://delivery_url', 'user1', 'somepassword', 'sub123', 'selflink', 'loglink');
diff --git a/datarouter-prov/src/test/resources/h2Database.properties b/datarouter-prov/src/test/resources/h2Database.properties
index 5bc20ed4..e9540029 100755
--- a/datarouter-prov/src/test/resources/h2Database.properties
+++ b/datarouter-prov/src/test/resources/h2Database.properties
@@ -24,3 +24,4 @@
# Database access
org.onap.dmaap.datarouter.db.driver = org.h2.Driver
org.onap.dmaap.datarouter.db.url = jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
+org.onap.dmaap.datarouter.provserver.isaddressauthenabled = true \ No newline at end of file