summaryrefslogtreecommitdiffstats
path: root/datarouter-prov
diff options
context:
space:
mode:
authorRam Koya <rk541m@att.com>2018-09-10 21:02:59 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-10 21:02:59 +0000
commit90d9273e98248b1de99542b990cb6abc5e621d5b (patch)
tree3a64236a215bb33857908936e60270f8b881c562 /datarouter-prov
parent82105b59b2502fe1f119bc909c08c9bac173bdfc (diff)
parent01e985fdcbd3a7410cb7f513085a8f879464f0eb (diff)
Merge "unit tests for feed bean"
Diffstat (limited to 'datarouter-prov')
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java117
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/GroupTest.java3
2 files changed, 120 insertions, 0 deletions
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java
new file mode 100644
index 00000000..907aa93b
--- /dev/null
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * ============LICENSE_START==================================================
+ * * org.onap.dmaap
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package org.onap.dmaap.datarouter.provisioning.beans;
+
+import org.json.JSONObject;
+import org.junit.*;
+import org.junit.runner.RunWith;
+import org.onap.dmaap.datarouter.provisioning.utils.DB;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import java.io.InvalidObjectException;
+import java.sql.SQLException;
+import java.util.List;
+
+@RunWith(PowerMockRunner.class)
+public class FeedTest {
+ private static EntityManagerFactory emf;
+ private static EntityManager em;
+ private Feed feed;
+ 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();
+ feed = new Feed("Feed1","v0.1", "First Feed for testing", "First Feed for testing");
+ feed.setFeedid(1);
+ feed.setGroupid(1);
+ feed.setPublisher("pub");
+ feed.setDeleted(false);
+ }
+
+ @Test
+ public void Given_getFilteredFeedUrlList_With_Name_Then_Method_Returns_Self_Links() {
+ List<String> list= feed.getFilteredFeedUrlList("name","Feed1");
+ Assert.assertEquals("self_link",list.get(0));
+ }
+
+ @Test
+ public void Given_getFilteredFeedUrlList_With_Publ_Then_Method_Returns_Self_Links() {
+ List<String> list= feed.getFilteredFeedUrlList("publ","pub");
+ Assert.assertEquals("self_link",list.get(0));
+ }
+
+ @Test
+ public void Given_getFilteredFeedUrlList_With_Subs_Then_Method_Returns_Self_Links() {
+ List<String> list= feed.getFilteredFeedUrlList("subs","sub123");
+ Assert.assertEquals("self_link",list.get(0));
+ }
+
+ @Test
+ public void Given_doDelete_Succeeds_Then_doInsert_To_Put_Feed_Back_And_Bool_Is_True() throws SQLException, InvalidObjectException {
+ Boolean bool = feed.doDelete(db.getConnection());
+ Assert.assertEquals(true, bool);
+ JSONObject jo = new JSONObject();
+ jo.put("self","self_link");
+ jo.put("publish","publish_link");
+ jo.put("subscribe","subscribe_link");
+ jo.put("log","log_link");
+ feed.setLinks(new FeedLinks(jo));
+ bool = feed.doInsert(db.getConnection());
+ Assert.assertEquals(true, bool);
+ }
+
+ @Test
+ public void Validate_ChaneOwnerShip_Returns_True()
+ {
+ Boolean bool = feed.changeOwnerShip();
+ Assert.assertEquals(true, bool);
+ }
+
+ @Test
+ public void Given_Feeds_Are_Equal_Then_Equals_Returns_True()
+ {
+ Feed feed2 = feed;
+ Boolean bool = feed.equals(feed2);
+ Assert.assertEquals(true, bool);
+ }
+} \ No newline at end of file
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/GroupTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/GroupTest.java
index 91d72af7..b785fdc2 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/GroupTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/GroupTest.java
@@ -23,7 +23,9 @@
package org.onap.dmaap.datarouter.provisioning.beans;
import org.junit.*;
+import org.junit.runner.RunWith;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
+import org.powermock.modules.junit4.PowerMockRunner;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -32,6 +34,7 @@ import java.util.Collection;
import java.util.Date;
import java.util.List;
+@RunWith(PowerMockRunner.class)
public class GroupTest {
private static EntityManagerFactory emf;
private static EntityManager em;