2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.rest.jpa;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
29 import java.util.Date;
30 import java.util.HashSet;
31 import java.util.LinkedHashSet;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.policy.common.logging.flexlogger.FlexLogger;
37 import org.onap.policy.common.logging.flexlogger.Logger;
39 public class CommonDictionaryJpaTest {
41 private static Logger logger = FlexLogger.getLogger(CommonDictionaryJpaTest.class);
42 private UserInfo userInfo;
45 * Initiations for testing.
47 * @throws Exception on test initiation errors
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");
59 public void testAttribute() {
60 Attribute data = new Attribute();
62 assertTrue(1 == data.getId());
63 data.setCategoryBean(new Category());
64 assertTrue(data.getCategoryBean() != null);
65 data.setConstraintType(new ConstraintType());
66 assertTrue(data.getConstraintType() != null);
67 data.setConstraintValues(new HashSet<>());
68 assertTrue(data.getConstraintValues() != null);
69 data.addConstraintValue(new ConstraintValue());
70 data.removeConstraintValue(new ConstraintValue());
71 data.removeAllConstraintValues();
74 new Attribute("Test");
75 new Attribute(new Attribute());
76 data.setAttributeValue("Test");
77 assertTrue("Test".equals(data.getAttributeValue()));
78 data.setDescription("Test");
79 assertTrue("Test".equals(data.getDescription()));
80 data.setXacmlId("Test");
81 assertTrue("Test".equals(data.getXacmlId()));
82 data.setDatatypeBean(new Datatype());
83 assertTrue(data.getDatatypeBean() != null);
84 data.setIsDesignator(true);
85 assertTrue(data.isDesignator());
86 data.setIssuer("Test");
87 assertTrue("Test".equals(data.getIssuer()));
88 data.setMustBePresent(true);
89 assertTrue(data.isMustBePresent());
90 data.setPriority("Test");
91 assertTrue("Test".equals(data.getPriority()));
92 data.setSelectorPath("Test");
93 assertTrue("Test".equals(data.getSelectorPath()));
94 data.setCreatedDate(new Date());
95 assertTrue(data.getCreatedDate() != null);
96 data.setModifiedDate(new Date());
97 assertTrue(data.getModifiedDate() != null);
98 data.setUserCreatedBy(userInfo);
99 assertTrue(data.getUserCreatedBy() != null);
100 data.setUserModifiedBy(userInfo);
101 assertTrue(data.getUserModifiedBy() != null);
103 ConstraintValue constraintValue = new ConstraintValue("Greeting", "Hello");
104 data.getConstraintValues().add(constraintValue);
105 assertEquals("Hello", data.getConstraintValues().iterator().next().getValue());
107 data.removeConstraintValue(constraintValue);
108 assertTrue(data.getConstraintValues().isEmpty());
110 data.addConstraintValue(constraintValue);
111 assertEquals("Hello", data.getConstraintValues().iterator().next().getValue());
113 data.setConstraintValues(null);
114 assertNull(data.getConstraintValues());
116 data.addConstraintValue(constraintValue);
117 assertEquals("Hello", data.getConstraintValues().iterator().next().getValue());
119 data.removeAllConstraintValues();
120 assertTrue(data.getConstraintValues().isEmpty());
122 data.setConstraintValues(null);
123 assertNull(data.getConstraintValues());
125 data.removeAllConstraintValues();
126 assertNull(data.getConstraintValues());
128 data.addConstraintValue(constraintValue);
129 assertEquals("Hello", data.getConstraintValues().iterator().next().getValue());
131 data.setConstraintValues(null);
132 assertNull(data.getConstraintValues());
134 Set<ConstraintValue> constraintValueSet = new LinkedHashSet<>();
135 constraintValueSet.add(constraintValue);
137 data.setConstraintValues(null);
138 assertNull(data.getConstraintValues());
140 data.setConstraintValues(constraintValueSet);
141 assertEquals("Hello", data.getConstraintValues().iterator().next().getValue());
143 Attribute data2 = new Attribute(data);
144 assertEquals("Hello", data2.getConstraintValues().iterator().next().getValue());
146 data.setIsDesignator(true);
147 assertTrue(data.isDesignator());
149 data.setIsDesignator(false);
150 assertFalse(data.isDesignator());
154 public void testOnapName() {
155 OnapName data = new OnapName();
159 assertTrue(1 == data.getId());
160 data.setName("Test");
161 assertTrue("Test".equals(data.getName()));
162 data.setDescription("Test");
163 assertTrue("Test".equals(data.getDescription()));
164 data.setCreatedDate(new Date());
165 assertTrue(data.getCreatedDate() != null);
166 data.setModifiedDate(new Date());
167 assertTrue(data.getModifiedDate() != null);
168 data.setUserCreatedBy(userInfo);
169 assertTrue(data.getUserCreatedBy() != null);
170 data.setUserModifiedBy(userInfo);
171 assertTrue(data.getUserModifiedBy() != null);
175 public void testRiskType() {
176 RiskType data = new RiskType();
180 assertTrue(1 == data.getId());
181 data.setName("Test");
182 assertTrue("Test".equals(data.getName()));
183 data.setDescription("Test");
184 assertTrue("Test".equals(data.getDescription()));
185 data.setCreatedDate(new Date());
186 assertTrue(data.getCreatedDate() != null);
187 data.setModifiedDate(new Date());
188 assertTrue(data.getModifiedDate() != null);
189 data.setUserCreatedBy(userInfo);
190 assertTrue(data.getUserCreatedBy() != null);
191 data.setUserModifiedBy(userInfo);
192 assertTrue(data.getUserModifiedBy() != null);
196 public void testSafePolicyWarning() {
197 SafePolicyWarning data = new SafePolicyWarning();
199 assertTrue(1 == data.getId());
200 data.setName("Test");
201 assertTrue("Test".equals(data.getName()));
202 data.setMessage("Test");
203 assertTrue("Test".equals(data.getMessage()));
204 data.setRiskType("Test");
205 assertTrue("Test".equals(data.getRiskType()));