aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-node/src/test
diff options
context:
space:
mode:
authorsunil unnava <su622b@att.com>2019-07-25 14:21:23 +0000
committerGerrit Code Review <gerrit@onap.org>2019-07-25 14:21:23 +0000
commitb10c179229cea56e36a2fb9b6f2c17baf0d83f13 (patch)
tree1876eba2027df9a685daaa0467fde038100bc379 /datarouter-node/src/test
parent06271b9df78dadfdab95dc2f6f853cdaa3148d9d (diff)
parentf09604a09059d6c3ecf05b253c9058c1a2e81ca2 (diff)
Merge "FINAL unit test covergae commit"
Diffstat (limited to 'datarouter-node/src/test')
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java48
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigManagerTest.java79
-rw-r--r--datarouter-node/src/test/resources/node_test.properties103
3 files changed, 197 insertions, 33 deletions
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java
index a0f05779..0123c315 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java
@@ -20,15 +20,9 @@
package org.onap.dmaap.datarouter.node;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.OutputStream;
+import java.io.ByteArrayOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -42,14 +36,12 @@ import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({DeliveryTask.class})
+@PrepareForTest({URL.class})
public class DeliveryTaskTest {
@Mock
private DeliveryQueue deliveryQueue;
- private ExecutorService executorService;
-
@Before
public void setUp() throws Exception {
DestInfo destInfo = getPrivDestInfo();
@@ -57,14 +49,13 @@ public class DeliveryTaskTest {
URL url = PowerMockito.mock(URL.class);
HttpURLConnection urlConnection = PowerMockito.mock(HttpURLConnection.class);
- OutputStream outputStream = PowerMockito.mock(OutputStream.class);
- PowerMockito.whenNew(URL.class).withParameterTypes(String.class).withArguments(Mockito.anyString())
- .thenReturn(url);
- PowerMockito.when(urlConnection.getOutputStream()).thenReturn(outputStream);
- PowerMockito.when(url.openConnection()).thenReturn(urlConnection);
+ PowerMockito.whenNew(URL.class).withParameterTypes(String.class).withArguments(Mockito.anyString()).thenReturn(url);
+
+ PowerMockito.when(urlConnection.getOutputStream()).thenReturn(new ByteArrayOutputStream());
PowerMockito.when(urlConnection.getHeaderField(0)).thenReturn("PUT");
PowerMockito.when(urlConnection.getResponseCode()).thenReturn(200);
+ PowerMockito.when(url.openConnection()).thenReturn(urlConnection);
}
@After
@@ -74,8 +65,8 @@ public class DeliveryTaskTest {
@Test
public void Validate_Delivery_Task_Equals() {
- DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-datafile");
- DeliveryTask task2 = new DeliveryTask(deliveryQueue, "123456789.test-dr-datafile");
+ DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-node");
+ DeliveryTask task2 = new DeliveryTask(deliveryQueue, "123456789.test-dr-node");
Assert.assertEquals(task, task2);
Assert.assertEquals(task.hashCode(), task2.hashCode());
Assert.assertEquals(task.toString(), task2.toString());
@@ -91,29 +82,19 @@ public class DeliveryTaskTest {
Assert.assertEquals(task.getFileId(), task2.getFileId());
Assert.assertEquals(task.getAttempts(), task2.getAttempts());
Assert.assertEquals(task.getFollowRedirects(), task2.getFollowRedirects());
-
Assert.assertEquals(0, task.compareTo(task2));
}
@Test
- public void Validate_Delivery_Tasks_Success_For_Standard_File() throws InterruptedException {
+ public void Validate_Delivery_Tasks_Success_For_Standard_File() {
DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-node");
- executorService = Executors.newSingleThreadExecutor();
- executorService.execute(task);
-
- executorService.shutdown();
- executorService.awaitTermination(2, TimeUnit.SECONDS);
+ task.run();
}
@Test
- public void Validate_Delivery_Tasks_Success_For_Compressed_File() throws InterruptedException {
-
+ public void Validate_Delivery_Tasks_Success_For_Compressed_File() {
DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-node.gz");
- executorService = Executors.newSingleThreadExecutor();
- executorService.execute(task);
-
- executorService.shutdown();
- executorService.awaitTermination(2, TimeUnit.SECONDS);
+ task.run();
}
private DestInfo getPrivDestInfo() {
@@ -125,8 +106,9 @@ public class DeliveryTaskTest {
}
private DeliveryQueue mockDelvieryQueue(DestInfo destInfo) {
- DeliveryQueue mockedDeliveryQueue = mock(DeliveryQueue.class);
- when(mockedDeliveryQueue.getDestinationInfo()).thenReturn(destInfo);
+ DeliveryQueue mockedDeliveryQueue = PowerMockito.mock(DeliveryQueue.class);
+ PowerMockito.when(mockedDeliveryQueue.getDestinationInfo()).thenReturn(destInfo);
+ PowerMockito.when(mockedDeliveryQueue.getDestURL(Mockito.anyString())).thenReturn("https://dmaap-dr-node:8443/internal/publish");
return mockedDeliveryQueue;
}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigManagerTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigManagerTest.java
new file mode 100644
index 00000000..87c2bdf6
--- /dev/null
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigManagerTest.java
@@ -0,0 +1,79 @@
+/*-
+ * ============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.node;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.URL;
+import org.apache.commons.io.FileUtils;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore({"javax.net.ssl.*", "javax.security.auth.x500.X500Principal"})
+@PrepareForTest({InetAddress.class, URL.class})
+public class NodeConfigManagerTest {
+
+ private NodeConfigManager nodeConfigManager = NodeConfigManager.getInstance();
+
+ @BeforeClass
+ public static void init() {
+ System.setProperty("org.onap.dmaap.datarouter.node.properties", "src/test/resources/node_test.properties");
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws IOException {
+ FileUtils.deleteDirectory(new File(System.getProperty("user.dir") + "/src/test/resources/spool"));
+ FileUtils.deleteDirectory(new File(System.getProperty("user.dir") + "/src/test/resources/logs"));
+ }
+
+ @Test
+ public void Verify_NodeConfigMan_Getters() {
+ Assert.assertEquals("legacy", nodeConfigManager.getAafInstance());
+ Assert.assertEquals("src/test/resources/spool/f", nodeConfigManager.getSpoolDir());
+ Assert.assertEquals("src/test/resources/spool", nodeConfigManager.getSpoolBase());
+ Assert.assertEquals("jks", nodeConfigManager.getKSType());
+ Assert.assertEquals(8080, nodeConfigManager.getHttpPort());
+ Assert.assertEquals(8443, nodeConfigManager.getHttpsPort());
+ Assert.assertEquals(443, nodeConfigManager.getExtHttpsPort());
+ Assert.assertEquals("dmaap-dr-node", nodeConfigManager.getMyName());
+ Assert.assertEquals("https://dmaap-dr-prov:8443/internal/logs", nodeConfigManager.getEventLogUrl());
+ Assert.assertEquals("src/test/resources/logs/events", nodeConfigManager.getEventLogPrefix());
+ Assert.assertEquals(".log", nodeConfigManager.getEventLogSuffix());
+ Assert.assertEquals("src/test/resources/logs", nodeConfigManager.getLogDir());
+ Assert.assertEquals((86400000L * 30), nodeConfigManager.getLogRetention());
+ Assert.assertEquals(new String[] {"TLSv1.1", "TLSv1.2"}, nodeConfigManager.getEnabledprotocols());
+ Assert.assertEquals("org.onap.dmaap-dr.feed", nodeConfigManager.getAafType());
+ Assert.assertEquals("publish", nodeConfigManager.getAafAction());
+ Assert.assertEquals("https://aaf-onap-test.osaaf.org:8095", nodeConfigManager.getAafURL());
+ Assert.assertFalse(nodeConfigManager.getCadiEnabled());
+ Assert.assertFalse(nodeConfigManager.isShutdown());
+ Assert.assertFalse(nodeConfigManager.isConfigured());
+ }
+
+} \ No newline at end of file
diff --git a/datarouter-node/src/test/resources/node_test.properties b/datarouter-node/src/test/resources/node_test.properties
new file mode 100644
index 00000000..9e0cd994
--- /dev/null
+++ b/datarouter-node/src/test/resources/node_test.properties
@@ -0,0 +1,103 @@
+#-------------------------------------------------------------------------------
+# ============LICENSE_START==================================================
+# * org.onap.dmaap
+# * ===========================================================================
+# * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+# * ===========================================================================
+# * 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.
+# * ============LICENSE_END====================================================
+# *
+# * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+# *
+#-------------------------------------------------------------------------------
+#
+# Configuration parameters set at startup for the DataRouter node
+#
+# URL to retrieve dynamic configuration
+ProvisioningURL = https://dmaap-dr-prov:8443/internal/prov
+#
+# URL to upload PUB/DEL/EXP logs
+LogUploadURL = https://dmaap-dr-prov:8443/internal/logs
+#
+# The port number for http as seen within the server
+IntHttpPort = 8080
+#
+# The port number for https as seen within the server
+IntHttpsPort = 8443
+#
+# The external port number for https taking port mapping into account
+ExtHttpsPort = 443
+#
+# The minimum interval between fetches of the dynamic configuration from the provisioning server
+MinProvFetchInterval = 10000
+#
+# The minimum interval between saves of the redirection data file
+MinRedirSaveInterval = 10000
+#
+# The path to the directory where log files are stored
+LogDir = src/test/resources/logs
+#
+# The retention interval (in days) for log files
+LogRetention = 30
+#
+# The path to the directories where data and meta data files are stored
+SpoolDir = src/test/resources/spool
+#
+# The path to the redirection data file
+RedirectionFile = src/test/redirections.dat
+#
+# The type of keystore for https
+KeyStoreType = jks
+#
+# The path to the keystore for https
+KeyStoreFile = aaf_certs/org.onap.dmaap-dr.jks
+#
+# The password for the https keystore
+KeyStorePassword=WGxd2P6MDo*Bi4+UdzWs{?$8
+#
+# The password for the private key in the https keystore
+KeyPassword=WGxd2P6MDo*Bi4+UdzWs{?$8
+#
+# The type of truststore for https
+TrustStoreType = jks
+#
+# The path to the truststore for https
+TrustStoreFile = aaf_certs/org.onap.dmaap-dr.trust.jks
+#
+# The password for the https truststore
+TrustStorePassword=)OBvCd{e{aWq.^mJJdX:S:1&
+#
+# The path to the file used to trigger an orderly shutdown
+QuiesceFile = etc/SHUTDOWN
+#
+# The key used to generate passwords for node to node transfers
+NodeAuthKey = Node123!
+#
+# DR_NODE DEFAULT ENABLED TLS PROTOCOLS
+NodeHttpsProtocols = TLSv1.1|TLSv1.2
+#
+# AAF type to generate permission string
+AAFType = org.onap.dmaap-dr.feed
+#
+# AAF default instance to generate permission string - default should be legacy
+AAFInstance = legacy
+#
+# AAF action to generate permission string - default should be publish
+AAFAction = publish
+#
+# AAF URL to connect to AAF server
+AafUrl = https://aaf-onap-test.osaaf.org:8095
+#
+# AAF CADI enabled flag
+CadiEnabled = false
+