2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.drools.protocol.configuration;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.UUID;
31 import org.junit.Test;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class PdpdConfigurationTest {
37 private static final Logger logger = LoggerFactory.getLogger(PdpdConfigurationTest.class);
39 private static final String REQUEST_ID = UUID.randomUUID().toString();
40 private static final String REQUEST_ID2 = UUID.randomUUID().toString();
42 private static final String ENTITY = "entity1";
43 private static final String ENTITY2 = "entity2";
45 private static final String PROPERTY1 = "property1";
46 private static final String PROPERTY2 = "property2";
48 private static final String VALUE1 = "value1";
49 private static final String VALUE2 = "value2";
51 private static final String ARTIFACT = "org.onap.artifact";
52 private static final String GROUPID = "group";
53 private static final String VERSION = "1.0.0";
55 private static final String ARTIFACT2 = "org.onap.artifact2";
56 private static final String GROUPID2 = "group2";
57 private static final String VERSION2 = "1.0.1";
59 private static final String NAME = "name";
60 private static final String OPERATION = "operation";
62 private static final String NAME2 = "name2";
63 private static final String OPERATION2 = "operation2";
68 // Empty constructor test
70 DroolsConfiguration drools = new DroolsConfiguration();
71 drools.set("artifactId", ARTIFACT);
72 drools.set("groupId", GROUPID);
73 drools.set("version", VERSION);
74 drools.set(PROPERTY1, VALUE1);
76 assertTrue(drools.equals(drools));
77 assertFalse(drools.equals(new Object()));
79 logger.info("Drools HashCode {}", drools.hashCode());
82 // Constructor with values test get calls
84 DroolsConfiguration drools2 = new DroolsConfiguration(
85 drools.get("artifactId"),
86 drools.get("groupId"),
87 drools.get("version"));
93 drools2.set(PROPERTY1, drools.get(PROPERTY1));
95 assertTrue(drools.equals(drools2));
100 drools2.withArtifactId(ARTIFACT2).withGroupId(GROUPID2).withVersion(VERSION2)
101 .withAdditionalProperty(PROPERTY2, VALUE2);
103 assertFalse(drools.equals(drools2));
106 // Test get additional properties
108 assertEquals(drools.getAdditionalProperties().size(), 1);
113 assertEquals(DroolsConfiguration.NOT_FOUND_VALUE,
114 drools.declaredPropertyOrNotFound(PROPERTY2, DroolsConfiguration.NOT_FOUND_VALUE));
116 logger.info("drools {}", drools);
117 logger.info("drools2 {}", drools2);
120 // Test Controller Default Constructor
122 ControllerConfiguration controller = new ControllerConfiguration();
128 controller.set("name", NAME);
129 controller.set("operation", OPERATION);
130 controller.set("drools", drools);
131 controller.set(PROPERTY1, VALUE1);
133 assertTrue(controller.equals(controller));
134 assertFalse(controller.equals(new Object()));
136 logger.info("Controller HashCode {}", controller.hashCode());
139 // Controller Constructor gets
141 ControllerConfiguration controller2 = new ControllerConfiguration(
142 controller.get("name"),
143 controller.get("operation"),
144 controller.get("drools"));
150 controller2.set(PROPERTY1, controller.get(PROPERTY1));
152 assertTrue(controller.equals(controller2));
158 controller2.withDrools(drools2).withName(NAME2)
159 .withOperation(OPERATION2).withAdditionalProperty(PROPERTY2, VALUE2);
161 assertFalse(controller.equals(controller2));
164 // Test additional properties
166 assertEquals(controller.getAdditionalProperties().size(), 1);
171 assertEquals(ControllerConfiguration.NOT_FOUND_VALUE,
172 controller.declaredPropertyOrNotFound(PROPERTY2, ControllerConfiguration.NOT_FOUND_VALUE));
177 logger.info("Controller {}", controller);
178 logger.info("Controller2 {}", controller2);
181 // PDP Configuration empty constructor
183 PdpdConfiguration config = new PdpdConfiguration();
189 config.set("requestID", REQUEST_ID);
190 config.set("entity", ENTITY);
191 List<ControllerConfiguration> controllers = new ArrayList<>();
192 controllers.add(controller);
193 config.set("controllers", controllers);
194 config.set(PROPERTY1, VALUE1);
196 assertTrue(config.equals(config));
197 assertFalse(config.equals(new Object()));
199 logger.info("Config HashCode {}", config.hashCode());
202 // Test constructor with values
205 PdpdConfiguration config2 = new PdpdConfiguration(
206 config.get("requestID"),
207 config.get("entity"),
208 config.get("controllers"));
214 config2.set(PROPERTY1, config.get(PROPERTY1));
216 assertTrue(config.equals(config2));
221 List<ControllerConfiguration> controllers2 = new ArrayList<>();
222 controllers2.add(controller2);
223 config2.withRequestID(REQUEST_ID2).withEntity(ENTITY2).withController(controllers2);
225 assertFalse(config.equals(config2));
228 // Test additional properties
231 assertEquals(config.getAdditionalProperties().size(), 1);
236 assertEquals(ControllerConfiguration.NOT_FOUND_VALUE,
237 config.declaredPropertyOrNotFound(PROPERTY2, ControllerConfiguration.NOT_FOUND_VALUE));
242 logger.info("Config {}", config);
243 logger.info("Config2 {}", config2);
248 public void testConstructor() {
249 PdpdConfiguration config = new PdpdConfiguration(REQUEST_ID, ENTITY, null);
250 assertEquals(config.getRequestID(), REQUEST_ID);
251 assertEquals(config.getEntity(), ENTITY);