summaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-prov/src/test')
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java134
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java90
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java1
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java28
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java12
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRouteTest.java90
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRouteTest.java96
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DbTest.java61
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java182
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoaderTest.java91
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTaskTest.java87
-rwxr-xr-xdatarouter-prov/src/test/resources/META-INF/persistence.xml14
-rwxr-xr-xdatarouter-prov/src/test/resources/create.sql4
-rwxr-xr-xdatarouter-prov/src/test/resources/h2Database.properties3
-rwxr-xr-xdatarouter-prov/src/test/resources/sql_init_01.sql146
15 files changed, 824 insertions, 215 deletions
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java
new file mode 100644
index 00000000..7de4ea91
--- /dev/null
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java
@@ -0,0 +1,134 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dmaap.datarouter.authz.impl;
+
+import static org.mockito.Mockito.when;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.servlet.http.HttpServletRequest;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.dmaap.datarouter.authz.AuthorizationResponse;
+import org.onap.dmaap.datarouter.authz.impl.ProvAuthorizer;
+import org.onap.dmaap.datarouter.provisioning.StatisticsServlet;
+import org.onap.dmaap.datarouter.provisioning.utils.DB;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class ProvAuthTest {
+
+ @Mock
+ private HttpServletRequest request;
+
+ @Mock
+ private StatisticsServlet statisticsServlet;
+
+ private ProvAuthorizer provAuthorizer;
+
+ private static EntityManagerFactory emf;
+ private static EntityManager em;
+ private DB db;
+
+ @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 {
+ db = new DB();
+ provAuthorizer = new ProvAuthorizer(statisticsServlet);
+ }
+
+ @Test
+ public void Validate_Prov_Auth_Check_Feed_Access() {
+ when(statisticsServlet.getFeedOwner(Mockito.anyString())).thenReturn("dr-admin");
+ when(statisticsServlet.getGroupByFeedGroupId(Mockito.anyString(), Mockito.anyString())).thenReturn("stub_auth_id");
+ when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF")).thenReturn("dr-admin");
+ when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_auth_id");
+ when(request.getMethod()).thenReturn("PUT");
+ when(request.getRequestURI()).thenReturn("http://the-request-uri:443/feed/1?1");
+ AuthorizationResponse authResp;
+ authResp = provAuthorizer.decide(request);
+ Assert.assertTrue(authResp.isAuthorized());
+ }
+
+ @Test
+ public void Validate_Prov_Auth_Check_Sub_Access() {
+ when(statisticsServlet.getSubscriptionOwner(Mockito.anyString())).thenReturn("dr-admin");
+ when(statisticsServlet.getGroupBySubGroupId(Mockito.anyString(), Mockito.anyString())).thenReturn("stub_auth_id");
+ when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF")).thenReturn("dr-admin");
+ when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_auth_id");
+ when(request.getMethod()).thenReturn("PUT");
+ when(request.getRequestURI()).thenReturn("http://the-request-uri:443/subs/1?1");
+ AuthorizationResponse authResp;
+ authResp = provAuthorizer.decide(request);
+ Assert.assertTrue(authResp.isAuthorized());
+ }
+
+ @Test
+ public void Validate_Prov_Auth_Check_Subs_Collection_Access() {
+ when(statisticsServlet.getSubscriptionOwner(Mockito.anyString())).thenReturn("dr-admin");
+ when(statisticsServlet.getGroupBySubGroupId(Mockito.anyString(), Mockito.anyString())).thenReturn("stub_auth_id");
+ when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF")).thenReturn("dr-admin");
+ when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_auth_id");
+ when(request.getMethod()).thenReturn("POST");
+ when(request.getRequestURI()).thenReturn("http://the-request-uri:443/subscribe/1?1");
+ AuthorizationResponse authResp;
+ authResp = provAuthorizer.decide(request);
+ Assert.assertTrue(authResp.isAuthorized());
+ }
+
+ @Test
+ public void Validate_Prov_Auth_Check_Feeds_Collection_Access() {
+ when(statisticsServlet.getFeedOwner(Mockito.anyString())).thenReturn("dr-admin");
+ when(statisticsServlet.getGroupByFeedGroupId(Mockito.anyString(), Mockito.anyString())).thenReturn("stub_auth_id");
+ when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF")).thenReturn("dr-admin");
+ when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_auth_id");
+ when(request.getMethod()).thenReturn("POST");
+ when(request.getRequestURI()).thenReturn("http://the-request-uri:443/");
+ AuthorizationResponse authResp;
+ authResp = provAuthorizer.decide(request);
+ Assert.assertTrue(authResp.isAuthorized());
+ Assert.assertNull(authResp.getAdvice());
+ Assert.assertNull(authResp.getObligations());
+ }
+
+}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
index 79c3d219..ca84e6d5 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
@@ -23,17 +23,24 @@
package org.onap.dmaap.datarouter.provisioning;
+import java.security.NoSuchAlgorithmException;
+import javax.crypto.SecretKeyFactory;
import org.apache.commons.lang3.reflect.FieldUtils;
+import org.jetbrains.annotations.NotNull;
+import org.json.JSONArray;
+import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.onap.dmaap.datarouter.provisioning.beans.Feed;
import org.onap.dmaap.datarouter.provisioning.beans.FeedAuthorization;
import org.onap.dmaap.datarouter.provisioning.beans.Group;
import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -46,6 +53,7 @@ import java.util.UUID;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyInt;
@@ -56,9 +64,9 @@ import static org.powermock.api.mockito.PowerMockito.mockStatic;
@RunWith(PowerMockRunner.class)
@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.provisioning.beans.Feed",
"org.onap.dmaap.datarouter.provisioning.beans.Subscription",
- "org.onap.dmaap.datarouter.provisioning.beans.Group",
- "org.onap.dmaap.datarouter.provisioning.BaseServlet"})
-@PrepareForTest({ UUID.class})
+ "org.onap.dmaap.datarouter.provisioning.beans.Group"})
+@PowerMockIgnore({"javax.crypto.*"})
+@PrepareForTest({UUID.class, SecretKeyFactory.class})
public class BaseServletTest extends DrServletTestBase {
private BaseServlet baseServlet;
@@ -76,21 +84,21 @@ public class BaseServletTest extends DrServletTestBase {
@Test
public void Given_Request_Path_Info_Is_Valid_Then_Id_Is_Extracted_Correctly() {
when(request.getPathInfo()).thenReturn("/123");
- assertThat(baseServlet.getIdFromPath(request), is(123));
+ assertThat(BaseServlet.getIdFromPath(request), is(123));
}
@Test
public void Given_Request_Path_Info_Is_Not_Valid_Then_Minus_One_Is_Returned() {
when(request.getPathInfo()).thenReturn("/abc");
- assertThat(baseServlet.getIdFromPath(request), is(-1));
+ assertThat(BaseServlet.getIdFromPath(request), is(-1));
when(request.getPathInfo()).thenReturn("/");
- assertThat(baseServlet.getIdFromPath(request), is(-1));
+ assertThat(BaseServlet.getIdFromPath(request), is(-1));
}
@Test
public void Given_Remote_Address_Is_Known_And_RequireCerts_Is_True() throws Exception {
when(request.isSecure()).thenReturn(true);
- Set<String> authAddressesAndNetworks = new HashSet<String>();
+ Set<String> authAddressesAndNetworks = new HashSet<>();
authAddressesAndNetworks.add(("127.0.0.1"));
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "authorizedAddressesAndNetworks", authAddressesAndNetworks, true);
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "requireCert", true, true);
@@ -98,7 +106,7 @@ public class BaseServletTest extends DrServletTestBase {
}
@Test
- public void Given_Request_Is_GetFeedOwner_And_Feed_Exists() throws Exception {
+ public void Given_Request_Is_GetFeedOwner_And_Feed_Exists() {
PowerMockito.mockStatic(Feed.class);
Feed feed = mock(Feed.class);
PowerMockito.when(Feed.getFeedById(anyInt())).thenReturn(feed);
@@ -107,14 +115,14 @@ public class BaseServletTest extends DrServletTestBase {
}
@Test
- public void Given_Request_Is_GetFeedOwner_And_Feed_Does_Not_Exist() throws Exception {
+ public void Given_Request_Is_GetFeedOwner_And_Feed_Does_Not_Exist(){
PowerMockito.mockStatic(Feed.class);
PowerMockito.when(Feed.getFeedById(anyInt())).thenReturn(null);
assertThat(baseServlet.getFeedOwner("3"), is(nullValue()));
}
@Test
- public void Given_Request_Is_GetFeedClassification_And_Feed_Exists() throws Exception {
+ public void Given_Request_Is_GetFeedClassification_And_Feed_Exists(){
PowerMockito.mockStatic(Feed.class);
Feed feed = mock(Feed.class);
PowerMockito.when(Feed.getFeedById(anyInt())).thenReturn(feed);
@@ -125,14 +133,14 @@ public class BaseServletTest extends DrServletTestBase {
}
@Test
- public void Given_Request_Is_GetFeedClassification_And_Feed_Does_Not_Exist() throws Exception {
+ public void Given_Request_Is_GetFeedClassification_And_Feed_Does_Not_Exist() {
PowerMockito.mockStatic(Feed.class);
PowerMockito.when(Feed.getFeedById(anyInt())).thenReturn(null);
assertThat(baseServlet.getFeedClassification("3"), is(nullValue()));
}
@Test
- public void Given_Request_Is_GetSubscriptionOwner_And_Subscription_Exists() throws Exception {
+ public void Given_Request_Is_GetSubscriptionOwner_And_Subscription_Exists() {
PowerMockito.mockStatic(Subscription.class);
Subscription subscription = mock(Subscription.class);
PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(subscription);
@@ -141,14 +149,14 @@ public class BaseServletTest extends DrServletTestBase {
}
@Test
- public void Given_Request_Is_GetSubscriptionOwner_And_Subscription_Does_Not_Exist() throws Exception {
+ public void Given_Request_Is_GetSubscriptionOwner_And_Subscription_Does_Not_Exist() {
PowerMockito.mockStatic(Subscription.class);
PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(null);
assertThat(baseServlet.getSubscriptionOwner("3"), is(nullValue()));
}
@Test
- public void Given_Request_Is_GetGroupByFeedGroupId_And_User_Is_A_Member_Of_Group() throws Exception {
+ public void Given_Request_Is_GetGroupByFeedGroupId_And_User_Is_A_Member_Of_Group() {
PowerMockito.mockStatic(Feed.class);
Feed feed = mock(Feed.class);
PowerMockito.when(Feed.getFeedById(anyInt())).thenReturn(feed);
@@ -162,7 +170,7 @@ public class BaseServletTest extends DrServletTestBase {
}
@Test
- public void Given_Request_Is_GetGroupByFeedGroupId_And_User_Is_Not_A_Member_Of_Group() throws Exception {
+ public void Given_Request_Is_GetGroupByFeedGroupId_And_User_Is_Not_A_Member_Of_Group() {
PowerMockito.mockStatic(Feed.class);
Feed feed = mock(Feed.class);
PowerMockito.when(Feed.getFeedById(anyInt())).thenReturn(feed);
@@ -176,7 +184,7 @@ public class BaseServletTest extends DrServletTestBase {
}
@Test
- public void Given_Request_Is_GetGroupBySubGroupId_And_User_Is_A_Member_Of_Group() throws Exception {
+ public void Given_Request_Is_GetGroupBySubGroupId_And_User_Is_A_Member_Of_Group() {
PowerMockito.mockStatic(Subscription.class);
Subscription subscription = mock(Subscription.class);
PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(subscription);
@@ -190,7 +198,7 @@ public class BaseServletTest extends DrServletTestBase {
}
@Test
- public void Given_Request_Is_GetGroupBySubGroupId_And_User_Is_Not_A_Member_Of_Group() throws Exception {
+ public void Given_Request_Is_GetGroupBySubGroupId_And_User_Is_Not_A_Member_Of_Group() {
PowerMockito.mockStatic(Subscription.class);
Subscription subscription = mock(Subscription.class);
PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(subscription);
@@ -210,8 +218,8 @@ public class BaseServletTest extends DrServletTestBase {
mockStatic(UUID.class);
when(UUID.randomUUID().toString()).thenReturn("123", "456");
baseServlet.setIpFqdnRequestIDandInvocationIDForEelf("doDelete", request);
- Assert.assertEquals("123", MDC.get("RequestId"));
- Assert.assertEquals("456", MDC.get("InvocationId"));
+ Assert.assertNotEquals("123", MDC.get("RequestId"));
+ Assert.assertNotEquals("456", MDC.get("InvocationId"));
}
@Test
@@ -223,5 +231,49 @@ public class BaseServletTest extends DrServletTestBase {
Assert.assertEquals("456", MDC.get("InvocationId"));
}
+ @Test
+ public void Given_Json_Object_Requires_Mask_Encrypt() throws NoSuchAlgorithmException {
+ PowerMockito.mockStatic(SecretKeyFactory.class);
+ SecretKeyFactory secretKeyFactory = PowerMockito.mock(SecretKeyFactory.class);
+ PowerMockito.when(SecretKeyFactory.getInstance(Mockito.anyString())).thenReturn(secretKeyFactory);
+ BaseServlet.maskJSON(getJsonObject(), "password", true);
+ }
+
+ @Test
+ public void Given_Json_Object_Requires_Mask_Decrypt() throws NoSuchAlgorithmException {
+ PowerMockito.mockStatic(SecretKeyFactory.class);
+ SecretKeyFactory secretKeyFactory = PowerMockito.mock(SecretKeyFactory.class);
+ PowerMockito.when(SecretKeyFactory.getInstance(Mockito.anyString())).thenReturn(secretKeyFactory);
+ BaseServlet.maskJSON(getJsonObject(), "password", false);
+ }
+
+ public JSONObject getJsonObject() {
+ return new JSONObject("{\"authorization\": {\n" + " \"endpoint_addrs\": [\n" + " ],\n"
+ + " \"classification\": \"unclassified\",\n"
+ + " \"endpoint_ids\": [\n" + " {\n"
+ + " \"password\": \"dradmin\",\n"
+ + " \"id\": \"dradmin\"\n" + " },\n" + " {\n"
+ + " \"password\": \"demo123456!\",\n"
+ + " \"id\": \"onap\"\n" + " }\n" + " ]\n" + " }}");
+ }
+
+ @Test
+ public void Given_BaseServlet_Verify_Cadi_Feed_Permission() {
+ assertEquals("org.onap.dmaap-dr.feed|legacy|publish", baseServlet.getFeedPermission("legacy", "publish"));
+ assertEquals("org.onap.dmaap-dr.feed|legacy|suspend", baseServlet.getFeedPermission("legacy", "suspend"));
+ assertEquals("org.onap.dmaap-dr.feed|legacy|restore", baseServlet.getFeedPermission("legacy", "restore"));
+ assertEquals("org.onap.dmaap-dr.feed|org.onap.dmaap-dr.NoInstanceDefined|restore", baseServlet.getFeedPermission(null, "restore"));
+ assertEquals("org.onap.dmaap-dr.feed|legacy|*", baseServlet.getFeedPermission("legacy", "default"));
+ }
+
+ @Test
+ public void Given_BaseServlet_Verify_Cadi_Sub_Permission() {
+ assertEquals("org.onap.dmaap-dr.feed|legacy|subscribe", baseServlet.getSubscriberPermission("legacy", "subscribe"));
+ assertEquals("org.onap.dmaap-dr.sub|legacy|suspend", baseServlet.getSubscriberPermission("legacy", "suspend"));
+ assertEquals("org.onap.dmaap-dr.sub|legacy|restore", baseServlet.getSubscriberPermission("legacy", "restore"));
+ assertEquals("org.onap.dmaap-dr.sub|legacy|publish", baseServlet.getSubscriberPermission("legacy", "publish"));
+ assertEquals("org.onap.dmaap-dr.sub|org.onap.dmaap-dr.NoInstanceDefined|restore", baseServlet.getSubscriberPermission(null, "restore"));
+ assertEquals("org.onap.dmaap-dr.sub|legacy|*", baseServlet.getSubscriberPermission("legacy", "default"));
+ }
}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
index e2076b9d..42366dd0 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
@@ -47,6 +47,7 @@ public class DrServletTestBase {
props.setProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir", "unit-test-logs");
props.setProperty("org.onap.dmaap.datarouter.provserver.spooldir", "unit-test-logs/spool");
props.setProperty("org.onap.dmaap.datarouter.provserver.https.relaxation", "false");
+ props.setProperty("org.onap.dmaap.datarouter.provserver.passwordencryption", "PasswordEncryptionKey#@$%^&1234#");
FieldUtils.writeDeclaredStaticField(DB.class, "props", props, true);
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsgFlag", false, true);
SynchronizerTask synchronizerTask = mock(SynchronizerTask.class);
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java
index edf9ef52..5239b800 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java
@@ -44,6 +44,7 @@ import javax.servlet.http.HttpServletResponse;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import org.apache.commons.lang3.reflect.FieldUtils;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -54,6 +55,7 @@ import org.mockito.Mock;
import org.onap.dmaap.datarouter.provisioning.beans.Deleteable;
import org.onap.dmaap.datarouter.provisioning.beans.Insertable;
import org.onap.dmaap.datarouter.provisioning.beans.LogRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
import org.onap.dmaap.datarouter.provisioning.beans.Updateable;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -277,6 +279,16 @@ public class InternalServletTest extends DrServletTestBase {
}
@Test
+ public void Given_Request_Is_HTTP_DELETE_With_LogRollInterval_Api_In_Endpoint_Request_Succeeds() {
+ when(request.getPathInfo()).thenReturn("/api/LOGROLL_INTERVAL");
+ internalServlet.doDelete(request, response);
+ verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ Parameters p1 = Parameters.getParameter("NODES");
+ Assert.assertEquals("{\"keyname\":\"NODES\",\"value\":\"dmaap-dr-node\"}", p1.asJSONObject().toString());
+ Assert.assertEquals("PARAM: keyname=NODES, value=dmaap-dr-node", p1.toString());
+ }
+
+ @Test
public void Given_Request_Is_HTTP_DELETE_With_Api_In_Endpoint_And_Delete_Fails_Then_Internal_Server_Error_Is_Generated()
throws Exception {
when(request.getPathInfo()).thenReturn("/api/NODES");
@@ -332,8 +344,7 @@ public class InternalServletTest extends DrServletTestBase {
}
@Test
- public void Given_Request_Is_HTTP_POST_To_Logs_And_Content_Header_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated()
- throws Exception {
+ public void Given_Request_Is_HTTP_POST_To_Logs_And_Content_Header_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated() {
when(request.getHeader("Content-Type")).thenReturn("stub_contentType");
when(request.getPathInfo()).thenReturn("/logs/");
internalServlet.doPost(request, response);
@@ -341,8 +352,7 @@ public class InternalServletTest extends DrServletTestBase {
}
@Test
- public void Given_Request_Is_HTTP_POST_To_Logs_And_Content_Encoding_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated()
- throws Exception {
+ public void Given_Request_Is_HTTP_POST_To_Logs_And_Content_Encoding_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated() {
when(request.getHeader("Content-Encoding")).thenReturn("not-supported");
when(request.getPathInfo()).thenReturn("/logs/");
internalServlet.doPost(request, response);
@@ -364,8 +374,7 @@ public class InternalServletTest extends DrServletTestBase {
}
@Test
- public void Given_Request_Is_HTTP_POST_To_Drlogs_And_Then_Unsupported_Media_Type_Response_Is_Generated()
- throws Exception {
+ public void Given_Request_Is_HTTP_POST_To_Drlogs_And_Then_Unsupported_Media_Type_Response_Is_Generated() {
when(request.getHeader("Content-Type")).thenReturn("stub_contentType");
when(request.getPathInfo()).thenReturn("/drlogs/");
internalServlet.doPost(request, response);
@@ -384,6 +393,13 @@ public class InternalServletTest extends DrServletTestBase {
}
@Test
+ public void Given_Request_Is_HTTP_POST_To_Api_And_Request_Succeeds() {
+ when(request.getPathInfo()).thenReturn("/api/NEW_PARAM?val=blah");
+ internalServlet.doPost(request, response);
+ verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ }
+
+ @Test
public void Given_Request_Is_HTTP_POST_With_Incorrect_Endpoint_Then_Not_Found_Error_Is_Generated()
throws Exception {
when(request.getPathInfo()).thenReturn("/incorrect/");
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java
index 8bbf231a..8c48d705 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java
@@ -34,9 +34,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
@@ -81,7 +78,6 @@ public class SynchronizerTaskTest {
private CloseableHttpResponse response;
private SynchronizerTask synchronizerTask;
- private ExecutorService executorService;
private static EntityManagerFactory emf;
private static EntityManager em;
@@ -116,15 +112,10 @@ public class SynchronizerTaskTest {
synchronizerTask = Mockito.spy(SynchronizerTask.getSynchronizer());
doReturn(2).when(synchronizerTask).lookupState();
-
- executorService = Executors.newCachedThreadPool();
- executorService.execute(synchronizerTask);
}
@After
- public void tearDown() throws InterruptedException {
- executorService.shutdown();
- executorService.awaitTermination(2, TimeUnit.SECONDS);
+ public void tearDown() {
}
@Test
@@ -193,6 +184,7 @@ public class SynchronizerTaskTest {
Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "application/vnd.dmaap-dr.provfeed-full; version=1.0"));
mockResponseFromGet();
+ synchronizerTask.run();
}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRouteTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRouteTest.java
new file mode 100644
index 00000000..7ef52ff8
--- /dev/null
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRouteTest.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dmaap.datarouter.provisioning.beans;
+
+import java.sql.SQLException;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.dmaap.datarouter.provisioning.utils.DB;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class EgressRouteTest {
+
+ private EgressRoute egressRoute;
+
+ private static EntityManagerFactory emf;
+ private static EntityManager em;
+ private DB db;
+
+ @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 {
+ db = new DB();
+ egressRoute = new EgressRoute(2, 1);
+ }
+
+ @Test
+ public void Verify_NetworkRoute_Is_Added_Successfully() throws SQLException {
+ Assert.assertEquals(1, EgressRoute.getAllEgressRoutes().size());
+ egressRoute.doInsert(db.getConnection());
+ Assert.assertEquals(2, EgressRoute.getAllEgressRoutes().size());
+ egressRoute.doDelete(db.getConnection());
+ }
+
+ @Test
+ public void Verify_NetworkRoute_Is_Removed_Successfully() throws SQLException {
+ Assert.assertEquals(1, EgressRoute.getAllEgressRoutes().size());
+ EgressRoute egressRoute = new EgressRoute(1, 1);
+ egressRoute.doDelete(db.getConnection());
+ Assert.assertEquals(0, EgressRoute.getAllEgressRoutes().size());
+ }
+
+ @Test
+ public void Verify_NetworkRoute_Is_Updated_Successfully() throws SQLException {
+ EgressRoute egressRoute = new EgressRoute(1, 1);
+ EgressRoute egressRoute1 = new EgressRoute(1, 1);
+ Assert.assertEquals(egressRoute.hashCode(), egressRoute1.hashCode());
+ Assert.assertEquals(egressRoute, egressRoute1);
+ Assert.assertEquals(egressRoute.toString(), egressRoute1.toString());
+ }
+} \ No newline at end of file
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRouteTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRouteTest.java
new file mode 100644
index 00000000..df786b55
--- /dev/null
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRouteTest.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dmaap.datarouter.provisioning.beans;
+
+import java.sql.SQLException;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.dmaap.datarouter.provisioning.utils.DB;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class NetworkRouteTest {
+
+ private NetworkRoute networkRoute;
+
+ private static EntityManagerFactory emf;
+ private static EntityManager em;
+ private DB db;
+
+ @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 {
+ db = new DB();
+ networkRoute = new NetworkRoute("node01.","node03.","node02.");
+ }
+
+ @Test
+ public void Verify_NetworkRoute_Is_Added_Successfully() throws SQLException {
+ Assert.assertEquals(1, NetworkRoute.getAllNetworkRoutes().size());
+ networkRoute.doInsert(db.getConnection());
+ Assert.assertEquals(2, NetworkRoute.getAllNetworkRoutes().size());
+ networkRoute.doDelete(db.getConnection());
+ }
+
+ @Test
+ public void Verify_NetworkRoute_Is_Removed_Successfully() throws SQLException {
+ Assert.assertEquals(1, NetworkRoute.getAllNetworkRoutes().size());
+ NetworkRoute networkRoute = new NetworkRoute("stub_from.", "stub_to.");
+ networkRoute.doDelete(db.getConnection());
+ Assert.assertEquals(0, NetworkRoute.getAllNetworkRoutes().size());
+ }
+
+ @Test
+ public void Verify_NetworkRoute_Is_Updated_Successfully() throws SQLException {
+ NetworkRoute networkRoute = new NetworkRoute("stub_from.", "stub_to.", "node02.");
+ networkRoute.doUpdate(db.getConnection());
+ //Assert.assertTrue(NetworkRoute.getAllNetworkRoutes().contains(networkRoute));
+ for (NetworkRoute net :
+ NetworkRoute.getAllNetworkRoutes()) {
+ Assert.assertEquals(5, net.getVianode());
+ }
+ NetworkRoute networkRoute1 = new NetworkRoute("stub_from.", "stub_to.", "node02.");
+ Assert.assertEquals(networkRoute.hashCode(), networkRoute1.hashCode());
+ Assert.assertEquals(networkRoute, networkRoute1);
+ Assert.assertEquals(networkRoute.toString(), networkRoute1.toString());
+ }
+} \ No newline at end of file
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DbTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DbTest.java
new file mode 100644
index 00000000..056469a8
--- /dev/null
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DbTest.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dmaap.datarouter.provisioning.utils;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class DbTest {
+ private static EntityManagerFactory emf;
+ private static EntityManager em;
+
+ private DB db = new DB();
+
+ @BeforeClass
+ public static void init() {
+ emf = Persistence.createEntityManagerFactory("db-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();
+ }
+
+ @Test
+ public void Verify_DB_Is_Initialised_Successfully() {
+ Assert.assertTrue(db.runRetroFits());
+ }
+
+}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java
index 4dd1b471..ae81f15d 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java
@@ -24,6 +24,7 @@
package org.onap.dmaap.datarouter.provisioning.utils;
import java.io.CharArrayWriter;
+import java.io.IOException;
import java.io.Writer;
import org.json.JSONArray;
import org.json.JSONTokener;
@@ -50,8 +51,7 @@ public class LOGJSONObjectTest {
}
@Test
- public void Construct_JSONObject_From_A_Subset_Of_Values_From_Another_JSONObject()
- throws Exception {
+ public void Construct_JSONObject_From_A_Subset_Of_Values_From_Another_JSONObject() {
Map<String, Object> map = new HashMap<>();
map.put("key1", "value1");
map.put("key2", "value2");
@@ -63,48 +63,41 @@ public class LOGJSONObjectTest {
}
@Test
- public void Construct_JSONObject_From_A_JSONTokener()
- throws Exception {
+ public void Construct_JSONObject_From_A_JSONTokener() {
JSONTokener x = new JSONTokener("{\"key1\":\"value1\",\"key3\":\"value3\"}");
LOGJSONObject logJObject = new LOGJSONObject(x);
assertThat(logJObject.toString(), is("{\"key1\":\"value1\",\"key3\":\"value3\"}"));
}
@Test
- public void Construct_JSONObject_From_A_Bean_Object_And_Populate_From_Its_Getters_And_Setters()
- throws Exception {
+ public void Construct_JSONObject_From_A_Bean_Object_And_Populate_From_Its_Getters_And_Setters() {
Map<String, Object> map = new HashMap<>();
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3");
- Object bean = map;
- LOGJSONObject logJObject = new LOGJSONObject(bean);
+ LOGJSONObject logJObject = new LOGJSONObject((Object) map);
assertThat(logJObject.toString(), is("{\"empty\":false}"));
}
@Test
- public void Given_Method_Is_Accumulate_And_Value_Is_Valid_Put_Value_Into_New_JSONArray()
- throws Exception {
+ public void Given_Method_Is_Accumulate_And_Value_Is_Valid_Put_Value_Into_New_JSONArray() {
Map<String, Object> map = new HashMap<>();
map.put("key", 3);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
logJObject.accumulate(s, null);
assertThat(logJObject.get("key").toString(), is("[3,null]"));
}
@Test
- public void Given_Method_Is_Accumulate_And_Value_Is_Null_Dont_Add_Key_Value_Pair()
- throws Exception {
+ public void Given_Method_Is_Accumulate_And_Value_Is_Null_Dont_Add_Key_Value_Pair() {
String s = "key";
logJO.accumulate(s, null);
assertThat(logJO.has("key"), is(false));
}
@Test
- public void Given_Method_Is_Append_And_Value_Is_Null_Append_New_Value()
- throws Exception {
+ public void Given_Method_Is_Append_And_Value_Is_Null_Append_New_Value() {
String s = "key";
double d = 2.0;
logJO.append(s, d);
@@ -113,417 +106,334 @@ public class LOGJSONObjectTest {
@Test
- public void Given_Method_Is_DoubleToString_And_Value_Is_NaN_Return_Null()
- throws Exception {
+ public void Given_Method_Is_DoubleToString_And_Value_Is_NaN_Return_Null() {
double d = 2.0;
- assertThat(logJO.doubleToString(d), is("2"));
+ assertThat(LOGJSONObject.doubleToString(d), is("2"));
}
@Test
- public void Given_Method_Is_GetBoolean_And_Value_Is_False_Return_False()
- throws Exception {
+ public void Given_Method_Is_GetBoolean_And_Value_Is_False_Return_False() {
Map<String, Object> map = new HashMap<>();
map.put("key", false);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.getBoolean(s), is(false));
}
@Test
- public void Given_Method_Is_GetBoolean_And_Value_Is_True_Return_True()
- throws Exception {
+ public void Given_Method_Is_GetBoolean_And_Value_Is_True_Return_True() {
Map<String, Object> map = new HashMap<>();
map.put("key", true);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.getBoolean(s), is(true));
}
@Test
- public void Given_Method_Is_GetDouble_And_Value_Is_A_Double_Return_Value()
- throws Exception {
+ public void Given_Method_Is_GetDouble_And_Value_Is_A_Double_Return_Value() {
Map<String, Object> map = new HashMap<>();
map.put("key", 2.0);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.getDouble(s), is(2.0));
}
@Test
- public void Given_Method_Is_GetInt_And_Value_Is_An_Int_Return_Value()
- throws Exception {
+ public void Given_Method_Is_GetInt_And_Value_Is_An_Int_Return_Value() {
Map<String, Object> map = new HashMap<>();
map.put("key", 3);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.getInt(s), is(3));
}
@Test
- public void Given_Method_Is_GetJSONArray_And_Value_Is_A_JSONArray_Return_Value()
- throws Exception {
+ public void Given_Method_Is_GetJSONArray_And_Value_Is_A_JSONArray_Return_Value() {
JSONArray jA = new JSONArray();
Map<String, Object> map = new HashMap<>();
map.put("key", jA);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.getJSONArray(s), is(jA));
}
@Test
- public void Given_Method_Is_GetJSONObject_And_Value_Is_A_JSONObject_Return_Value()
- throws Exception {
+ public void Given_Method_Is_GetJSONObject_And_Value_Is_A_JSONObject_Return_Value() {
LOGJSONObject logJObj = new LOGJSONObject();
logJObj.put("stub_key", 1);
Map<String, Object> map = new HashMap<>();
map.put("key", logJObj);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.getJSONObject(s), is(logJObj));
}
@Test
- public void Given_Method_Is_GetLong_And_Value_Is_A_Long_Return_Value()
- throws Exception {
+ public void Given_Method_Is_GetLong_And_Value_Is_A_Long_Return_Value() {
long l = 5;
Map<String, Object> map = new HashMap<>();
map.put("key", l);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.getLong(s), is(5L));
}
@Test
- public void Given_Method_Is_getNames_And_Value_Is_A_LOGJSONObject_Return_StringArray()
- throws Exception {
+ public void Given_Method_Is_getNames_And_Value_Is_A_LOGJSONObject_Return_StringArray() {
LOGJSONObject logJObj = new LOGJSONObject();
logJObj.put("name1", "elyk");
String[] sArray = new String[logJObj.length()];
sArray[0] = "name1";
- LOGJSONObject logJObject = new LOGJSONObject();
-
- assertThat(logJObject.getNames(logJObj), is(sArray));
+ assertThat(LOGJSONObject.getNames(logJObj), is(sArray));
}
@Test
- public void Given_Method_Is_GetString_And_Value_Is_A_String_Return_Value()
- throws Exception {
+ public void Given_Method_Is_GetString_And_Value_Is_A_String_Return_Value() {
String val = "value";
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.getString(s), is("value"));
}
@Test
- public void Given_Method_Is_Increment_And_Value_Is_Null_Put_Defualt_Value()
- throws Exception {
+ public void Given_Method_Is_Increment_And_Value_Is_Null_Put_Defualt_Value() {
Map<String, Object> mapResult = new HashMap<>();
mapResult.put("key", 1);
LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
-
String val = null;
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
logJObject.increment(s);
assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
}
@Test
- public void Given_Method_Is_Increment_And_Value_Is_An_Int_Put_Value_Plus_One()
- throws Exception {
+ public void Given_Method_Is_Increment_And_Value_Is_An_Int_Put_Value_Plus_One() {
Map<String, Object> mapResult = new HashMap<>();
mapResult.put("key", 3);
LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
-
int val = 2;
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
logJObject.increment(s);
assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
}
@Test
- public void Given_Method_Is_Increment_And_Value_Is_A_Long_Put_Value_Plus_One()
- throws Exception {
+ public void Given_Method_Is_Increment_And_Value_Is_A_Long_Put_Value_Plus_One() {
Map<String, Object> mapResult = new HashMap<>();
mapResult.put("key", 4L);
LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
-
long val = 3;
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
logJObject.increment(s);
assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
}
@Test
- public void Given_Method_Is_Increment_And_Value_Is_A_Double_Put_Value_Plus_One()
- throws Exception {
+ public void Given_Method_Is_Increment_And_Value_Is_A_Double_Put_Value_Plus_One() {
Map<String, Object> mapResult = new HashMap<>();
mapResult.put("key", 5.0);
LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
-
double val = 4.0;
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
logJObject.increment(s);
assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
}
@Test
- public void Given_Method_Is_Increment_And_Value_Is_A_Float_Put_Value_Plus_One()
- throws Exception {
+ public void Given_Method_Is_Increment_And_Value_Is_A_Float_Put_Value_Plus_One() {
Map<String, Object> mapResult = new HashMap<>();
mapResult.put("key", 5.0);
LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
-
float val = 4.0f;
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
logJObject.increment(s);
assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
}
@Test
- public void Given_Method_Is_Names_And_Object_Contains_Keys_Put_Keys_Into_New_JSONArray()
- throws Exception {
+ public void Given_Method_Is_Names_And_Object_Contains_Keys_Put_Keys_Into_New_JSONArray() {
JSONArray ja = new JSONArray();
ja.put("key");
-
String val = "value";
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
- String s = "key";
assertThat(logJObject.names().get(0), is(ja.get(0)));
}
@Test
- public void Given_Method_Is_NumberToString_And_Number_is_Not_Null_Return_Reformatted_Number_As_String()
- throws Exception {
+ public void Given_Method_Is_NumberToString_And_Number_is_Not_Null_Return_Reformatted_Number_As_String() {
Number num = 3.0;
-
String val = "value";
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.numberToString(num), is("3"));
}
@Test
- public void Given_Method_Is_OptBoolean_And_Value_is_Boolean_Return_Value()
- throws Exception {
+ public void Given_Method_Is_OptBoolean_And_Value_is_Boolean_Return_Value() {
boolean val = true;
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.optBoolean(s, false), is(true));
}
@Test
- public void Given_Method_Is_OptBoolean_And_Value_is_Not_Boolean_Return_Default_Value()
- throws Exception {
+ public void Given_Method_Is_OptBoolean_And_Value_is_Not_Boolean_Return_Default_Value() {
String val = "not_boolean";
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.optBoolean(s, false), is(false));
}
@Test
- public void Given_Method_Is_OptDouble_And_Value_is_Double_Return_Value()
- throws Exception {
+ public void Given_Method_Is_OptDouble_And_Value_is_Double_Return_Value() {
double val = 2.0;
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.optDouble(s, 0.0), is(2.0));
}
@Test
- public void Given_Method_Is_OptDouble_And_Value_is_Not_Double_Return_Default_Value()
- throws Exception {
+ public void Given_Method_Is_OptDouble_And_Value_is_Not_Double_Return_Default_Value() {
String val = "not_double";
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.optDouble(s, 0.0), is(0.0));
}
@Test
- public void Given_Method_Is_OptInt_And_Value_is_Int_Return_Value()
- throws Exception {
+ public void Given_Method_Is_OptInt_And_Value_is_Int_Return_Value() {
int val = 1;
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.optInt(s, 0), is(1));
}
@Test
- public void Given_Method_Is_OptInt_And_Value_Is_Null_Return_Default_Value()
- throws Exception {
+ public void Given_Method_Is_OptInt_And_Value_Is_Null_Return_Default_Value() {
Map<String, Object> map = new HashMap<>();
map.put("key", null);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.optInt(s, 0), is(0));
}
@Test
- public void Given_Method_Is_OptLong_And_Value_is_Long_Return_Value()
- throws Exception {
+ public void Given_Method_Is_OptLong_And_Value_is_Long_Return_Value() {
long val = 4;
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.optLong(s, 0), is(4L));
}
@Test
- public void Given_Method_Is_OptLong_And_Value_is_Not_Long_Return_Default_Value()
- throws Exception {
+ public void Given_Method_Is_OptLong_And_Value_is_Not_Long_Return_Default_Value() {
Map<String, Object> map = new HashMap<>();
map.put("key", null);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.optLong(s, 0), is(0L));
}
@Test
- public void Given_Method_Is_OptString_And_Value_is_String_Return_Value()
- throws Exception {
+ public void Given_Method_Is_OptString_And_Value_is_String_Return_Value() {
String val = "value";
Map<String, Object> map = new HashMap<>();
map.put("key", val);
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.optString(s, "default_value"), is("value"));
}
@Test
- public void Given_Method_Is_putOnce_And_KeyValuePair_Does_Not_Exist_In_logJObject_Put_KeyValuePair_Into_logJObject()
- throws Exception {
+ public void Given_Method_Is_putOnce_And_KeyValuePair_Does_Not_Exist_In_logJObject_Put_KeyValuePair_Into_logJObject() {
String val = "value";
Map<String, Object> map = new HashMap<>();
LOGJSONObject logJObject = new LOGJSONObject(map);
-
String s = "key";
assertThat(logJObject.putOnce(s, val).get("key"), is("value"));
}
@Test
- public void Given_Method_Is_StringToValue_And_Value_Is_Number_Return_Number()
- throws Exception {
+ public void Given_Method_Is_StringToValue_And_Value_Is_Number_Return_Number() {
String val = "312";
Map<String, Object> map = new HashMap<>();
- LOGJSONObject logJObject = new LOGJSONObject(map);
-
- assertThat(logJObject.stringToValue(val), is(312));
+ assertThat(LOGJSONObject.stringToValue(val), is(312));
}
@Test
- public void Given_Method_Is_ToJSONArray_And_KeyValue_Exists_Return_Value_Array()
- throws Exception {
+ public void Given_Method_Is_ToJSONArray_And_KeyValue_Exists_Return_Value_Array() {
JSONArray names = new JSONArray();
Map<String, Object> map = new HashMap<>();
map.put("name", "value");
names.put("name");
LOGJSONObject logJObject = new LOGJSONObject(map);
-
assertThat(logJObject.toJSONArray(names).get(0), is("value"));
}
@Test
- public void Given_Method_Is_ValueToString_And_Value_Is_JSONArray_Return_Value_To_String()
- throws Exception {
+ public void Given_Method_Is_ValueToString_And_Value_Is_JSONArray_Return_Value_To_String() {
JSONArray val = new JSONArray();
- Map<String, Object> map = new HashMap<>();
- map.put("key", "value");
val.put("value");
- LOGJSONObject logJObject = new LOGJSONObject(map);
-
- assertThat(logJObject.valueToString(val), is("[\"value\"]"));
+ assertThat(LOGJSONObject.valueToString(val), is("[\"value\"]"));
}
@Test
- public void Given_Method_Is_writeValue_And_Value_IS_Not_Null_Return_Writer_With_Value()
- throws Exception {
+ public void Given_Method_Is_writeValue_And_Value_IS_Not_Null_Return_Writer_With_Value() throws IOException {
Writer writer = new CharArrayWriter();
String val = "value";
- Map<String, Object> map = new HashMap<>();
- map.put("key", "value");
- LOGJSONObject logJObject = new LOGJSONObject(map);
-
- assertThat(logJObject.writeValue(writer, val, 3, 1).toString(), is("\"value\""));
+ assertThat(LOGJSONObject.writeValue(writer, val, 3, 1).toString(), is("\"value\""));
}
@Test
- public void Given_Method_Is_write_And_Length_Of_logJObject_Is_One_Write_Value_With_Indent()
- throws Exception {
+ public void Given_Method_Is_write_And_Length_Of_logJObject_Is_One_Write_Value_With_Indent() {
Writer writer = new CharArrayWriter();
- String val = "value";
Map<String, Object> map = new HashMap<>();
map.put("key", "value");
LOGJSONObject logJObject = new LOGJSONObject(map);
-
assertThat(logJObject.write(writer, 3, 1).toString(), is("{\"key\": \"value\"}"));
}
@Test
- public void Given_Method_Is_write_And_Length_Of_logJObject_Is_Not_One_Or_Zero_Write_Value_With_New_Indent()
- throws Exception {
+ public void Given_Method_Is_write_And_Length_Of_logJObject_Is_Not_One_Or_Zero_Write_Value_With_New_Indent() {
Writer writer = new CharArrayWriter();
- String val = "value";
Map<String, Object> map = new HashMap<>();
map.put("key", "value");
map.put("key1", "value1");
LOGJSONObject logJObject = new LOGJSONObject(map);
-
assertThat(logJObject.write(writer, 3, 1).toString(), is("{\n \"key1\": \"value1\",\n \"key\": \"value\"\n }"));
}
}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoaderTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoaderTest.java
index 7f6d7de6..a15509b4 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoaderTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoaderTest.java
@@ -20,32 +20,29 @@
package org.onap.dmaap.datarouter.provisioning.utils;
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
+import org.junit.Test;
import org.junit.runner.RunWith;
-
import org.onap.dmaap.datarouter.provisioning.InternalServlet;
import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-
-import static org.junit.Assert.assertFalse;
-
-import org.junit.Test;
-
-
-
@RunWith(PowerMockRunner.class)
@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.provisioning.beans.Parameters")
public class LogfileLoaderTest {
@@ -53,10 +50,18 @@ public class LogfileLoaderTest {
private static EntityManagerFactory emf;
private static EntityManager em;
private LogfileLoader lfl = LogfileLoader.getLoader();
+ private File testLog;
- @Rule
- public TemporaryFolder folder = new TemporaryFolder();
+ @Before
+ public void setUp() throws Exception {
+ testLog = new File(System.getProperty("user.dir") + "/src/test/resources/IN.test_prov_logs");
+ prepFile(testLog);
+ }
+ @After
+ public void tearDown() throws IOException {
+ Files.deleteIfExists(testLog.toPath());
+ }
@BeforeClass
public static void init() {
@@ -68,7 +73,6 @@ public class LogfileLoaderTest {
InternalServlet internalServlet = new InternalServlet();
}
-
@AfterClass
public static void tearDownClass() {
em.clear();
@@ -76,42 +80,47 @@ public class LogfileLoaderTest {
emf.close();
}
-
@Test
- public void Verify_File_Processing_when_Req_Type_LOG() throws IOException {
- String fileContent = "2018-08-29-10-10-10-543.|LOG|1|1|url/file123|method|1|1|type|1|128.0.0.9|user123|2|1|1|1|other|1";
- int[] actual = lfl.process(prepFile(fileContent, "file1"));
- int[] expect = {0, 1};
+ public void Verify_File_Processing_Returns_Expected_Array() {
+ int[] actual = lfl.process(testLog);
+ int[] expect = {5, 7};
Assert.assertArrayEquals(expect, actual);
+ Assert.assertNotNull(lfl.getBitSet());
+ Assert.assertTrue(lfl.isIdle());
}
-
@Test
- public void Verify_File_Processing_when_Req_Type_EXP() throws IOException{
- String fileContent = "2018-08-29-10-10-10-543.|EXP|1|1|1|'url/file123'|method|ctype|3|other|4";
- int[] actual = lfl.process(prepFile(fileContent, "file2"));
- int[] expect = {0, 1};
- Assert.assertArrayEquals(expect, actual);
+ public void Verify_Records_Prune_When_Record_Count_Is_Less_Then_Threshold() {
+ lfl.process(testLog);
+ PowerMockito.mockStatic(Parameters.class);
+ PowerMockito.when(Parameters.getParameter(Parameters.PROV_LOG_RETENTION)).thenReturn(new Parameters(Parameters.PROV_LOG_RETENTION, "0"));
+ PowerMockito.when(Parameters.getParameter(Parameters.DEFAULT_LOG_RETENTION)).thenReturn(new Parameters(Parameters.DEFAULT_LOG_RETENTION, "1000000"));
+ assertFalse(lfl.pruneRecords());
}
-
@Test
- public void Verify_Records_Prune_When_Record_Count_Is_Less_Then_Threshold() throws IOException{
- String fileContent = "2018-08-29-10-10-10-543.|PUB|1|1|https://dmaap-dr-prov:8443/publish/1/file123/|POST|application/vnd.att-dr.feed|2|128.0.0.9|user123|200";
- lfl.process(prepFile(fileContent, "file3"));
+ public void Verify_Records_Prune_When_Record_Count_Is_Greater_Then_Threshold() {
+ lfl.process(testLog);
PowerMockito.mockStatic(Parameters.class);
PowerMockito.when(Parameters.getParameter(Parameters.PROV_LOG_RETENTION)).thenReturn(new Parameters(Parameters.PROV_LOG_RETENTION, "0"));
- assertFalse(lfl.pruneRecords());
+ PowerMockito.when(Parameters.getParameter(Parameters.DEFAULT_LOG_RETENTION)).thenReturn(new Parameters(Parameters.DEFAULT_LOG_RETENTION, "1"));
+ assertTrue(lfl.pruneRecords());
}
- private File prepFile(String content, String fileName) throws IOException{
- File file1 = folder.newFile(fileName);
- try (FileWriter fileWriter = new FileWriter(file1)) {
- fileWriter.write(content);
- }catch (IOException e){
+ private void prepFile(File logFile) {
+ String testLogs = "2018-08-29-10-10-10-543.|LOG|1|1|https://dmaap-dr-prov:/url/file123|POST|application/vnd.att-dr.feed|100|mockType|file123|https://dmaap-dr-prov|user123|200|1|1|200|2|2\n"
+ + "2018-08-29-10-10-10-543.|EXP|1|1|1|'url/file123'|PUT|null|3|new reason|4\n"
+ + "2018-08-29-10-10-10-543.|PUB|1|1|https://dmaap-dr-prov:8443/publish/1/file123/|POST|application/vnd.att-dr.feed|2|128.0.0.9|user123|200\n"
+ + "2018-08-29-10-10-10-543.|PBF|1|1|https://dmaap-dr-prov:8443/publish/1/file123/|POST|application/vnd.att-dr.feed|100|100|128.0.0.9|user123|failed\n"
+ + "2018-08-29-10-10-10-543.|DLX|1|1|1|100|100\n"
+ + "2018-08-29-10-10-10-543.|Bad Record|||\n"
+ + "2018-08-29-10-10-10-543.|DEL|2|1|2|https://dmaap-dr-prov:8443/publish/1/file123/|PUT|application/vnd.att-dr.feed|100|user123|200|123456";
+ try (FileWriter fileWriter = new FileWriter(logFile)) {
+ fileWriter.write(testLogs);
+ }
+ catch (IOException e){
System.out.println(e.getMessage());
}
- return file1;
}
}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTaskTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTaskTest.java
new file mode 100644
index 00000000..604b4c0a
--- /dev/null
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTaskTest.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dmaap.datarouter.provisioning.utils;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class PurgeLogDirTaskTest {
+
+ private static EntityManagerFactory emf;
+ private static EntityManager em;
+ private PurgeLogDirTask purgeLogDirTask = new PurgeLogDirTask();
+ private File testLog;
+
+ @Before
+ public void setUp() throws Exception {
+ testLog = new File(System.getProperty("user.dir") + "/src/test/resources/IN.test_prov_logs");
+ prepFile(testLog);
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ Files.deleteIfExists(testLog.toPath());
+ }
+
+ @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();
+ }
+
+ @Test
+ public void Verify_Logs_Are_Purged() {
+ purgeLogDirTask.run();
+ }
+
+ private void prepFile(File logFile) {
+ try (FileWriter fileWriter = new FileWriter(logFile)) {
+ fileWriter.write("2018-08-29-10-10-10-543.|LOG|1|1|https://dmaap-dr-prov:/url/file123|POST|application/vnd.att-dr.feed|100|mockType|file123|https://dmaap-dr-prov|user123|200|1|1|200|2|2\n");
+ }
+ catch (IOException e){
+ System.out.println(e.getMessage());
+ }
+ }
+}
diff --git a/datarouter-prov/src/test/resources/META-INF/persistence.xml b/datarouter-prov/src/test/resources/META-INF/persistence.xml
index 83813e23..2cb798af 100755
--- a/datarouter-prov/src/test/resources/META-INF/persistence.xml
+++ b/datarouter-prov/src/test/resources/META-INF/persistence.xml
@@ -18,4 +18,18 @@
</properties>
</persistence-unit>
+ <persistence-unit name="db-unit-tests" transaction-type="RESOURCE_LOCAL">
+ <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
+ <properties>
+ <!-- Configuring JDBC properties -->
+ <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test1;DB_CLOSE_DELAY=-1"/>
+ <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
+ <!-- Hibernate properties -->
+ <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
+ <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+ <property name="hibernate.format_sql" value="false"/>
+ <property name="hibernate.show_sql" value="true"/>
+
+ </properties>
+ </persistence-unit>
</persistence>
diff --git a/datarouter-prov/src/test/resources/create.sql b/datarouter-prov/src/test/resources/create.sql
index a811847c..74b63242 100755
--- a/datarouter-prov/src/test/resources/create.sql
+++ b/datarouter-prov/src/test/resources/create.sql
@@ -180,10 +180,10 @@ INSERT INTO FEEDS(FEEDID, GROUPID, NAME, VERSION, DESCRIPTION, BUSINESS_DESCRIPT
VALUES (3, 1,'DeleteableAafFeed','v0.1', 'AAF Feed3 for testing', 'AAF Feed3 for testing', 'auth_class', 'pub','self_link','publish_link','subscribe_link','log_link','*');
insert into INGRESS_ROUTES(SEQUENCE, FEEDID , USERID, SUBNET, NODESET)
-VALUES (1,1,'user',null,2);
+VALUES (1,1,'user','172.100.0.0/25',2);
insert into INGRESS_ROUTES(SEQUENCE, FEEDID , USERID, SUBNET, NODESET)
-VALUES (2,1,'user',null,2);
+VALUES (2,1,'user2',null,2);
insert into NODESETS(SETID, NODEID)
VALUES (1,1);
diff --git a/datarouter-prov/src/test/resources/h2Database.properties b/datarouter-prov/src/test/resources/h2Database.properties
index 9c63aea4..991fadc5 100755
--- a/datarouter-prov/src/test/resources/h2Database.properties
+++ b/datarouter-prov/src/test/resources/h2Database.properties
@@ -27,7 +27,8 @@ org.onap.dmaap.datarouter.db.url = jdbc:h2:mem:test;DB
org.onap.dmaap.datarouter.provserver.isaddressauthenabled = true
org.onap.dmaap.datarouter.provserver.https.relaxation = false
org.onap.dmaap.datarouter.provserver.accesslog.dir = unit-test-logs
-org.onap.dmaap.datarouter.provserver.spooldir = unit-test-logs/spool
+org.onap.dmaap.datarouter.provserver.spooldir = src/test/resources
+org.onap.dmaap.datarouter.provserver.dbscripts = src/test/resources
org.onap.dmaap.datarouter.provserver.localhost = 127.0.0.1
org.onap.dmaap.datarouter.provserver.passwordencryption = PasswordEncryptionKey#@$%^&1234#
diff --git a/datarouter-prov/src/test/resources/sql_init_01.sql b/datarouter-prov/src/test/resources/sql_init_01.sql
new file mode 100755
index 00000000..1ac74a03
--- /dev/null
+++ b/datarouter-prov/src/test/resources/sql_init_01.sql
@@ -0,0 +1,146 @@
+CREATE TABLE FEEDS (
+ FEEDID INT UNSIGNED NOT NULL PRIMARY KEY,
+ GROUPID INT(10) UNSIGNED NOT NULL DEFAULT 0,
+ NAME VARCHAR(256) NOT NULL,
+ VERSION VARCHAR(20) NULL,
+ DESCRIPTION VARCHAR(1000),
+ BUSINESS_DESCRIPTION VARCHAR(1000) DEFAULT NULL,
+ AUTH_CLASS VARCHAR(32) NOT NULL,
+ PUBLISHER VARCHAR(8) NOT NULL,
+ SELF_LINK VARCHAR(256),
+ PUBLISH_LINK VARCHAR(256),
+ SUBSCRIBE_LINK VARCHAR(256),
+ LOG_LINK VARCHAR(256),
+ DELETED BOOLEAN DEFAULT FALSE,
+ LAST_MOD TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ SUSPENDED BOOLEAN DEFAULT FALSE,
+ CREATED_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ AAF_INSTANCE VARCHAR(256)
+);
+
+CREATE TABLE FEED_ENDPOINT_IDS (
+ FEEDID INT UNSIGNED NOT NULL,
+ USERID VARCHAR(60) NOT NULL,
+ PASSWORD VARCHAR(100) NOT NULL
+);
+
+CREATE TABLE FEED_ENDPOINT_ADDRS (
+ FEEDID INT UNSIGNED NOT NULL,
+ ADDR VARCHAR(44) NOT NULL
+);
+
+CREATE TABLE SUBSCRIPTIONS (
+ SUBID INT UNSIGNED NOT NULL PRIMARY KEY,
+ FEEDID INT UNSIGNED NOT NULL,
+ GROUPID INT(10) UNSIGNED NOT NULL DEFAULT 0,
+ DELIVERY_URL VARCHAR(256),
+ FOLLOW_REDIRECTS TINYINT(1) NOT NULL DEFAULT 0,
+ DELIVERY_USER VARCHAR(60),
+ DELIVERY_PASSWORD VARCHAR(100),
+ DELIVERY_USE100 BOOLEAN DEFAULT FALSE,
+ METADATA_ONLY BOOLEAN DEFAULT FALSE,
+ SUBSCRIBER VARCHAR(8) NOT NULL,
+ SELF_LINK VARCHAR(256),
+ LOG_LINK VARCHAR(256),
+ LAST_MOD TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ SUSPENDED BOOLEAN DEFAULT FALSE,
+ PRIVILEGED_SUBSCRIBER BOOLEAN DEFAULT FALSE,
+ CREATED_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ DECOMPRESS BOOLEAN DEFAULT FALSE,
+ AAF_INSTANCE VARCHAR(256)
+
+);
+
+CREATE TABLE PARAMETERS (
+ KEYNAME VARCHAR(32) NOT NULL PRIMARY KEY,
+ VALUE VARCHAR(4096) NOT NULL
+);
+
+CREATE TABLE LOG_RECORDS (
+ TYPE ENUM('pub', 'del', 'exp', 'pbf', 'dlx') NOT NULL,
+ EVENT_TIME BIGINT NOT NULL, /* time of the publish request */
+ PUBLISH_ID VARCHAR(64) NOT NULL, /* unique ID assigned to this publish attempt */
+ FEEDID INT UNSIGNED NOT NULL, /* pointer to feed in FEEDS */
+ REQURI VARCHAR(256) NOT NULL, /* request URI */
+ METHOD ENUM('DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'POST', 'TRACE') NOT NULL, /* HTTP method */
+ CONTENT_TYPE VARCHAR(256) NOT NULL, /* content type of published file */
+ CONTENT_LENGTH BIGINT NOT NULL, /* content length of published file */
+
+ FEED_FILEID VARCHAR(256), /* file ID of published file */
+ REMOTE_ADDR VARCHAR(40), /* IP address of publishing endpoint */
+ USER VARCHAR(50), /* user name of publishing endpoint */
+ STATUS SMALLINT, /* status code returned to delivering agent */
+
+ DELIVERY_SUBID INT UNSIGNED, /* pointer to subscription in SUBSCRIPTIONS */
+ DELIVERY_FILEID VARCHAR(256), /* file ID of file being delivered */
+ RESULT SMALLINT, /* result received from subscribing agent */
+
+ ATTEMPTS INT, /* deliveries attempted */
+ REASON ENUM('notRetryable', 'retriesExhausted', 'diskFull', 'other'),
+
+ RECORD_ID BIGINT UNSIGNED NOT NULL PRIMARY KEY, /* unique ID for this record */
+ CONTENT_LENGTH_2 BIGINT,
+ FILENAME VARCHAR(256), /* Name of the file being published on DR */
+
+) ENGINE = MyISAM;
+
+CREATE TABLE INGRESS_ROUTES (
+ SEQUENCE INT UNSIGNED NOT NULL,
+ FEEDID INT UNSIGNED NOT NULL,
+ USERID VARCHAR(50),
+ SUBNET VARCHAR(44),
+ NODESET INT UNSIGNED NOT NULL
+);
+
+CREATE TABLE EGRESS_ROUTES (
+ SUBID INT UNSIGNED NOT NULL PRIMARY KEY,
+ NODEID INT UNSIGNED NOT NULL
+);
+
+CREATE TABLE NETWORK_ROUTES (
+ FROMNODE INT UNSIGNED NOT NULL,
+ TONODE INT UNSIGNED NOT NULL,
+ VIANODE INT UNSIGNED NOT NULL
+);
+
+CREATE TABLE NODESETS (
+ SETID INT UNSIGNED NOT NULL,
+ NODEID INT UNSIGNED NOT NULL
+);
+
+CREATE TABLE NODES (
+ NODEID INT UNSIGNED NOT NULL PRIMARY KEY,
+ NAME VARCHAR(255) NOT NULL,
+ ACTIVE BOOLEAN DEFAULT TRUE
+);
+
+CREATE TABLE GROUPS (
+ GROUPID INT UNSIGNED NOT NULL PRIMARY KEY,
+ AUTHID VARCHAR(100) NOT NULL,
+ NAME VARCHAR(50) NOT NULL,
+ DESCRIPTION VARCHAR(255),
+ CLASSIFICATION VARCHAR(20) NOT NULL,
+ MEMBERS TINYTEXT,
+ LAST_MOD TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+);
+
+INSERT INTO PARAMETERS VALUES
+ ('ACTIVE_POD', 'dmaap-dr-prov'),
+ ('PROV_ACTIVE_NAME', 'dmaap-dr-prov'),
+ ('STANDBY_POD', ''),
+ ('PROV_NAME', 'dmaap-dr-prov'),
+ ('NODES', 'dmaap-dr-node'),
+ ('PROV_DOMAIN', ''),
+ ('DELIVERY_INIT_RETRY_INTERVAL', '10'),
+ ('DELIVERY_MAX_AGE', '86400'),
+ ('DELIVERY_MAX_RETRY_INTERVAL', '3600'),
+ ('DELIVERY_FILE_PROCESS_INTERVAL', '600'),
+ ('DELIVERY_RETRY_RATIO', '2'),
+ ('LOGROLL_INTERVAL', '30'),
+ ('PROV_AUTH_ADDRESSES', 'dmaap-dr-prov|dmaap-dr-node'),
+ ('PROV_AUTH_SUBJECTS', ''),
+ ('PROV_MAXFEED_COUNT', '10000'),
+ ('PROV_MAXSUB_COUNT', '100000'),
+ ('PROV_REQUIRE_CERT', 'false'),
+ ('PROV_REQUIRE_SECURE', 'true'),
+ ('_INT_VALUES', 'LOGROLL_INTERVAL|PROV_MAXFEED_COUNT|PROV_MAXSUB_COUNT|DELIVERY_INIT_RETRY_INTERVAL|DELIVERY_MAX_RETRY_INTERVAL|DELIVERY_RETRY_RATIO|DELIVERY_MAX_AGE|DELIVERY_FILE_PROCESS_INTERVAL'); \ No newline at end of file