1 /*******************************************************************************
2 * ============LICENSE_START==================================================
4 * * ===========================================================================
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * * ===========================================================================
7 * * Licensed under the Apache License, Version 2.0 (the "License");
8 * * you may not use this file except in compliance with the License.
9 * * You may obtain a copy of the License at
11 * * http://www.apache.org/licenses/LICENSE-2.0
13 * * Unless required by applicable law or agreed to in writing, software
14 * * distributed under the License is distributed on an "AS IS" BASIS,
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * * See the License for the specific language governing permissions and
17 * * limitations under the License.
18 * * ============LICENSE_END====================================================
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 ******************************************************************************/
23 package org.onap.dmaap.datarouter.provisioning.beans;
25 import org.json.JSONObject;
27 import org.junit.runner.RunWith;
28 import org.onap.dmaap.datarouter.provisioning.utils.DB;
29 import org.powermock.modules.junit4.PowerMockRunner;
31 import javax.persistence.EntityManager;
32 import javax.persistence.EntityManagerFactory;
33 import javax.persistence.Persistence;
34 import java.io.InvalidObjectException;
35 import java.sql.SQLException;
36 import java.util.List;
38 @RunWith(PowerMockRunner.class)
39 public class FeedTest {
40 private static EntityManagerFactory emf;
41 private static EntityManager em;
46 public static void init() {
47 emf = Persistence.createEntityManagerFactory("dr-unit-tests");
48 em = emf.createEntityManager();
50 "org.onap.dmaap.datarouter.provserver.properties",
51 "src/test/resources/h2Database.properties");
55 public static void tearDownClass() {
62 public void setUp() throws Exception {
64 feed = new Feed("Feed1","v0.1", "First Feed for testing", "First Feed for testing");
67 feed.setPublisher("pub");
68 feed.setDeleted(false);
72 public void Given_getFilteredFeedUrlList_With_Name_Then_Method_Returns_Self_Links() {
73 List<String> list= feed.getFilteredFeedUrlList("name","Feed1");
74 Assert.assertEquals("self_link",list.get(0));
78 public void Given_getFilteredFeedUrlList_With_Publ_Then_Method_Returns_Self_Links() {
79 List<String> list= feed.getFilteredFeedUrlList("publ","pub");
80 Assert.assertEquals("self_link",list.get(0));
84 public void Given_getFilteredFeedUrlList_With_Subs_Then_Method_Returns_Self_Links() {
85 List<String> list= feed.getFilteredFeedUrlList("subs","sub123");
86 Assert.assertEquals("self_link",list.get(0));
90 public void Given_doDelete_Succeeds_Then_doInsert_To_Put_Feed_Back_And_Bool_Is_True() throws SQLException, InvalidObjectException {
91 Boolean bool = feed.doDelete(db.getConnection());
92 Assert.assertEquals(true, bool);
93 JSONObject jo = new JSONObject();
94 jo.put("self","self_link");
95 jo.put("publish","publish_link");
96 jo.put("subscribe","subscribe_link");
97 jo.put("log","log_link");
98 feed.setLinks(new FeedLinks(jo));
99 bool = feed.doInsert(db.getConnection());
100 Assert.assertEquals(true, bool);
104 public void Validate_ChaneOwnerShip_Returns_True()
106 Boolean bool = feed.changeOwnerShip();
107 Assert.assertEquals(true, bool);
111 public void Given_Feeds_Are_Equal_Then_Equals_Returns_True()
114 Boolean bool = feed.equals(feed2);
115 Assert.assertEquals(true, bool);