7f049e5df587414535015591e9cbeca8a9e2c124
[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.powermock.modules.junit4.PowerMockRunner;
36
37 @RunWith(PowerMockRunner.class)
38 public class SubscriptionTest {
39
40     private Subscription subscription;
41
42     private static EntityManagerFactory emf;
43     private static EntityManager em;
44
45     @BeforeClass
46     public static void init() {
47         emf = Persistence.createEntityManagerFactory("dr-unit-tests");
48         em = emf.createEntityManager();
49         System.setProperty(
50                 "org.onap.dmaap.datarouter.provserver.properties",
51                 "src/test/resources/h2Database.properties");
52     }
53
54     @AfterClass
55     public static void tearDownClass() {
56         em.clear();
57         em.close();
58         emf.close();
59     }
60     @Before
61     public void setUp() throws Exception {
62         subscription = new Subscription();
63     }
64
65     @Test
66     public void validate_Subscription_Created_With_Default_Constructor() {
67         Assert.assertEquals(subscription.getSubid(), -1);
68         Assert.assertEquals(subscription.getGroupid(), -1);
69         Assert.assertEquals(subscription.getSubscriber(), "");
70     }
71
72     @Test
73     public void validate_Getters_And_Setters() {
74         String url = "1.2.3.4";
75         String user = "myUser";
76         String password = "myPass";
77         String subscriber = "mySubscriber";
78         SubDelivery subDelivery = new SubDelivery(url, user, password, false);
79         SubLinks subLinks = new SubLinks();
80         subLinks.setFeed("feed");
81         subLinks.setLog("log");
82         subLinks.setSelf("self");
83
84         subscription.setGroupid(2);
85         subscription.setDelivery(subDelivery);
86         subscription.setMetadataOnly(false);
87         subscription.setSubscriber(subscriber);
88         subscription.setSuspended(false);
89         subscription.setPrivilegedSubscriber(false);
90         subscription.setFollowRedirect(true);
91         subscription.setLinks(subLinks);
92         subscription.setDecompress(false);
93
94         Assert.assertEquals(2, subscription.getGroupid());
95         Assert.assertEquals(subDelivery, subscription.getDelivery());
96         Assert.assertEquals(subLinks, subscription.getLinks());
97         Assert.assertFalse(subscription.isMetadataOnly());
98         Assert.assertFalse(subscription.isSuspended());
99         Assert.assertFalse(subscription.isPrivilegedSubscriber());
100         Assert.assertFalse(subscription.isDecompress());
101
102         Subscription sub2 = new Subscription();
103         sub2.setGroupid(2);
104         sub2.setDelivery(subDelivery);
105         sub2.setMetadataOnly(false);
106         sub2.setSubscriber(subscriber);
107         sub2.setSuspended(false);
108         sub2.setPrivilegedSubscriber(false);
109         sub2.setFollowRedirect(true);
110         sub2.setLinks(subLinks);
111         sub2.setDecompress(false);
112         Assert.assertTrue(subscription.equals(sub2));
113         Assert.assertNotNull(sub2.toString());
114         sub2.hashCode();
115     }
116 }