2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.pap.main.parameters;
24 import java.util.Base64;
25 import java.util.HashMap;
27 import java.util.TreeMap;
29 import org.onap.policy.common.parameters.ParameterGroup;
30 import org.onap.policy.common.utils.coder.Coder;
31 import org.onap.policy.common.utils.coder.CoderException;
32 import org.onap.policy.common.utils.coder.StandardCoder;
33 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
36 * Class to hold/create all parameters for test cases.
38 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
40 public class CommonTestData {
42 private static final String REST_SERVER_PASSWORD = "zb!XztG34";
43 private static final String REST_SERVER_USER = "healthcheck";
44 private static final int REST_SERVER_PORT = 6969;
45 private static final String REST_SERVER_HOST = "0.0.0.0";
46 private static final boolean REST_SERVER_HTTPS = true;
47 private static final boolean REST_SERVER_AAF = false;
48 public static final String PAP_GROUP_NAME = "PapGroup";
50 private static final Coder coder = new StandardCoder();
53 * Converts the contents of a map to a parameter class.
55 * @param source property map
56 * @param clazz class of object to be created from the map
57 * @return a new object represented by the map
59 public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
61 return coder.decode(coder.encode(source), clazz);
63 } catch (final CoderException e) {
64 throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
69 * Returns a property map for a PapParameterGroup map for test cases.
71 * @param name name of the parameters
73 * @return a property map suitable for constructing an object
75 public Map<String, Object> getPapParameterGroupMap(final String name) {
76 final Map<String, Object> map = new TreeMap<>();
78 map.put("name", name);
79 map.put("restServerParameters", getRestServerParametersMap(false));
80 map.put("pdpParameters", getPdpParametersMap());
81 map.put("databaseProviderParameters", getPolicyModelsProviderParametersMap());
87 * Returns a property map for a RestServerParameters map for test cases.
89 * @param isEmpty boolean value to represent that object created should be empty or not
90 * @return a property map suitable for constructing an object
92 public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
93 final Map<String, Object> map = new TreeMap<>();
94 map.put("https", REST_SERVER_HTTPS);
95 map.put("aaf", REST_SERVER_AAF);
98 map.put("host", REST_SERVER_HOST);
99 map.put("port", REST_SERVER_PORT);
100 map.put("userName", REST_SERVER_USER);
101 map.put("password", REST_SERVER_PASSWORD);
108 * Returns a property map for a PdpParameters map for test cases.
110 * @return a property map suitable for constructing an object
112 public Map<String, Object> getPdpParametersMap() {
113 final Map<String, Object> map = new TreeMap<>();
115 map.put("updateParameters", getPdpUpdateParametersMap());
116 map.put("stateChangeParameters", getPdpStateChangeParametersMap());
122 * Returns a property map for a PdpUpdateParameters map for test cases.
124 * @return a property map suitable for constructing an object
126 public Map<String, Object> getPdpUpdateParametersMap() {
127 return getPdpRequestParametersMap();
131 * Returns a property map for a PdpStateChangeParameters map for test cases.
133 * @return a property map suitable for constructing an object
135 public Map<String, Object> getPdpStateChangeParametersMap() {
136 return getPdpRequestParametersMap();
140 * Returns a property map for a PdpParameters map for test cases.
142 * @return a property map suitable for constructing an object
144 public Map<String, Object> getPdpRequestParametersMap() {
145 final Map<String, Object> map = new HashMap<>();
146 map.put("maxRetryCount", "1");
147 map.put("maxWaitMs", "2");
153 * Returns a property map for a PdpGroupDeploymentParameters map for test cases.
155 * @return a property map suitable for constructing an object
157 public Map<String, Object> getPdpGroupDeploymentParametersMap() {
158 final Map<String, Object> map = new TreeMap<>();
159 map.put("waitResponseMs", "1");
165 * Returns a property map for a PolicyModelsProviderParameters map for test cases.
167 * @return a property map suitable for constructing an object
169 public Map<String, Object> getPolicyModelsProviderParametersMap() {
170 final Map<String, Object> map = new TreeMap<>();
171 map.put("name", PolicyModelsProviderParameters.class.getSimpleName());
172 map.put("implementation", REST_SERVER_HTTPS);
173 map.put("databaseUrl", "jdbc:h2:mem:testdb");
174 map.put("databaseUser", "policy");
175 map.put("databasePassword", Base64.getEncoder().encodeToString("P01icY".getBytes()));
176 map.put("persistenceUnit", "PdpGroupTest");