Update css file name in conf.py
[policy/engine.git] / ONAP-REST / src / test / java / org / onap / policy / rest / jpa / PolicyUtilsJpaTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-REST
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.rest.jpa;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28
29 import java.util.Date;
30
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.common.logging.flexlogger.FlexLogger;
34 import org.onap.policy.common.logging.flexlogger.Logger;
35
36 /**
37  * The Class PolicyUtilsJpaTest.
38  */
39 public class PolicyUtilsJpaTest {
40
41     private static Logger logger = FlexLogger.getLogger(PolicyUtilsJpaTest.class);
42     private UserInfo userInfo;
43
44     /**
45      * Sets the up.
46      *
47      * @throws Exception the exception
48      */
49     @Before
50     public void setUp() throws Exception {
51         logger.info("setUp: Entering");
52         userInfo = new UserInfo();
53         userInfo.setUserLoginId("Test");
54         userInfo.setUserName("Test");
55         logger.info("setUp: exit");
56     }
57
58     /**
59      * Test watch policy notification table.
60      */
61     @Test
62     public void testWatchPolicyNotificationTable() {
63         WatchPolicyNotificationTable data = new WatchPolicyNotificationTable();
64         data.setId(1);
65         assertTrue(1 == data.getId());
66         data.setPolicyName("Test");
67         assertTrue("Test".equals(data.getPolicyName()));
68         data.setLoginIds("Test");
69         assertTrue("Test".equals(data.getLoginIds()));
70         data.equals(data);
71         data.hashCode();
72     }
73
74     /**
75      * Test policy roles.
76      */
77     @Test
78     public void testPolicyRoles() {
79         PolicyRoles data = new PolicyRoles();
80         data.setId(1);
81         assertTrue(1 == data.getId());
82         data.setScope("Test");
83         assertTrue("Test".equals(data.getScope()));
84         data.setRole("Test");
85         assertTrue("Test".equals(data.getRole()));
86         data.setLoginId(userInfo);
87         assertTrue("Test".equals(data.getLoginId().getUserLoginId()));
88     }
89
90     /**
91      * Test policy version.
92      */
93     @Test
94     public void testPolicyVersion() {
95         PolicyVersion data = new PolicyVersion();
96         new PolicyVersion("Test", "Test");
97         data.prePersist();
98         data.preUpdate();
99         data.setId(1);
100         assertTrue(1 == data.getId());
101         data.setActiveVersion(1);
102         assertTrue(1 == data.getActiveVersion());
103         data.setHigherVersion(1);
104         assertTrue(1 == data.getHigherVersion());
105         data.setPolicyName("Test");
106         assertTrue("Test".equals(data.getPolicyName()));
107         data.setCreatedBy("Test");
108         assertTrue("Test".equals(data.getCreatedBy()));
109         data.setModifiedBy("Test");
110         assertTrue("Test".equals(data.getModifiedBy()));
111         data.setCreatedDate(new Date());
112         assertTrue(data.getCreatedDate() != null);
113         data.setModifiedDate(new Date());
114         assertTrue(data.getModifiedDate() != null);
115
116         assertNotNull(data.hashCode());
117
118         PolicyVersion version0 = new PolicyVersion();
119         PolicyVersion version1 = new PolicyVersion();
120         assertEquals(version0, version0);
121         assertEquals(version0, version1);
122         assertNotEquals(version0, null);
123         String helloString = "Hello";
124         Object helloObject = helloString;
125         assertNotEquals(version0, helloObject);
126
127         version0.setId(1);
128         assertNotEquals(version0, version1);
129         version1.setId(1);
130         assertEquals(version0, version1);
131         version0.setActiveVersion(1);
132         assertNotEquals(version0, version1);
133         version1.setActiveVersion(1);
134         assertEquals(version0, version1);
135         version0.setCreatedBy("Dorothy");
136         assertNotEquals(version0, version1);
137         version1.setCreatedBy("Dorothy");
138         assertEquals(version0, version1);
139         version1.setCreatedBy(null);
140         assertNotEquals(version0, version1);
141         version0.setCreatedBy(null);
142         assertEquals(version0, version1);
143         version1.setCreatedBy("Dorothy");
144         assertNotEquals(version0, version1);
145         version0.setCreatedBy("Dorothy");
146         assertEquals(version0, version1);
147         version0.setCreatedDate(new Date(12345L));
148         assertNotEquals(version0, version1);
149         version1.setCreatedDate(new Date(12345L));
150         assertEquals(version0, version1);
151         version1.setCreatedDate(null);
152         assertNotEquals(version0, version1);
153         version0.setCreatedDate(null);
154         assertEquals(version0, version1);
155         version1.setCreatedDate(new Date(12345L));
156         assertNotEquals(version0, version1);
157         version0.setCreatedDate(new Date(12345L));
158         assertEquals(version0, version1);
159         version0.setHigherVersion(1);
160         assertNotEquals(version0, version1);
161         version1.setHigherVersion(1);
162         assertEquals(version0, version1);
163         version0.setModifiedBy("Dorothy");
164         assertNotEquals(version0, version1);
165         version1.setModifiedBy("Dorothy");
166         assertEquals(version0, version1);
167         version1.setModifiedBy(null);
168         assertNotEquals(version0, version1);
169         version0.setModifiedBy(null);
170         assertEquals(version0, version1);
171         version1.setModifiedBy("Dorothy");
172         assertNotEquals(version0, version1);
173         version0.setModifiedBy("Dorothy");
174         assertEquals(version0, version1);
175         version0.setModifiedDate(new Date(12345L));
176         assertNotEquals(version0, version1);
177         version1.setModifiedDate(new Date(12345L));
178         assertEquals(version0, version1);
179         version1.setModifiedDate(null);
180         assertNotEquals(version0, version1);
181         version0.setModifiedDate(null);
182         assertEquals(version0, version1);
183         version1.setModifiedDate(new Date(12345L));
184         assertNotEquals(version0, version1);
185         version0.setModifiedDate(new Date(12345L));
186         assertEquals(version0, version1);
187         version0.setPolicyName("GoToOz");
188         assertNotEquals(version0, version1);
189         version1.setPolicyName("GoToOz");
190         assertEquals(version0, version1);
191         version1.setPolicyName(null);
192         assertNotEquals(version0, version1);
193         version0.setPolicyName(null);
194         assertEquals(version0, version1);
195         version1.setPolicyName("GoToOz");
196         assertNotEquals(version0, version1);
197         version0.setPolicyName("GoToOz");
198         assertEquals(version0, version1);
199
200         assertNotNull(version0.hashCode());
201         assertNotNull(version1.hashCode());
202         assertEquals(version0.hashCode(), version0.hashCode());
203
204         version0.setPolicyName("GoToOy");
205         assertNotEquals(version0, version1);
206         assertNotEquals(version0.hashCode(), version1.hashCode());
207     }
208
209     /**
210      * Test system log DB.
211      */
212     @Test
213     public void testSystemLogDb() {
214         SystemLogDb data = new SystemLogDb();
215         new SystemLogDb(1, "", "", "", "", "");
216         data.setId(1);
217         assertTrue(1 == data.getId());
218         data.setDescription("Test");
219         assertTrue("Test".equals(data.getDescription()));
220         data.setType("Test");
221         assertTrue("Test".equals(data.getType()));
222         data.setSystem("Test");
223         assertTrue("Test".equals(data.getSystem()));
224         data.setRemote("Test");
225         assertTrue("Test".equals(data.getRemote()));
226         data.setLogtype("Test");
227         assertTrue("Test".equals(data.getLogtype()));
228         data.setDate(new Date());
229         assertTrue(data.getDate() != null);
230     }
231
232     /**
233      * Test remote catalog values.
234      */
235     @Test
236     public void testRemoteCatalogValues() {
237         RemoteCatalogValues data = new RemoteCatalogValues();
238         data.setId(1);
239         assertTrue(1 == data.getId());
240         data.setName("Test");
241         assertTrue("Test".equals(data.getName()));
242         data.setValue("Test");
243         assertTrue("Test".equals(data.getValue()));
244     }
245
246     /**
247      * Test policy score.
248      */
249     @Test
250     public void testPolicyScore() {
251         PolicyScore data = new PolicyScore();
252         data.setId(1);
253         assertTrue(1 == data.getId());
254         data.setPolicyName("Test");
255         assertTrue("Test".equals(data.getPolicyName()));
256         data.setVersionExtension("Test");
257         assertTrue("Test".equals(data.getVersionExtension()));
258         data.setScore("Test");
259         assertTrue("Test".equals(data.getScore()));
260     }
261
262     /**
263      * Test policy editor scopes.
264      */
265     @Test
266     public void testPolicyEditorScopes() {
267         PolicyEditorScopes data = new PolicyEditorScopes();
268         data.prePersist();
269         data.preUpdate();
270         data.setId(1);
271         assertTrue(1 == data.getId());
272         data.setScopeName("Test");
273         assertTrue("Test".equals(data.getScopeName()));
274         data.setCreatedDate(new Date());
275         assertTrue(data.getCreatedDate() != null);
276         data.setModifiedDate(new Date());
277         assertTrue(data.getModifiedDate() != null);
278         data.setUserCreatedBy(userInfo);
279         assertTrue(data.getUserCreatedBy() != null);
280         data.setUserModifiedBy(userInfo);
281         assertTrue(data.getUserModifiedBy() != null);
282     }
283
284     /**
285      * Test descriptive scope.
286      */
287     @Test
288     public void testDescriptiveScope() {
289         DescriptiveScope data = new DescriptiveScope();
290         data.prePersist();
291         data.preUpdate();
292         data.setId(1);
293         assertTrue(1 == data.getId());
294         data.setScopeName("Test");
295         assertTrue("Test".equals(data.getScopeName()));
296         data.setSearch("Test");
297         assertTrue("Test".equals(data.getSearch()));
298         data.setCreatedDate(new Date());
299         assertTrue(data.getCreatedDate() != null);
300         data.setModifiedDate(new Date());
301         assertTrue(data.getModifiedDate() != null);
302         data.setUserCreatedBy(userInfo);
303         assertTrue(data.getUserCreatedBy() != null);
304         data.setUserModifiedBy(userInfo);
305         assertTrue(data.getUserModifiedBy() != null);
306     }
307
308     /**
309      * Test global role settings.
310      */
311     @Test
312     public void testGlobalRoleSettings() {
313         GlobalRoleSettings data = new GlobalRoleSettings();
314         new GlobalRoleSettings(true);
315         data.setRole("Test");
316         assertTrue("Test".equals(data.getRole()));
317         data.setLockdown(true);
318         assertTrue(data.isLockdown());
319     }
320 }