Adding more DR-Node unit tests
[dmaap/datarouter.git] / datarouter-prov / src / test / java / org / onap / dmaap / datarouter / provisioning / beans / SubscriptionTest.java
1 /*******************************************************************************
2  * ============LICENSE_START==================================================
3  * * org.onap.dmaap
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
10  * *
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * *
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====================================================
19  * *
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  * *
22  ******************************************************************************/
23
24 package org.onap.dmaap.datarouter.provisioning.beans;
25
26 import javax.persistence.EntityManager;
27 import javax.persistence.EntityManagerFactory;
28 import javax.persistence.Persistence;
29 import org.junit.AfterClass;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.onap.dmaap.datarouter.provisioning.utils.DB;
36 import org.powermock.modules.junit4.PowerMockRunner;
37
38 @RunWith(PowerMockRunner.class)
39 public class SubscriptionTest {
40
41     private Subscription subscription;
42
43     private static EntityManagerFactory emf;
44     private static EntityManager em;
45     private DB db;
46
47     @BeforeClass
48     public static void init() {
49         emf = Persistence.createEntityManagerFactory("dr-unit-tests");
50         em = emf.createEntityManager();
51         System.setProperty(
52                 "org.onap.dmaap.datarouter.provserver.properties",
53                 "src/test/resources/h2Database.properties");
54     }
55
56     @AfterClass
57     public static void tearDownClass() {
58         em.clear();
59         em.close();
60         emf.close();
61     }
62     @Before
63     public void setUp() throws Exception {
64         db = new DB();
65         subscription = new Subscription();
66     }
67
68     @Test
69     public void validate_Subscription_Created_With_Default_Constructor() {
70         Assert.assertEquals(subscription.getSubid(), -1);
71         Assert.assertEquals(subscription.getGroupid(), -1);
72         Assert.assertEquals(subscription.getSubscriber(), "");
73     }
74
75     @Test
76     public void validate_Getters_And_Setters() {
77         String url = "1.2.3.4";
78         String user = "myUser";
79         String password = "myPass";
80         String subscriber = "mySubscriber";
81         SubDelivery subDelivery = new SubDelivery(url, user, password, false);
82         SubLinks subLinks = new SubLinks();
83         subLinks.setFeed("feed");
84         subLinks.setLog("log");
85         subLinks.setSelf("self");
86
87         subscription.setGroupid(2);
88         subscription.setDelivery(subDelivery);
89         subscription.setMetadataOnly(false);
90         subscription.setSubscriber(subscriber);
91         subscription.setSuspended(false);
92         subscription.setPrivilegedSubscriber(false);
93         subscription.setFollowRedirect(true);
94         subscription.setLinks(subLinks);
95         subscription.setDecompress(false);
96
97         Assert.assertEquals(2, subscription.getGroupid());
98         Assert.assertEquals(subDelivery, subscription.getDelivery());
99         Assert.assertEquals(subLinks, subscription.getLinks());
100         Assert.assertFalse(subscription.isMetadataOnly());
101         Assert.assertFalse(subscription.isSuspended());
102         Assert.assertFalse(subscription.isPrivilegedSubscriber());
103         Assert.assertFalse(subscription.isDecompress());
104
105         Subscription sub2 = new Subscription();
106         sub2.setGroupid(2);
107         sub2.setDelivery(subDelivery);
108         sub2.setMetadataOnly(false);
109         sub2.setSubscriber(subscriber);
110         sub2.setSuspended(false);
111         sub2.setPrivilegedSubscriber(false);
112         sub2.setFollowRedirect(true);
113         sub2.setLinks(subLinks);
114         sub2.setDecompress(false);
115         Assert.assertTrue(subscription.equals(sub2));
116         Assert.assertNotNull(sub2.toString());
117         sub2.hashCode();
118     }
119 }