aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-node/src/test/java/org/onap
diff options
context:
space:
mode:
authorefiacor <fiachra.corcoran@est.tech>2019-07-25 11:05:54 +0000
committerefiacor <fiachra.corcoran@est.tech>2019-07-25 11:05:54 +0000
commitf09604a09059d6c3ecf05b253c9058c1a2e81ca2 (patch)
treead5c6e1abffdc7cf30404df8af8b9c11f8d71a0e /datarouter-node/src/test/java/org/onap
parentf20778ffa99aa9c6f30a0f84112a5392b259ea63 (diff)
FINAL unit test covergae commit
Change-Id: Ieb9e9d49931c253b89026ed4884edbdc8d6c6024 Issue-ID: DMAAP-1226 Signed-off-by: efiacor <fiachra.corcoran@est.tech>
Diffstat (limited to 'datarouter-node/src/test/java/org/onap')
-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
2 files changed, 94 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