aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-prov/src')
-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
4 files changed, 83 insertions, 37 deletions
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