diff options
author | Emmett Cox <emmett.cox@ericsson.com> | 2018-09-07 15:10:10 +0100 |
---|---|---|
committer | Emmett Cox <emmett.cox@ericsson.com> | 2018-09-10 10:18:23 +0100 |
commit | 01e985fdcbd3a7410cb7f513085a8f879464f0eb (patch) | |
tree | c5f615947e270f54523fa80169a4e482e41a155f /datarouter-prov/src/test | |
parent | 26311ae5220efa4460c03284d0a47b2def420ecb (diff) |
unit tests for feed bean
Change-Id: Ib97db321e24b609c4baa7dd0783431ead18198a5
Signed-off-by: Emmett Cox <emmett.cox@ericsson.com>
Issue-ID: DMAAP-101
Diffstat (limited to 'datarouter-prov/src/test')
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; |