aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-node/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-node/src/test')
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DRNodeCadiFilterTest.java47
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java186
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java133
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTest.java162
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DestInfoTest.java77
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java107
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java206
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java2
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java42
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/PathFinderTest.java75
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/ProvDataTest.java153
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/RedirManagerTest.java73
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/StatusLogTest.java6
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/TaskListTest.java44
-rw-r--r--datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node1
-rw-r--r--datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.M8
-rw-r--r--datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gzbin0 -> 150 bytes
-rw-r--r--datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz.M8
-rw-r--r--datarouter-node/src/test/resources/org.onap.dmaap-dr-test-cert.jksbin0 -> 3647 bytes
-rw-r--r--datarouter-node/src/test/resources/redir_file2
20 files changed, 1012 insertions, 320 deletions
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DRNodeCadiFilterTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DRNodeCadiFilterTest.java
index f6737b1e..bb367186 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DRNodeCadiFilterTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DRNodeCadiFilterTest.java
@@ -1,4 +1,4 @@
-/**-
+/*
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* ================================================================================
@@ -20,6 +20,17 @@
package org.onap.dmaap.datarouter.node;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -32,19 +43,10 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-import static org.mockito.Mockito.*;
-
@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
@PrepareForTest({CadiFilter.class})
@RunWith(PowerMockRunner.class)
-public class DRNodeCadiFilterTest
-{
+public class DRNodeCadiFilterTest {
@Mock
private PropAccess access;
@@ -67,7 +69,8 @@ public class DRNodeCadiFilterTest
}
@Test
- public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Instance_Is_NULL_Then_Chain_doFilter_Called() throws Exception {
+ public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Instance_Is_NULL_Then_Chain_doFilter_Called()
+ throws Exception {
PowerMockito.mockStatic(NodeConfigManager.class);
NodeConfigManager config = mock(NodeConfigManager.class);
@@ -75,12 +78,13 @@ public class DRNodeCadiFilterTest
PowerMockito.when(config.getAafInstance("/other/5")).thenReturn("legacy");
when(request.getPathInfo()).thenReturn("/publish/5");
when(request.getMethod()).thenReturn("GET");
- cadiFilter.doFilter(request,response,chain);
+ cadiFilter.doFilter(request, response, chain);
verify(chain, times(1)).doFilter(request, response);
}
@Test
- public void Given_doFilter_Called_And_Method_Is_GET_And_Path_Includes_Internal_Then_Chain_doFilter_Called() throws Exception {
+ public void Given_doFilter_Called_And_Method_Is_GET_And_Path_Includes_Internal_Then_Chain_doFilter_Called()
+ throws Exception {
PowerMockito.mockStatic(NodeConfigManager.class);
NodeConfigManager config = mock(NodeConfigManager.class);
@@ -88,12 +92,13 @@ public class DRNodeCadiFilterTest
PowerMockito.when(config.getAafInstance("/other/5")).thenReturn("legacy");
when(request.getPathInfo()).thenReturn("/internal/5");
when(request.getMethod()).thenReturn("GET");
- cadiFilter.doFilter(request,response,chain);
+ cadiFilter.doFilter(request, response, chain);
verify(chain, times(1)).doFilter(request, response);
}
@Test
- public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Is_Not_Null_Then_Super_doFilter_Called() throws Exception {
+ public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Is_Not_Null_Then_Super_doFilter_Called()
+ throws Exception {
PowerMockito.mockStatic(NodeConfigManager.class);
NodeConfigManager config = mock(NodeConfigManager.class);
@@ -102,20 +107,22 @@ public class DRNodeCadiFilterTest
when(request.getPathInfo()).thenReturn("/publish/5/fileId");
when(request.getMethod()).thenReturn("GET");
PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(CadiFilter.class));
- cadiFilter.doFilter(request,response,chain);
+ cadiFilter.doFilter(request, response, chain);
verify(chain, times(0)).doFilter(request, response);
}
@Test
- public void Given_getFileid_Called_And_SendError_Fails_Then_Throw_IOException_And_Call_chain_doFilter() throws Exception {
+ public void Given_getFileid_Called_And_SendError_Fails_Then_Throw_IOException_And_Call_chain_doFilter()
+ throws Exception {
PowerMockito.mockStatic(NodeConfigManager.class);
NodeConfigManager config = mock(NodeConfigManager.class);
PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);
when(request.getPathInfo()).thenReturn("/publish/5");
when(request.getMethod()).thenReturn("DELETE");
- doThrow(new IOException()).when(response).sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid request URI. Expecting <feed-publishing-url>/<fileid>. Possible missing fileid.");
- cadiFilter.doFilter(request,response,chain);
+ doThrow(new IOException()).when(response).sendError(HttpServletResponse.SC_NOT_FOUND,
+ "Invalid request URI. Expecting <feed-publishing-url>/<fileid>. Possible missing fileid.");
+ cadiFilter.doFilter(request, response, chain);
verify(chain, times(1)).doFilter(request, response);
}
}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java
index 6dc334fc..6a5f219b 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java
@@ -23,48 +23,60 @@
package org.onap.dmaap.datarouter.node;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.util.Hashtable;
+import java.util.Vector;
import org.apache.commons.lang3.reflect.FieldUtils;
+import org.jetbrains.annotations.NotNull;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
-import java.io.File;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.when;
-
@RunWith(PowerMockRunner.class)
+@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
public class DeliveryQueueTest {
+ @Mock
+ DeliveryQueueHelper deliveryQueueHelper;
private DeliveryQueue deliveryQueue;
@Mock
private DestInfo destInfo;
- @Mock
- DeliveryQueueHelper deliveryQueueHelper;
-
private String dirPath = "/tmp/dir001/";
- private String FileName1 = "10000000000004.fileName.M";
+ private String fileName = "10000000000004.fileName.M";
@Before
- public void setUp() {
- when(destInfo.getSpool()).thenReturn("tmp");
+ public void setUp() throws IllegalAccessException {
+ when(destInfo.getSpool()).thenReturn(dirPath);
+ when(destInfo.isPrivilegedSubscriber()).thenReturn(true);
deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
+ NodeConfigManager configManager = mockNodeConfigManager();
+ FieldUtils.writeDeclaredStaticField(StatusLog.class, "config", configManager, true);
}
@Test
public void Given_New_DeliveryQueue_Directory_Is_Created_As_Defined_By_DestInfo() {
- when(destInfo.getSpool()).thenReturn("tmp");
- File file = new File("tmp");
+ File file = new File("/tmp");
assertTrue(file.exists());
- deleteFile("tmp");
}
@Test
public void Given_Delivery_Task_Failed_And_Resume_Time_Not_Reached_Return_Null() throws Exception {
- FieldUtils.writeField(deliveryQueue,"failed",true,true);
- FieldUtils.writeField(deliveryQueue,"resumetime",System.currentTimeMillis()*2,true);
+ FieldUtils.writeField(deliveryQueue, "failed", true, true);
+ FieldUtils.writeField(deliveryQueue, "resumetime", System.currentTimeMillis() * 2, true);
assertNull(deliveryQueue.peekNext());
}
@@ -75,21 +87,155 @@ public class DeliveryQueueTest {
deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
DeliveryTask nt = deliveryQueue.getNext();
assertEquals("10000000000004.fileName", nt.getPublishId());
- deleteFile(dirPath + FileName1);
+ deleteFile(dirPath + fileName);
deleteFile(dirPath);
}
@Test
+ public void Given_Task_In_Todo_Is_Already_Cleaned_GetNext_Returns_Null() throws Exception {
+ when(deliveryQueueHelper.getExpirationTimer()).thenReturn(10000L);
+ deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
+ Vector<DeliveryTask> tasks = new Vector<>();
+ DeliveryTask task = new DeliveryTask(deliveryQueue, "123.node.datarouternew.com");
+ task.clean();
+ tasks.add(task);
+ FieldUtils.writeField(deliveryQueue, "todo", tasks, true);
+ DeliveryTask nt = deliveryQueue.getNext();
+ assertNull(nt);
+ }
+
+ @Test
+ public void Given_Task_In_Todo_Has_Resume_Time_In_Future_GetNext_Returns_Null() throws Exception {
+ when(destInfo.isPrivilegedSubscriber()).thenReturn(true);
+ when(deliveryQueueHelper.getExpirationTimer()).thenReturn(10000L);
+ deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
+ Vector<DeliveryTask> tasks = new Vector<>();
+ DeliveryTask task = new DeliveryTask(deliveryQueue, "123.node.datarouternew.com");
+ long timeInFuture = 2558366240223L;
+ task.setResumeTime(timeInFuture);
+ tasks.add(task);
+ FieldUtils.writeField(deliveryQueue, "todo", tasks, true);
+ DeliveryTask nt = deliveryQueue.getNext();
+ assertNull(nt);
+ }
+
+ @Test
+ public void Given_Task_In_Todo_Is_Expired_GetNext_Returns_Null() throws Exception {
+ when(destInfo.isPrivilegedSubscriber()).thenReturn(true);
+ when(deliveryQueueHelper.getExpirationTimer()).thenReturn(10000L);
+ deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
+ Vector<DeliveryTask> tasks = new Vector<>();
+ DeliveryTask task = new DeliveryTask(deliveryQueue, "123.node.datarouternew.com");
+ long timeInPast = 1058366240223L;
+ task.setResumeTime(timeInPast);
+ tasks.add(task);
+ FieldUtils.writeField(deliveryQueue, "todo", tasks, true);
+ DeliveryTask nt = deliveryQueue.getNext();
+ assertNull(nt);
+ }
+
+ @Test
public void Given_Delivery_Task_Cancel_And_FileId_Is_Null_Return_Zero() {
long rc = deliveryQueue.cancelTask("123.node.datarouternew.com");
assertEquals(0, rc);
}
+ @Test
+ public void Given_Delivery_Task_Is_Working_Cancel_Task_Returns_Zero() throws IllegalAccessException {
+ Hashtable<String, DeliveryTask> tasks = new Hashtable<>();
+ tasks.put("123.node.datarouternew.com", new DeliveryTask(deliveryQueue, "123.node.datarouternew.com"));
+ FieldUtils.writeField(deliveryQueue, "working", tasks, true);
+ long rc = deliveryQueue.cancelTask("123.node.datarouternew.com");
+ assertEquals(0, rc);
+ }
+
+ @Test
+ public void Given_Delivery_Task_In_Todo_Cancel_Task_Returns_Zero() throws IllegalAccessException {
+ Vector<DeliveryTask> tasks = new Vector<>();
+ tasks.add(new DeliveryTask(deliveryQueue, "123.node.datarouternew.com"));
+ FieldUtils.writeField(deliveryQueue, "todo", tasks, true);
+ long rc = deliveryQueue.cancelTask("123.node.datarouternew.com");
+ assertEquals(0, rc);
+ }
+
+ @Test
+ public void Given_Ok_Status_And_Privileged_Subscriber_Then_Set_Resume_Time_Is_Called_On_DeliveryTask() {
+ DeliveryTask deliveryTask = mockDeliveryTask();
+ deliveryQueue.reportStatus(deliveryTask, 200, "123456789.dmaap-dr-node", "delivery");
+ verify(deliveryTask, times(1)).setResumeTime(anyLong());
+ cleanUpLogging();
+ }
+
+ @Test
+ public void Given_Ok_Status_And_Not_Privileged_Subscriber_Then_Clean_Is_Called_On_DeliveryTask() {
+ DeliveryTask deliveryTask = mockDeliveryTask();
+ when(destInfo.isPrivilegedSubscriber()).thenReturn(false);
+ deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
+ deliveryQueue.reportStatus(deliveryTask, 200, "123456789.dmaap-dr-node", "delivery");
+ verify(deliveryTask, times(1)).clean();
+ cleanUpLogging();
+ }
+
+ @Test
+ public void Given_Not_Ok_Status_Then_Clean_Is_Called_On_DeliveryTask() {
+ DeliveryTask deliveryTask = mockDeliveryTask();
+ deliveryQueue.reportStatus(deliveryTask, 400, "123456789.dmaap-dr-node", "delivery");
+ verify(deliveryTask, times(1)).clean();
+ cleanUpLogging();
+ }
+
+ @Test
+ public void Given_Task_In_Working_MarkTaskSuccess_Returns_True() throws IllegalAccessException {
+ Hashtable<String, DeliveryTask> tasks = new Hashtable<>();
+ tasks.put("123.node.datarouternew.com", new DeliveryTask(deliveryQueue, "123.node.datarouternew.com"));
+ FieldUtils.writeField(deliveryQueue, "working", tasks, true);
+ assertTrue(deliveryQueue.markTaskSuccess("123.node.datarouternew.com"));
+ }
+
+ @Test
+ public void Given_Task_In_Retry_MarkTaskSuccess_Returns_True() throws IllegalAccessException {
+ Hashtable<String, DeliveryTask> tasks = new Hashtable<>();
+ tasks.put("123.node.datarouternew.com", new DeliveryTask(deliveryQueue, "123.node.datarouternew.com"));
+ FieldUtils.writeField(deliveryQueue, "retry", tasks, true);
+ assertTrue(deliveryQueue.markTaskSuccess("123.node.datarouternew.com"));
+ }
+
+ @Test
+ public void Given_Task_Does_Not_Exist_MarkTaskSuccess_Returns_False() {
+ assertFalse(deliveryQueue.markTaskSuccess("false.pubId.com"));
+ }
+
+ private void cleanUpLogging() {
+ final File currentDir = new File(System.getProperty("user.dir"));
+ final File[] files = currentDir.listFiles((file, name) -> name.matches("null.*"));
+ if (files != null) {
+ for (final File file : files) {
+ file.delete();
+ }
+ }
+ }
+
+ @NotNull
+ private DeliveryTask mockDeliveryTask() {
+ DeliveryTask deliveryTask = mock(DeliveryTask.class);
+ when(deliveryTask.getPublishId()).thenReturn("123456789.dmaap-dr-node");
+ when(deliveryTask.getFeedId()).thenReturn("1");
+ when(deliveryTask.getSubId()).thenReturn("1");
+ when(deliveryTask.getURL()).thenReturn("http://subcriber.com:7070/delivery");
+ when(deliveryTask.getCType()).thenReturn("application/json");
+ when(deliveryTask.getLength()).thenReturn(486L);
+ return deliveryTask;
+ }
+
+ private NodeConfigManager mockNodeConfigManager() {
+ NodeConfigManager config = mock(NodeConfigManager.class);
+ PowerMockito.when(config.getEventLogInterval()).thenReturn("30000");
+ return config;
+ }
+
private void prepareFiles() throws Exception {
createFolder(dirPath);
- createFile(FileName1, dirPath);
- String[] files = new String[2];
- files[0] = dirPath + FileName1;
+ createFile(fileName, dirPath);
}
private void createFolder(String dirName) {
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
new file mode 100644
index 00000000..a0f05779
--- /dev/null
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java
@@ -0,0 +1,133 @@
+/*
+ * ============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 static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.OutputStream;
+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;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DeliveryTask.class})
+public class DeliveryTaskTest {
+
+ @Mock
+ private DeliveryQueue deliveryQueue;
+
+ private ExecutorService executorService;
+
+ @Before
+ public void setUp() throws Exception {
+ DestInfo destInfo = getPrivDestInfo();
+ deliveryQueue = mockDelvieryQueue(destInfo);
+
+ 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.when(urlConnection.getHeaderField(0)).thenReturn("PUT");
+ PowerMockito.when(urlConnection.getResponseCode()).thenReturn(200);
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+
+ @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");
+ Assert.assertEquals(task, task2);
+ Assert.assertEquals(task.hashCode(), task2.hashCode());
+ Assert.assertEquals(task.toString(), task2.toString());
+ Assert.assertEquals(task.getPublishId(), task2.getPublishId());
+ Assert.assertEquals(task.getSubId(), task2.getSubId());
+ Assert.assertEquals(task.getFeedId(), task2.getFeedId());
+ Assert.assertEquals(task.getLength(), task2.getLength());
+ Assert.assertEquals(task.isCleaned(), task2.isCleaned());
+ Assert.assertEquals(task.getDate(), task2.getDate());
+ Assert.assertEquals(task.getURL(), task2.getURL());
+ Assert.assertEquals(task.getCType(), task2.getCType());
+ Assert.assertEquals(task.getMethod(), task2.getMethod());
+ 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 {
+ DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-node");
+ executorService = Executors.newSingleThreadExecutor();
+ executorService.execute(task);
+
+ executorService.shutdown();
+ executorService.awaitTermination(2, TimeUnit.SECONDS);
+ }
+
+ @Test
+ public void Validate_Delivery_Tasks_Success_For_Compressed_File() throws InterruptedException {
+
+ DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-node.gz");
+ executorService = Executors.newSingleThreadExecutor();
+ executorService.execute(task);
+
+ executorService.shutdown();
+ executorService.awaitTermination(2, TimeUnit.SECONDS);
+ }
+
+ private DestInfo getPrivDestInfo() {
+ return new DestInfoBuilder().setName("n:" + "dmaap-dr-node")
+ .setSpool(System.getProperty("user.dir") + "/src/test/resources/delivery_files")
+ .setSubid("1").setLogdata("n2n-dmaap-dr-node").setUrl("https://dmaap-dr-node:8443/internal/publish")
+ .setAuthuser("dmaap-dr-node").setAuthentication("Auth").setMetaonly(false).setUse100(true)
+ .setPrivilegedSubscriber(true).setFollowRedirects(false).setDecompress(true).createDestInfo();
+ }
+
+ private DeliveryQueue mockDelvieryQueue(DestInfo destInfo) {
+ DeliveryQueue mockedDeliveryQueue = mock(DeliveryQueue.class);
+ when(mockedDeliveryQueue.getDestinationInfo()).thenReturn(destInfo);
+ return mockedDeliveryQueue;
+ }
+
+}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTest.java
index 08120073..18d9d56c 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTest.java
@@ -22,86 +22,124 @@
******************************************************************************/
package org.onap.dmaap.datarouter.node;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Hashtable;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.onap.dmaap.datarouter.node.Delivery.DelItem;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
-import java.io.File;
-import java.io.IOException;
-import java.util.Hashtable;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
@RunWith(PowerMockRunner.class)
@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
public class DeliveryTest {
- @Mock
- private DeliveryQueue deliveryQueue;
+ @Mock
+ private DeliveryQueue deliveryQueue;
+ @Mock
+ private NodeConfigManager config;
+ private File nDir = new File("tmp/n");
+ private File newNDir = new File("tmp/n/0");
+ private File newNFile = new File("tmp/n/0/testN.txt");
+ private File sDir = new File("tmp/s");
+ private File newSDir = new File("tmp/s/0/1");
+ private File newSpoolFile = new File("tmp/s/0/1/123456789.dmaap-dr-node");
+ private File spoolFileMeta = new File("tmp/s/0/1/123456789.dmaap-dr-node.M");
+
+ @Before
+ public void setUp() throws IOException {
+ nDir.mkdirs();
+ sDir.mkdirs();
+ newNDir.mkdirs();
+ newNFile.createNewFile();
+ newSDir.mkdirs();
+ newSpoolFile.createNewFile();
+ spoolFileMeta.createNewFile();
+ config = mockNodeConfigManager();
+ }
+
+ @Test
+ public void Validate_Reset_Queue_Calls_Reset_Queue_On_Delivery_Queue_Object() throws IllegalAccessException {
+ Delivery delivery = new Delivery(config);
+ HashMap<String, DeliveryQueue> dqs = new HashMap<>();
+ dqs.put("tmp/s/0/1", deliveryQueue);
+ FieldUtils.writeDeclaredField(delivery, "dqs", dqs, true);
+ delivery.resetQueue("tmp/s/0/1");
+ verify(deliveryQueue, times(1)).resetQueue();
+ }
- private File nDir = new File("tmp/n");
- private File sDir = new File("tmp/s");
+ @Test
+ public void Validate_Mark_Success_Calls_Mark_Success_On_Delivery_Queue_Object() throws IllegalAccessException {
+ Delivery delivery = new Delivery(config);
+ HashMap<String, DeliveryQueue> dqs = new HashMap<>();
+ dqs.put("tmp/s/0/1", deliveryQueue);
+ FieldUtils.writeDeclaredField(delivery, "dqs", dqs, true);
+ delivery.markTaskSuccess("tmp/s/0/1", "123456789.dmaap-dr-node");
+ verify(deliveryQueue, times(1)).markTaskSuccess("123456789.dmaap-dr-node");
+ }
- @Before
- public void setUp() throws IOException {
- nDir.mkdirs();
- sDir.mkdirs();
- File newNDir = new File("tmp/n/0");
- newNDir.mkdirs();
- File newNFile = new File("tmp/n/0/testN.txt");
- newNFile.createNewFile();
- File newSDir = new File("tmp/s/0/1");
- newSDir.mkdirs();
- File newSpoolFile = new File("tmp/s/0/1/testSpool.txt");
- newSpoolFile.createNewFile();
- }
+ @Test
+ public void Validate_DelItem_With_Equal_Spool_And_PubId_Are_Equal() {
+ DelItem delItem1 = new DelItem("123456789.dmaap-dr-node", "tmp/s/0/1");
+ DelItem delItem2 = new DelItem("123456789.dmaap-dr-node", "tmp/s/0/1");
+ Assert.assertEquals(delItem1, delItem2);
+ Assert.assertEquals(0, delItem1.compareTo(delItem2));
+ }
- @Test
- public void Validate_Reset_Queue_Calls_Reset_Queue_On_Delivery_Queue_Object() throws IllegalAccessException {
- NodeConfigManager config = mockNodeConfigManager();
- Delivery delivery = new Delivery(config);
- Hashtable<String, DeliveryQueue> dqs = new Hashtable<>();
- dqs.put("spool/s/0/1", deliveryQueue);
- FieldUtils.writeDeclaredField(delivery, "dqs", dqs, true);
- delivery.resetQueue("spool/s/0/1");
- verify(deliveryQueue, times(1)).resetQueue();
- }
+ @Test
+ public void Validate_DelItem_With_Unequal_Spool_And_PubId_Are_Not_Equal() {
+ DelItem delItem1 = new DelItem("123456789.dmaap-dr-node", "tmp/s/0/1");
+ DelItem delItem2 = new DelItem("000000000.dmaap-dr-node", "tmp/s/0/2");
+ Assert.assertNotEquals(delItem1, delItem2);
+ Assert.assertNotEquals(0, delItem1.compareTo(delItem2));
+ }
- @After
- public void tearDown() {
- nDir.delete();
- sDir.delete();
- File tmpDir = new File("tmp");
- tmpDir.delete();
- }
+ @After
+ public void tearDown() {
+ newSpoolFile.delete();
+ spoolFileMeta.delete();
+ newNFile.delete();
+ newNDir.delete();
+ newSDir.delete();
+ new File("tmp/s/0").delete();
+ nDir.delete();
+ sDir.delete();
+ File tmpDir = new File("tmp");
+ tmpDir.delete();
+ }
- private NodeConfigManager mockNodeConfigManager() {
- PowerMockito.mockStatic(NodeConfigManager.class);
- NodeConfigManager config = mock(NodeConfigManager.class);
- PowerMockito.when(config.isConfigured()).thenReturn(true);
- PowerMockito.when(config.getAllDests()).thenReturn(createDestInfoObjects());
- PowerMockito.when(config.getFreeDiskStart()).thenReturn(0.49);
- PowerMockito.when(config.getFreeDiskStop()).thenReturn(0.5);
- PowerMockito.when(config.getDeliveryThreads()).thenReturn(0);
- PowerMockito.when(config.getSpoolBase()).thenReturn("tmp");
- return config;
- }
+ private NodeConfigManager mockNodeConfigManager() {
+ NodeConfigManager config = mock(NodeConfigManager.class);
+ PowerMockito.when(config.isConfigured()).thenReturn(true);
+ PowerMockito.when(config.getAllDests()).thenReturn(createDestInfoObjects());
+ PowerMockito.when(config.getFreeDiskStart()).thenReturn(0.9);
+ PowerMockito.when(config.getFreeDiskStop()).thenReturn(0.2);
+ PowerMockito.when(config.getDeliveryThreads()).thenReturn(0);
+ PowerMockito.when(config.getSpoolBase()).thenReturn("tmp");
+ return config;
+ }
- private DestInfo[] createDestInfoObjects() {
- DestInfo[] destInfos = new DestInfo[1];
- DestInfo destInfo = new DestInfo.DestInfoBuilder().setName("node.datarouternew.com").setSpool("spool/s/0/1").setSubid("1")
- .setLogdata("logs/").setUrl("/subs/1").setAuthuser("user1").setAuthentication("Basic dXNlcjE6cGFzc3dvcmQx")
- .setMetaonly(false).setUse100(true).setPrivilegedSubscriber(false).setFollowRedirects(false)
- .setDecompress(false).createDestInfo();
- destInfos[0] = destInfo;
- return destInfos;
- }
+ private DestInfo[] createDestInfoObjects() {
+ DestInfo[] destInfos = new DestInfo[1];
+ DestInfo destInfo = new DestInfoBuilder().setName("node.datarouternew.com").setSpool("tmp/s/0/1")
+ .setSubid("1")
+ .setLogdata("logs/").setUrl("/subs/1").setAuthuser("user1")
+ .setAuthentication("Basic dXNlcjE6cGFzc3dvcmQx")
+ .setMetaonly(false).setUse100(true).setPrivilegedSubscriber(false).setFollowRedirects(false)
+ .setDecompress(false).createDestInfo();
+ destInfos[0] = destInfo;
+ return destInfos;
+ }
}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DestInfoTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DestInfoTest.java
new file mode 100644
index 00000000..ed629bf2
--- /dev/null
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DestInfoTest.java
@@ -0,0 +1,77 @@
+/*
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class DestInfoTest {
+
+ private DestInfo destInfo;
+
+ @Before
+ public void setUp() {
+ destInfo = getDestInfo("/src/test/resources");
+ }
+
+ @Test
+ public void Validate_Getters_And_Setters() {
+ assertEquals("n:dmaap-dr-node", destInfo.getName());
+ assertEquals("/src/test/resources", destInfo.getSpool());
+ assertEquals("1", destInfo.getSubId());
+ assertEquals("n2n-dmaap-dr-node", destInfo.getLogData());
+ assertEquals("https://dmaap-dr-node:8443/internal/publish", destInfo.getURL());
+ assertEquals("dmaap-dr-node", destInfo.getAuthUser());
+ assertEquals("Auth", destInfo.getAuth());
+ assertFalse(destInfo.isMetaDataOnly());
+ assertTrue(destInfo.isUsing100());
+ assertFalse(destInfo.isPrivilegedSubscriber());
+ assertFalse(destInfo.isFollowRedirects());
+ assertFalse(destInfo.isDecompress());
+ }
+
+ @Test
+ public void Validate_DestInfo_Objects_Are_Equal() {
+ DestInfo destInfo2 = getDestInfo("/src/test/resources");
+ assertEquals(destInfo, destInfo2);
+ assertEquals(destInfo.hashCode(), destInfo2.hashCode());
+ }
+
+ @Test
+ public void Validate_DestInfo_Objects_Are_Not_Equal() {
+ DestInfo destInfo2 = getDestInfo("notEqual");
+ assertNotEquals(destInfo, destInfo2);
+ assertNotEquals(destInfo.hashCode(), destInfo2.hashCode());
+ }
+
+ private DestInfo getDestInfo(String spool) {
+ return new DestInfoBuilder().setName("n:" + "dmaap-dr-node").setSpool(spool)
+ .setSubid("1").setLogdata("n2n-dmaap-dr-node").setUrl("https://dmaap-dr-node:8443/internal/publish")
+ .setAuthuser("dmaap-dr-node").setAuthentication("Auth").setMetaonly(false).setUse100(true)
+ .setPrivilegedSubscriber(false).setFollowRedirects(false).setDecompress(false).createDestInfo();
+ }
+
+}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java
new file mode 100644
index 00000000..da690206
--- /dev/null
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java
@@ -0,0 +1,107 @@
+/*
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Timer;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.onap.dmaap.datarouter.node.LogManager.Uploader;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.node.NodeConfigManager"})
+public class LogManagerTest {
+
+ @Mock
+ private NodeConfigManager config;
+
+ private LogManager logManager;
+
+ @Before
+ public void setUp() throws IllegalAccessException {
+ mockNodeConfigManager();
+ FieldUtils.writeDeclaredStaticField(StatusLog.class, "config", config, true);
+ logManager = new LogManager(config);
+ }
+
+ @AfterClass
+ public static void tearDown() throws IOException {
+ File spoolDir = new File(System.getProperty("user.dir") + "/src/test/resources/.spool");
+ FileUtils.deleteDirectory(spoolDir);
+ }
+
+ @Test
+ public void Verify_LogManager_Attempts_To_Deliver_Log_Files_To_Prov() {
+ logManager.run();
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {
+ System.out.println("Exception caught: " + e.getMessage());
+ }
+ File file = new File(System.getProperty("user.dir") + "/src/test/resources/.spool/.lastqueued");
+ assertTrue(file.isFile());
+ }
+
+ @Test
+ public void Validate_Uploader_Getters() {
+ Uploader worker = logManager.getWorker();
+ assertEquals(10000L, worker.getInitFailureTimer());
+ assertEquals(600000L, worker.getWaitForFileProcessFailureTimer());
+ assertEquals(2.0, worker.getFailureBackoff(), 0.0);
+ assertEquals(150000L, worker.getMaxFailureTimer());
+ assertEquals(604800000L, worker.getExpirationTimer());
+ assertEquals(10000, worker.getFairFileLimit());
+ assertEquals(86400000, worker.getFairTimeLimit());
+ assertEquals("https://dmaap-dr-prov:8443/internal/logs",
+ worker.getDestURL(new DestInfoBuilder().createDestInfo(), "String"));
+ assertFalse(worker.handleRedirection(new DestInfoBuilder().createDestInfo(), "", ""));
+ assertFalse(worker.isFollowRedirects());
+ assertNull(worker.getFeedId(""));
+ }
+
+ private void mockNodeConfigManager() {
+ PowerMockito.when(config.getLogDir()).thenReturn(System.getProperty("user.dir") + "/src/test/resources");
+ PowerMockito.when(config.getTimer()).thenReturn(new Timer("Node Configuration Timer", true));
+ PowerMockito.when(config.getEventLogPrefix())
+ .thenReturn(System.getProperty("user.dir") + "/src/test/resources/events");
+ PowerMockito.when(config.getEventLogSuffix()).thenReturn(".log");
+ PowerMockito.when(config.getLogRetention()).thenReturn(94608000000L);
+ PowerMockito.when(config.getEventLogInterval()).thenReturn("30s");
+ PowerMockito.when(config.getPublishId()).thenReturn("123456789.dmaap-dr-node");
+ PowerMockito.when(config.getEventLogUrl()).thenReturn("https://dmaap-dr-prov:8443/internal/logs");
+ }
+
+}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java
index 5e357373..b03407bf 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java
@@ -22,6 +22,9 @@
******************************************************************************/
package org.onap.dmaap.datarouter.node;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Assert;
@@ -31,23 +34,114 @@ import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-
@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.node.ProvData",
- "org.onap.dmaap.datarouter.node.NodeUtils"})
+@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.node.ProvData"})
public class NodeConfigTest {
private static NodeConfig nodeConfig;
@BeforeClass
- public static void setUp() throws IOException{
+ public static void setUp() throws IOException {
ProvData provData = setUpProvData();
nodeConfig = new NodeConfig(provData, "Name", "spool/dir", 80, "Key");
}
+ private static ProvData setUpProvData() throws IOException {
+ JSONObject provData = new JSONObject();
+ createValidFeed(provData);
+ createValidSubscription(provData);
+ createValidParameters(provData);
+ createValidIngressValues(provData);
+ createValidEgressValues(provData);
+ createValidRoutingValues(provData);
+ Reader reader = new StringReader(provData.toString());
+ return new ProvData(reader);
+ }
+
+ private static void createValidFeed(JSONObject provData) {
+ JSONArray feeds = new JSONArray();
+ JSONObject feed = new JSONObject();
+ JSONObject auth = new JSONObject();
+ JSONArray endpointIds = new JSONArray();
+ JSONArray endpointAddrs = new JSONArray();
+ JSONObject endpointId = new JSONObject();
+ feed.put("feedid", "1");
+ feed.put("name", "Feed1");
+ feed.put("version", "m1.0");
+ feed.put("suspend", false);
+ feed.put("deleted", false);
+ endpointId.put("id", "user1");
+ endpointId.put("password", "password1");
+ endpointIds.put(endpointId);
+ auth.put("endpoint_ids", endpointIds);
+ endpointAddrs.put("172.0.0.1");
+ auth.put("endpoint_addrs", endpointAddrs);
+ feed.put("authorization", auth);
+ feed.put("aaf_instance", "legacy");
+ feeds.put(feed);
+ provData.put("feeds", feeds);
+ }
+
+ private static void createValidSubscription(JSONObject provData) {
+ JSONArray subscriptions = new JSONArray();
+ JSONObject subscription = new JSONObject();
+ JSONObject delivery = new JSONObject();
+ subscription.put("subid", "1");
+ subscription.put("feedid", "1");
+ subscription.put("suspend", false);
+ subscription.put("metadataOnly", false);
+ delivery.put("url", "https://172.0.0.2");
+ delivery.put("user", "user1");
+ delivery.put("password", "password1");
+ delivery.put("use100", true);
+ subscription.put("delivery", delivery);
+ subscription.put("privilegedSubscriber", false);
+ subscription.put("follow_redirect", false);
+ subscription.put("decompress", false);
+ subscriptions.put(subscription);
+ provData.put("subscriptions", subscriptions);
+ }
+
+ private static void createValidParameters(JSONObject provData) {
+ JSONObject parameters = new JSONObject();
+ JSONArray nodes = new JSONArray();
+ parameters.put("PROV_NAME", "prov.datarouternew.com");
+ parameters.put("DELIVERY_INIT_RETRY_INTERVAL", "10");
+ parameters.put("DELIVERY_MAX_AGE", "86400");
+ parameters.put("PROV_DOMAIN", "");
+ nodes.put("172.0.0.4");
+ parameters.put("NODES", nodes);
+ provData.put("parameters", parameters);
+ }
+
+ private static void createValidIngressValues(JSONObject provData) {
+ JSONArray ingresses = new JSONArray();
+ JSONObject ingress = new JSONObject();
+ ingress.put("feedid", "1");
+ ingress.put("subnet", "");
+ ingress.put("user", "");
+ ingress.put("node", "172.0.0.4");
+ ingresses.put(ingress);
+ provData.put("ingress", ingresses);
+ }
+
+ private static void createValidEgressValues(JSONObject provData) {
+ JSONObject egress = new JSONObject();
+ egress.put("subid", "1");
+ egress.put("nodeid", "172.0.0.4");
+ provData.put("egress", egress);
+ }
+
+ private static void createValidRoutingValues(JSONObject provData) {
+ JSONArray routings = new JSONArray();
+ JSONObject routing = new JSONObject();
+ routing.put("from", "prov.datarouternew.com");
+ routing.put("to", "172.0.0.4");
+ routing.put("via", "172.100.0.1");
+ routings.put(routing);
+ provData.put("routing", routings);
+ }
+
@Test
public void Given_Feed_Does_Not_Exist_Then_Is_Publish_Permitted_Returns_Not_Null() {
String permitted = nodeConfig.isPublishPermitted("2", "user", "0.0.0.0");
@@ -73,7 +167,7 @@ public class NodeConfigTest {
}
@Test
- public void Given_SubId_Then_Get_Feed_Id_Returns_Correct_Id(){
+ public void Given_SubId_Then_Get_Feed_Id_Returns_Correct_Id() {
String feedId = nodeConfig.getFeedId("1");
Assert.assertEquals("1", feedId);
}
@@ -164,100 +258,4 @@ public class NodeConfigTest {
String auth = nodeConfig.getMyAuth();
Assert.assertEquals("Basic TmFtZTp6Z04wMFkyS3gybFppbXltNy94ZDhuMkdEYjA9", auth);
}
-
- private static ProvData setUpProvData() throws IOException {
- JSONObject provData = new JSONObject();
- createValidFeed(provData);
- createValidSubscription(provData);
- createValidParameters(provData);
- createValidIngressValues(provData);
- createValidEgressValues(provData);
- createValidRoutingValues(provData);
- Reader reader = new StringReader(provData.toString());
- return new ProvData(reader);
- }
-
- private static void createValidFeed(JSONObject provData) {
- JSONArray feeds = new JSONArray();
- JSONObject feed = new JSONObject();
- JSONObject auth = new JSONObject();
- JSONArray endpointIds = new JSONArray();
- JSONArray endpointAddrs = new JSONArray();
- JSONObject endpointId = new JSONObject();
- feed.put("feedid", "1");
- feed.put("name", "Feed1");
- feed.put("version", "m1.0");
- feed.put("suspend", false);
- feed.put("deleted", false);
- endpointId.put("id", "user1");
- endpointId.put("password", "password1");
- endpointIds.put(endpointId);
- auth.put("endpoint_ids", endpointIds);
- endpointAddrs.put("172.0.0.1");
- auth.put("endpoint_addrs", endpointAddrs);
- feed.put("authorization", auth);
- feed.put("aaf_instance", "legacy");
- feeds.put(feed);
- provData.put("feeds", feeds);
- }
-
- private static void createValidSubscription(JSONObject provData) {
- JSONArray subscriptions = new JSONArray();
- JSONObject subscription = new JSONObject();
- JSONObject delivery = new JSONObject();
- subscription.put("subid", "1");
- subscription.put("feedid", "1");
- subscription.put("suspend", false);
- subscription.put("metadataOnly", false);
- delivery.put("url", "https://172.0.0.2");
- delivery.put("user", "user1");
- delivery.put("password", "password1");
- delivery.put("use100", true);
- subscription.put("delivery", delivery);
- subscription.put("privilegedSubscriber", false);
- subscription.put("follow_redirect", false);
- subscription.put("decompress", false);
- subscriptions.put(subscription);
- provData.put("subscriptions", subscriptions);
- }
-
- private static void createValidParameters(JSONObject provData) {
- JSONObject parameters = new JSONObject();
- JSONArray nodes = new JSONArray();
- parameters.put("PROV_NAME", "prov.datarouternew.com");
- parameters.put("DELIVERY_INIT_RETRY_INTERVAL", "10");
- parameters.put("DELIVERY_MAX_AGE", "86400");
- parameters.put("PROV_DOMAIN", "");
- nodes.put("172.0.0.4");
- parameters.put("NODES", nodes);
- provData.put("parameters", parameters);
- }
-
- private static void createValidIngressValues(JSONObject provData) {
- JSONArray ingresses = new JSONArray();
- JSONObject ingress = new JSONObject();
- ingress.put("feedid", "1");
- ingress.put("subnet", "");
- ingress.put("user", "");
- ingress.put("node", "172.0.0.4");
- ingresses.put(ingress);
- provData.put("ingress", ingresses);
- }
-
- private static void createValidEgressValues(JSONObject provData) {
- JSONObject egress = new JSONObject();
- egress.put("subid", "1");
- egress.put("nodeid", "172.0.0.4");
- provData.put("egress", egress);
- }
-
- private static void createValidRoutingValues(JSONObject provData) {
- JSONArray routings = new JSONArray();
- JSONObject routing = new JSONObject();
- routing.put("from", "prov.datarouternew.com");
- routing.put("to", "172.0.0.4");
- routing.put("via", "172.100.0.1");
- routings.put(routing);
- provData.put("routing", routings);
- }
}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java
index db71ceae..a375f026 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java
@@ -219,7 +219,7 @@ public class NodeServletTest {
@Test
public void Given_Request_Is_HTTP_PUT_On_Publish_On_AAF_Feed_And_Cadi_Enabled_And_No_Permissions_Then_Forbidden_Response_Is_Generated() throws Exception {
- when(config.getCadiEnabeld()).thenReturn(true);
+ when(config.getCadiEnabled()).thenReturn(true);
when(config.getAafInstance("1")).thenReturn("*");
when(request.getPathInfo()).thenReturn("/publish/1/fileName");
setHeadersForValidRequest(true);
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java
index 27fcd1c4..2d87b8b9 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java
@@ -22,29 +22,19 @@
******************************************************************************/
package org.onap.dmaap.datarouter.node;
+import static org.mockito.Mockito.when;
+
+import javax.servlet.http.HttpServletRequest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
import org.slf4j.MDC;
-import javax.servlet.http.HttpServletRequest;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.util.UUID;
-
-import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
-import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
-import static org.mockito.Mockito.when;
-import static org.powermock.api.mockito.PowerMockito.mockStatic;
-
@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeUtils")
-@PrepareForTest({ UUID.class, InetAddress.class })
+@PowerMockIgnore({"java.net.ssl", "javax.security.auth.x500.X500Principal"})
public class NodeUtilsTest {
@Mock
@@ -54,6 +44,7 @@ public class NodeUtilsTest {
public void Given_Uri_With_Params_Then_Get_Feed_And_File_Id_Returns_Correct_Values() {
String uri = "prov.datarouternew.com:8443/feed/12/fileName";
String[] uriParams = NodeUtils.getFeedAndFileID(uri);
+ assert uriParams != null;
Assert.assertEquals("12", uriParams[0]);
Assert.assertEquals("fileName", uriParams[1]);
}
@@ -87,23 +78,8 @@ public class NodeUtilsTest {
}
@Test
- public void Given_setIpAndFqdnForEelf_Called_Set_MDC_Values() throws IOException {
- mockStatic(InetAddress.class);
- when(InetAddress.getLocalHost().getHostName()).thenReturn("testHostName");
- when(InetAddress.getLocalHost().getHostAddress()).thenReturn("testHostAddress");
- NodeUtils.setIpAndFqdnForEelf("doGet");
- Assert.assertEquals("testHostName", MDC.get(MDC_SERVER_FQDN));
- Assert.assertEquals("testHostAddress", MDC.get(MDC_SERVER_IP_ADDRESS));
- }
-
- @Test
- public void Given_Request_Has_Empty_RequestId_And_InvocationId_Headers_Generate_MDC_Values() {
- when(request.getHeader("X-ONAP-RequestID")).thenReturn("");
- when(request.getHeader("X-InvocationID")).thenReturn("");
- mockStatic(UUID.class);
- when(UUID.randomUUID().toString()).thenReturn("123", "456");
- NodeUtils.setRequestIdAndInvocationId(request);
- Assert.assertEquals("123", MDC.get("RequestId"));
- Assert.assertEquals("456", MDC.get("InvocationId"));
+ public void Given_Get_CanonicalName_Called_Valid_CN_Returned() {
+ String canonicalName = NodeUtils.getCanonicalName("jks", "src/test/resources/org.onap.dmaap-dr-test-cert.jks", "WGxd2P6MDo*Bi4+UdzWs{?$8");
+ Assert.assertEquals("dmaap-dr-node", canonicalName);
}
}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/PathFinderTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/PathFinderTest.java
new file mode 100644
index 00000000..25edd0c0
--- /dev/null
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/PathFinderTest.java
@@ -0,0 +1,75 @@
+/*-
+ * ============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 static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class PathFinderTest {
+
+ @Test
+ public void Given_Unknown_From_Node_Returns_Null() {
+ new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
+ new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-4", "dr-node-3", "dr-node-2")});
+ }
+
+ @Test
+ public void Given_Unknown_Destination_Node_Returns_Null() {
+ new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
+ new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-5", "dr-node-2")});
+ }
+
+ @Test
+ public void Given_Duplicate_Next_Hop_Returns_Null() {
+ PathFinder p = new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
+ new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-3", "dr-node-2"),
+ new NodeConfig.ProvHop("dr-node-1", "dr-node-3", "dr-node-2")});
+ assertThat(p.getErrors().length, is(1));
+ assertNotNull(p.getPath("dr-node-3"));
+ assertThat(p.getPath("dr-node-5").length(), is(0));
+ }
+
+ @Test
+ public void Given_Unknown_Via_Node_Returns_Null() {
+ new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
+ new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-3", "dr-node-4")});
+ }
+
+ @Test
+ public void Given_Dest_Equals_Via_Bad_Hop_Defined() {
+ new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
+ new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-2", "dr-node-2")});
+ }
+
+ @Test
+ public void Given_Valid_Path_Defined_Success() {
+ new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
+ new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-3+", "dr-node-2")});
+ }
+
+
+}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/ProvDataTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/ProvDataTest.java
index 662f2cc0..1fd79d9a 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/ProvDataTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/ProvDataTest.java
@@ -20,17 +20,16 @@
package org.onap.dmaap.datarouter.node;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNull;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
public class ProvDataTest {
@@ -40,77 +39,77 @@ public class ProvDataTest {
public void Validate_Values_Are_Set_Correctly_Through_ProvData_Constuctor() throws Exception {
String InternalProvData =
"{" +
- "\"ingress\":[{" +
- "\"feedid\":1," +
- "\"subnet\":\"\"," +
- "\"user\":\"\"," +
- "\"node\":\"node\"" +
- "}]," +
- "\"routing\":[{" +
- "\"from\":\"172.10.10.10\"," +
- "\"to\":\"172.10.10.12\"," +
- "\"via\":\"172.10.10.11\"" +
- "}]," +
- "\"subscriptions\":[{" +
- "\"subid\":1," +
- "\"suspend\":false," +
- "\"delivery\":{" +
- "\"use100\":true," +
- "\"password\":\"PASSWORD\"," +
- "\"user\":\"LOGIN\"," +
- "\"url\":\"http://172.18.0.2:7070\"" +
- "}," +
- "\"last_mod\":1553608460000," +
- "\"subscriber\":\"PMMAPER\"," +
- "\"feedid\":1," +
- "\"decompress\":false," +
- "\"groupid\":1," +
- "\"metadataOnly\":false," +
- "\"follow_redirect\":false," +
- "\"links\":{" +
- "\"feed\":\"https://dmaap-dr-prov/feed/1\"" +
- ",\"log\":\"https://dmaap-dr-prov/sublog/1\"" +
- ",\"self\":\"https://dmaap-dr-prov/subs/1\"" +
- "}," +
- "\"created_date\":1553608460000," +
- "\"privilegedSubscriber\":false" +
- "}]," +
- "\"feeds\":[{" +
- "\"suspend\":false," +
- "\"groupid\":0," +
- "\"description\":\"Default feed\"," +
- "\"version\":\"m1.0\"," +
- "\"authorization\":{" +
- "\"endpoint_addrs\":[\"172.10.10.20\"]," +
- "\"classification\":\"unclassified\"," +
- "\"endpoint_ids\":[{" +
- "\"password\":\"password\"," +
- "\"id\":\"user\"" +
- "}]" +
- "}," +
- "\"last_mod\":1553608454000," +
- "\"deleted\":false," +
- "\"feedid\":1," +
- "\"name\":\"CSIT_Test2\"" +
- ",\"business_description\":\"Default Feed\"" +
- ",\"publisher\":\"dradmin\"" +
- ",\"links\":{" +
- "\"subscribe\":\"https://dmaap-dr-prov/subscribe/1\"," +
- "\"log\":\"https://dmaap-dr-prov/feedlog/1\"," +
- "\"publish\":\"https://dmaap-dr-prov/publish/1\"," +
- "\"self\":\"https://dmaap-dr-prov/feed/1\"" +
- "}," +
- "\"created_date\":1553608454000" +
- "}]," +
- "\"groups\":[]," +
- "\"parameters\":{" +
- "\"NODES\":[\"dmaap-dr-node\"]," +
- "\"PROV_DOMAIN\":\"\"" +
- "}," +
- "\"egress\":{" +
- "\"1\":1" +
- "}" +
- "}" ;
+ "\"ingress\":[{" +
+ "\"feedid\":1," +
+ "\"subnet\":\"\"," +
+ "\"user\":\"\"," +
+ "\"node\":\"node\"" +
+ "}]," +
+ "\"routing\":[{" +
+ "\"from\":\"172.10.10.10\"," +
+ "\"to\":\"172.10.10.12\"," +
+ "\"via\":\"172.10.10.11\"" +
+ "}]," +
+ "\"subscriptions\":[{" +
+ "\"subid\":1," +
+ "\"suspend\":false," +
+ "\"delivery\":{" +
+ "\"use100\":true," +
+ "\"password\":\"PASSWORD\"," +
+ "\"user\":\"LOGIN\"," +
+ "\"url\":\"http://172.18.0.2:7070\"" +
+ "}," +
+ "\"last_mod\":1553608460000," +
+ "\"subscriber\":\"PMMAPER\"," +
+ "\"feedid\":1," +
+ "\"decompress\":false," +
+ "\"groupid\":1," +
+ "\"metadataOnly\":false," +
+ "\"follow_redirect\":false," +
+ "\"links\":{" +
+ "\"feed\":\"https://dmaap-dr-prov/feed/1\"" +
+ ",\"log\":\"https://dmaap-dr-prov/sublog/1\"" +
+ ",\"self\":\"https://dmaap-dr-prov/subs/1\"" +
+ "}," +
+ "\"created_date\":1553608460000," +
+ "\"privilegedSubscriber\":false" +
+ "}]," +
+ "\"feeds\":[{" +
+ "\"suspend\":false," +
+ "\"groupid\":0," +
+ "\"description\":\"Default feed\"," +
+ "\"version\":\"m1.0\"," +
+ "\"authorization\":{" +
+ "\"endpoint_addrs\":[\"172.10.10.20\"]," +
+ "\"classification\":\"unclassified\"," +
+ "\"endpoint_ids\":[{" +
+ "\"password\":\"password\"," +
+ "\"id\":\"user\"" +
+ "}]" +
+ "}," +
+ "\"last_mod\":1553608454000," +
+ "\"deleted\":false," +
+ "\"feedid\":1," +
+ "\"name\":\"CSIT_Test2\"" +
+ ",\"business_description\":\"Default Feed\"" +
+ ",\"publisher\":\"dradmin\"" +
+ ",\"links\":{" +
+ "\"subscribe\":\"https://dmaap-dr-prov/subscribe/1\"," +
+ "\"log\":\"https://dmaap-dr-prov/feedlog/1\"," +
+ "\"publish\":\"https://dmaap-dr-prov/publish/1\"," +
+ "\"self\":\"https://dmaap-dr-prov/feed/1\"" +
+ "}," +
+ "\"created_date\":1553608454000" +
+ "}]," +
+ "\"groups\":[]," +
+ "\"parameters\":{" +
+ "\"NODES\":[\"dmaap-dr-node\"]," +
+ "\"PROV_DOMAIN\":\"\"" +
+ "}," +
+ "\"egress\":{" +
+ "\"1\":1" +
+ "}" +
+ "}";
Reader r = new InputStreamReader(new ByteArrayInputStream(InternalProvData.getBytes(StandardCharsets.UTF_8)));
ProvData pd = new ProvData(r);
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/RedirManagerTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/RedirManagerTest.java
new file mode 100644
index 00000000..2c8a0e52
--- /dev/null
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/RedirManagerTest.java
@@ -0,0 +1,73 @@
+/*-
+ * ============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 static org.junit.Assert.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.Timer;
+import org.hamcrest.core.Is;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class RedirManagerTest {
+
+ private RedirManager redirManager;
+ private String redirFilePath = System.getProperty("user.dir") + "/src/test/resources/redir_file";
+
+ @Before
+ public void setUp() {
+ Timer timer = new Timer("Node Configuration Timer", true);
+ redirManager = new RedirManager(redirFilePath, 10000L, timer);
+ }
+
+ @Test
+ public void Given_Lookup_On_Valid_Redirect_Returns_Target_URL() {
+ assertThat(redirManager.lookup("1", "http://destination:8443/path/to"), Is.is("http://redirect:8443/path/to"));
+ }
+
+ @Test
+ public void Given_IsRedirected_Called_On_Valid_Sub_Id_Then_Returns_True() {
+ assertThat(redirManager.isRedirected("1"), Is.is(true));
+ }
+
+ @Test
+ public void Given_Redirect_Called_On_Valid_Redirect_New_Redirect_Added() throws IOException {
+ long origFileLenght = new File(redirFilePath).length();
+ redirManager.redirect("3", "http://destination3:8443/path/to", "http://redirect3:8443/path/to");
+ assertThat(redirManager.lookup("3", "http://destination3:8443/path/to"), Is.is("http://redirect3:8443/path/to"));
+ new RandomAccessFile(redirFilePath, "rw").setLength(origFileLenght);
+ }
+
+ @Test
+ public void Given_Lookup_On_Invalid_Redirect_Returns_Primary_Target_URL_And_Is_Forgotten() throws IOException {
+ assertThat(redirManager.lookup("2", "http://invalid:8443/path/to"), Is.is("http://invalid:8443/path/to"));
+ Files.write(Paths.get(redirFilePath), "2 http://destination2:8443/path/to http://redirect2:8443/path/to".getBytes(), StandardOpenOption.APPEND);
+ }
+}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/StatusLogTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/StatusLogTest.java
index e60f576c..d3793069 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/StatusLogTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/StatusLogTest.java
@@ -22,6 +22,9 @@
******************************************************************************/
package org.onap.dmaap.datarouter.node;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -31,9 +34,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
@RunWith(PowerMockRunner.class)
@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
@PrepareForTest(StatusLog.class)
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/TaskListTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/TaskListTest.java
new file mode 100644
index 00000000..311165c6
--- /dev/null
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/TaskListTest.java
@@ -0,0 +1,44 @@
+/*-
+ * ============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 org.junit.Test;
+
+public class TaskListTest {
+
+ @Test
+ public void Given_New_Task_List_Verify_Add_And_Run() {
+ TaskList taskList = new TaskList();
+ taskList.startRun();
+ taskList.addTask(() -> {
+ });
+ taskList.next();
+ taskList.removeTask(() -> {
+ });
+ }
+
+ @Test
+ public void Given_Empty_Task_List_Verify_Next() {
+ TaskList taskList = new TaskList();
+ taskList.startRun();
+ taskList.next();
+ }
+}
diff --git a/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node
new file mode 100644
index 00000000..1677aafe
--- /dev/null
+++ b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node
@@ -0,0 +1 @@
+Hello World!!!!!! \ No newline at end of file
diff --git a/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.M b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.M
new file mode 100644
index 00000000..b317b671
--- /dev/null
+++ b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.M
@@ -0,0 +1,8 @@
+PUT A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-RequestID A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-InvocationID ea407097-2de5-452e-9f21-569e6d867deb
+X-TransactionID A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-ONAP-RequestID A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-DMAAP-DR-META {"productName":"RnNode","vendorName":"Ericsson","lastEpochMicrosec":"1561550151179","sourceName":"","startEpochMicrosec":"1561550151179","timeZoneOffset":"UTC+00:00","location":"ftps://onap:pano@10.209.63.42:2036/A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz","compression":"gzip","fileFormatType":"org.3GPP.32.435#measCollec","fileFormatVersion":"V10"}
+Content-Type application/octet-stream
+X-DMAAP-DR-RECEIVED 2019-06-26T11:56:38.216Z;from=10.42.54.206;by=10.42.70.78 \ No newline at end of file
diff --git a/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz
new file mode 100644
index 00000000..d38bae1f
--- /dev/null
+++ b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz
Binary files differ
diff --git a/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz.M b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz.M
new file mode 100644
index 00000000..b317b671
--- /dev/null
+++ b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz.M
@@ -0,0 +1,8 @@
+PUT A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-RequestID A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-InvocationID ea407097-2de5-452e-9f21-569e6d867deb
+X-TransactionID A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-ONAP-RequestID A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-DMAAP-DR-META {"productName":"RnNode","vendorName":"Ericsson","lastEpochMicrosec":"1561550151179","sourceName":"","startEpochMicrosec":"1561550151179","timeZoneOffset":"UTC+00:00","location":"ftps://onap:pano@10.209.63.42:2036/A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz","compression":"gzip","fileFormatType":"org.3GPP.32.435#measCollec","fileFormatVersion":"V10"}
+Content-Type application/octet-stream
+X-DMAAP-DR-RECEIVED 2019-06-26T11:56:38.216Z;from=10.42.54.206;by=10.42.70.78 \ No newline at end of file
diff --git a/datarouter-node/src/test/resources/org.onap.dmaap-dr-test-cert.jks b/datarouter-node/src/test/resources/org.onap.dmaap-dr-test-cert.jks
new file mode 100644
index 00000000..2320dc9f
--- /dev/null
+++ b/datarouter-node/src/test/resources/org.onap.dmaap-dr-test-cert.jks
Binary files differ
diff --git a/datarouter-node/src/test/resources/redir_file b/datarouter-node/src/test/resources/redir_file
new file mode 100644
index 00000000..0c72ebe9
--- /dev/null
+++ b/datarouter-node/src/test/resources/redir_file
@@ -0,0 +1,2 @@
+1 http://destination:8443/path/to http://redirect:8443/path/to
+2 http://destination2:8443/path/to http://redirect2:8443/path/to \ No newline at end of file