summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorefiacor <fiachra.corcoran@est.tech>2019-07-10 15:02:29 +0000
committerefiacor <fiachra.corcoran@est.tech>2019-07-10 15:02:29 +0000
commit98572b78fcce9ff28fa7429c9265812bd1e78bf2 (patch)
treee5f14bf7b083f543435634be6fee442882024827
parentcec9a9227c805ff5415d6b9fd913fa64adafdd3a (diff)
Adding more DR-Node unit tests
Change-Id: I57b1c7aa678188136ecf84be53e0811908091f1a Issue-ID: DMAAP-1226 Signed-off-by: efiacor <fiachra.corcoran@est.tech>
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/PathFinder.java10
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java14
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java3
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java34
-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/RedirManagerTest.java73
-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
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java9
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java44
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java15
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java52
12 files changed, 252 insertions, 79 deletions
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/PathFinder.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/PathFinder.java
index d86b1e4d..fe3fdb6e 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/PathFinder.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/PathFinder.java
@@ -35,7 +35,7 @@ import org.onap.dmaap.datarouter.node.NodeConfig.ProvHop;
* get from this node to any other node.
*/
-public class PathFinder {
+class PathFinder {
private ArrayList<String> errors = new ArrayList<>();
private HashMap<String, String> routes = new HashMap<>();
@@ -47,7 +47,7 @@ public class PathFinder {
* @param nodes where we can go
* @param hops detours along the way
*/
- public PathFinder(String origin, String[] nodes, NodeConfig.ProvHop[] hops) {
+ PathFinder(String origin, String[] nodes, NodeConfig.ProvHop[] hops) {
HashSet<String> known = new HashSet<>();
HashMap<String, HashMap<String, Hop>> ht = new HashMap<>();
for (String n : nodes) {
@@ -77,8 +77,8 @@ public class PathFinder {
*
* @return array of error descriptions
*/
- public String[] getErrors() {
- return (errors.toArray(new String[errors.size()]));
+ String[] getErrors() {
+ return (errors.toArray(new String[0]));
}
/**
@@ -87,7 +87,7 @@ public class PathFinder {
* @param destination node
* @return list of node names separated by and ending with "/"
*/
- public String getPath(String destination) {
+ String getPath(String destination) {
String ret = routes.get(destination);
if (ret == null) {
return ("");
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java
index f501583a..b4a3f0a7 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java
@@ -37,10 +37,10 @@ import java.util.Timer;
/**
* Track redirections of subscriptions.
*/
-public class RedirManager {
+class RedirManager {
private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(RedirManager.class);
- RateLimitedOperation op;
+ private RateLimitedOperation op;
private HashMap<String, String> sid2primary = new HashMap<>();
private HashMap<String, String> sid2secondary = new HashMap<>();
private String redirfile;
@@ -52,7 +52,7 @@ public class RedirManager {
* @param mininterval The minimum number of milliseconds between writes to the redirection information file.
* @param timer The timer thread used to run delayed file writes.
*/
- public RedirManager(String redirfile, long mininterval, Timer timer) {
+ RedirManager(String redirfile, long mininterval, Timer timer) {
this.redirfile = redirfile;
op = new RateLimitedOperation(mininterval, timer) {
public void run() {
@@ -92,7 +92,7 @@ public class RedirManager {
* @param primary The URL associated with that subscription ID
* @param secondary The replacement URL to use instead
*/
- public synchronized void redirect(String sid, String primary, String secondary) {
+ synchronized void redirect(String sid, String primary, String secondary) {
sid2primary.put(sid, primary);
sid2secondary.put(sid, secondary);
op.request();
@@ -103,7 +103,7 @@ public class RedirManager {
*
* @param sid The subscription ID to remove from the table.
*/
- public synchronized void forget(String sid) {
+ synchronized void forget(String sid) {
sid2primary.remove(sid);
sid2secondary.remove(sid);
op.request();
@@ -117,7 +117,7 @@ public class RedirManager {
* @param primary The configured primary URL.
* @return The destination URL to really use.
*/
- public synchronized String lookup(String sid, String primary) {
+ synchronized String lookup(String sid, String primary) {
String oprim = sid2primary.get(sid);
if (primary.equals(oprim)) {
return (sid2secondary.get(sid));
@@ -130,7 +130,7 @@ public class RedirManager {
/**
* Is a subscription redirected.
*/
- public synchronized boolean isRedirected(String sid) {
+ synchronized boolean isRedirected(String sid) {
return (sid != null && sid2secondary.get(sid) != null);
}
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 79719243..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
@@ -35,8 +35,7 @@ import org.powermock.core.classloader.annotations.SuppressStaticInitializationFo
import org.powermock.modules.junit4.PowerMockRunner;
@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;
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 88e57432..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,27 +22,19 @@
******************************************************************************/
package org.onap.dmaap.datarouter.node;
-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;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.util.UUID;
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;
@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
@@ -52,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]);
}
@@ -85,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/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/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
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java
index c12d83d3..1cb1f2bb 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java
@@ -23,6 +23,8 @@
package org.onap.dmaap.datarouter.provisioning.beans;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.io.InvalidObjectException;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -34,9 +36,6 @@ import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Properties;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
import org.json.JSONObject;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
@@ -597,8 +596,8 @@ public class Subscription extends Syncable {
if (feedid != os.feedid) {
return false;
}
- if (groupid != os.groupid) //New field is added - Groups feature Rally:US708115 - 1610
- {
+ if (groupid != os.groupid) {
+ //New field is added - Groups feature Rally:US708115 - 1610
return false;
}
if (!delivery.equals(os.delivery)) {
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java
index b867c672..57007489 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java
@@ -22,8 +22,25 @@
******************************************************************************/
package org.onap.dmaap.datarouter.provisioning;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Mockito.argThat;
+import static org.mockito.Mockito.contains;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER;
+
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
@@ -36,30 +53,11 @@ import org.mockito.Mock;
import org.onap.dmaap.datarouter.authz.AuthorizationResponse;
import org.onap.dmaap.datarouter.authz.Authorizer;
import org.onap.dmaap.datarouter.provisioning.beans.Insertable;
-import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import static org.hamcrest.Matchers.notNullValue;
-import static org.mockito.Mockito.*;
-import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER;
-
@RunWith(PowerMockRunner.class)
-@PrepareForTest(Subscription.class)
public class SubscribeServletTest extends DrServletTestBase {
private static SubscribeServlet subscribeServlet;
private static EntityManagerFactory emf;
@@ -144,10 +142,6 @@ public class SubscribeServletTest extends DrServletTestBase {
ServletOutputStream outStream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(outStream);
when(request.getPathInfo()).thenReturn("/1");
- PowerMockito.mockStatic(Subscription.class);
- List<String> list = new ArrayList<>();
- list.add("{}");
- PowerMockito.when(Subscription.getSubscriptionUrlList(anyInt())).thenReturn(list);
subscribeServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
verifyEnteringExitCalled(listAppender);
@@ -294,8 +288,6 @@ public class SubscribeServletTest extends DrServletTestBase {
when(response.getOutputStream()).thenReturn(outStream);
when(request.getPathInfo()).thenReturn("/2");
when(request.isUserInRole("org.onap.dmaap-dr.feed|*|approveSub")).thenReturn(true);
- PowerMockito.mockStatic(Subscription.class);
- PowerMockito.when(Subscription.getSubscriptionMatching(new Subscription())).thenReturn(null);
JSONObject JSObject = buildRequestJsonObject();
SubscribeServlet subscribeServlet = new SubscribeServlet() {
protected JSONObject getJSONfromInput(HttpServletRequest req) {
@@ -353,8 +345,6 @@ public class SubscribeServletTest extends DrServletTestBase {
@Test
public void Given_Request_Is_HTTP_POST_And_POST_Fails_Bad_Request_Response_Is_Generated() throws Exception {
when(request.getPathInfo()).thenReturn("/2");
- PowerMockito.mockStatic(Subscription.class);
- PowerMockito.when(Subscription.getSubscriptionMatching(new Subscription())).thenReturn(null);
JSONObject JSObject = buildRequestJsonObject();
SubscribeServlet subscribeServlet = new SubscribeServlet() {
protected JSONObject getJSONfromInput(HttpServletRequest req) {
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java
index a17e23e0..4a410ddd 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java
@@ -323,6 +323,7 @@ public class SubscriptionServletTest extends DrServletTestBase {
subscriptionServlet.doPut(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
resetAafSubscriptionInDB();
+ addNewSubscriptionInDB();
verifyEnteringExitCalled(listAppender);
}
@@ -627,4 +628,18 @@ public class SubscriptionServletTest extends DrServletTestBase {
subscription.setPrivilegedSubscriber(false);
subscription.doUpdate(db.getConnection());
}
+
+ private void addNewSubscriptionInDB() throws SQLException {
+ Subscription subscription = new Subscription("https://172.100.0.6:8080", "user3", "password3");
+ subscription.setSubid(3);
+ subscription.setSubscriber("user3");
+ subscription.setFeedid(1);
+ SubDelivery subDelivery = new SubDelivery(URL, USER, PASSWORD, true);
+ subscription.setDelivery(subDelivery);
+ subscription.setGroupid(1);
+ subscription.setMetadataOnly(false);
+ subscription.setSuspended(false);
+ subscription.setDecompress(false);
+ subscription.doInsert(db.getConnection());
+ }
} \ No newline at end of file
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java
index d859e082..214cc6e7 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java
@@ -23,22 +23,50 @@
package org.onap.dmaap.datarouter.provisioning.beans;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import org.junit.AfterClass;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.onap.dmaap.datarouter.provisioning.utils.DB;
import org.powermock.modules.junit4.PowerMockRunner;
-
@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.provisioning.beans.Subscription"})
public class SubscriptionTest {
private Subscription subscription;
+ private static EntityManagerFactory emf;
+ private static EntityManager em;
+ private DB db;
+
+ @BeforeClass
+ public static void init() {
+ emf = Persistence.createEntityManagerFactory("dr-unit-tests");
+ em = emf.createEntityManager();
+ System.setProperty(
+ "org.onap.dmaap.datarouter.provserver.properties",
+ "src/test/resources/h2Database.properties");
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ em.clear();
+ em.close();
+ emf.close();
+ }
+ @Before
+ public void setUp() throws Exception {
+ db = new DB();
+ subscription = new Subscription();
+ }
+
@Test
public void validate_Subscription_Created_With_Default_Constructor() {
- subscription = new Subscription();
Assert.assertEquals(subscription.getSubid(), -1);
Assert.assertEquals(subscription.getGroupid(), -1);
Assert.assertEquals(subscription.getSubscriber(), "");
@@ -56,13 +84,13 @@ public class SubscriptionTest {
subLinks.setLog("log");
subLinks.setSelf("self");
- subscription = new Subscription();
subscription.setGroupid(2);
subscription.setDelivery(subDelivery);
subscription.setMetadataOnly(false);
subscription.setSubscriber(subscriber);
subscription.setSuspended(false);
subscription.setPrivilegedSubscriber(false);
+ subscription.setFollowRedirect(true);
subscription.setLinks(subLinks);
subscription.setDecompress(false);
@@ -73,5 +101,19 @@ public class SubscriptionTest {
Assert.assertFalse(subscription.isSuspended());
Assert.assertFalse(subscription.isPrivilegedSubscriber());
Assert.assertFalse(subscription.isDecompress());
+
+ Subscription sub2 = new Subscription();
+ sub2.setGroupid(2);
+ sub2.setDelivery(subDelivery);
+ sub2.setMetadataOnly(false);
+ sub2.setSubscriber(subscriber);
+ sub2.setSuspended(false);
+ sub2.setPrivilegedSubscriber(false);
+ sub2.setFollowRedirect(true);
+ sub2.setLinks(subLinks);
+ sub2.setDecompress(false);
+ Assert.assertTrue(subscription.equals(sub2));
+ Assert.assertNotNull(sub2.toString());
+ sub2.hashCode();
}
} \ No newline at end of file