update link to upper-constraints.txt
[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.core.classloader.annotations.PowerMockIgnore;
36 import org.powermock.modules.junit4.PowerMockRunner;
37
38 @RunWith(PowerMockRunner.class)
39 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*"})
40 public class SubscriptionTest {
41
42     private Subscription subscription;
43
44     private static EntityManagerFactory emf;
45     private static EntityManager em;
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         subscription = new Subscription();
65     }
66
67     @Test
68     public void validate_Subscription_Created_With_Default_Constructor() {
69         Assert.assertEquals(subscription.getSubid(), -1);
70         Assert.assertEquals(subscription.getGroupid(), -1);
71         Assert.assertEquals(subscription.getSubscriber(), "");
72     }
73
74     @Test
75     public void validate_Getters_And_Setters() {
76         String url = "1.2.3.4";
77         String user = "myUser";
78         String password = "myPass";
79         String subscriber = "mySubscriber";
80         SubDelivery subDelivery = new SubDelivery(url, user, password, false);
81         SubLinks subLinks = new SubLinks();
82         subLinks.setFeed("feed");
83         subLinks.setLog("log");
84         subLinks.setSelf("self");
85
86         subscription.setGroupid(2);
87         subscription.setDelivery(subDelivery);
88         subscription.setMetadataOnly(false);
89         subscription.setSubscriber(subscriber);
90         subscription.setSuspended(false);
91         subscription.setPrivilegedSubscriber(false);
92         subscription.setFollowRedirect(true);
93         subscription.setLinks(subLinks);
94         subscription.setDecompress(false);
95
96         Assert.assertEquals(2, subscription.getGroupid());
97         Assert.assertEquals(subDelivery, subscription.getDelivery());
98         Assert.assertEquals(subLinks, subscription.getLinks());
99         Assert.assertFalse(subscription.isMetadataOnly());
100         Assert.assertFalse(subscription.isSuspended());
101         Assert.assertFalse(subscription.isPrivilegedSubscriber());
102         Assert.assertFalse(subscription.isDecompress());
103
104         Subscription sub2 = new Subscription();
105         sub2.setGroupid(2);
106         sub2.setDelivery(subDelivery);
107         sub2.setMetadataOnly(false);
108         sub2.setSubscriber(subscriber);
109         sub2.setSuspended(false);
110         sub2.setPrivilegedSubscriber(false);
111         sub2.setFollowRedirect(true);
112         sub2.setLinks(subLinks);
113         sub2.setDecompress(false);
114         Assert.assertTrue(subscription.equals(sub2));
115         Assert.assertNotNull(sub2.toString());
116         sub2.hashCode();
117     }
118 }