From: Emmett Cox Date: Fri, 7 Sep 2018 14:10:10 +0000 (+0100) Subject: unit tests for feed bean X-Git-Tag: 1.0.1~1^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdatarouter.git;a=commitdiff_plain;h=01e985fdcbd3a7410cb7f513085a8f879464f0eb unit tests for feed bean Change-Id: Ib97db321e24b609c4baa7dd0783431ead18198a5 Signed-off-by: Emmett Cox Issue-ID: DMAAP-101 --- 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 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 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 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;