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;
34 import org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl;
37 * Class to hold/create all parameters for test cases.
39 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
41 public class CommonTestData {
43 private static final String REST_SERVER_PASSWORD = "zb!XztG34";
44 private static final String REST_SERVER_USER = "healthcheck";
45 private static final int REST_SERVER_PORT = 6969;
46 private static final String REST_SERVER_HOST = "0.0.0.0";
47 private static final boolean REST_SERVER_HTTPS = true;
48 private static final boolean REST_SERVER_AAF = false;
49 public static final String PAP_GROUP_NAME = "PapGroup";
51 private static final Coder coder = new StandardCoder();
54 * Converts the contents of a map to a parameter class.
56 * @param source property map
57 * @param clazz class of object to be created from the map
58 * @return a new object represented by the map
60 public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
62 return coder.decode(coder.encode(source), clazz);
64 } catch (final CoderException e) {
65 throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
70 * Returns a property map for a PapParameterGroup map for test cases.
72 * @param name name of the parameters
74 * @return a property map suitable for constructing an object
76 public Map<String, Object> getPapParameterGroupMap(final String name) {
77 final Map<String, Object> map = new TreeMap<>();
79 map.put("name", name);
80 map.put("restServerParameters", getRestServerParametersMap(false));
81 map.put("pdpParameters", getPdpParametersMap());
82 map.put("databaseProviderParameters", getPolicyModelsProviderParametersMap());
88 * Returns a property map for a RestServerParameters map for test cases.
90 * @param isEmpty boolean value to represent that object created should be empty or not
91 * @return a property map suitable for constructing an object
93 public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
94 final Map<String, Object> map = new TreeMap<>();
95 map.put("https", REST_SERVER_HTTPS);
96 map.put("aaf", REST_SERVER_AAF);
99 map.put("host", REST_SERVER_HOST);
100 map.put("port", REST_SERVER_PORT);
101 map.put("userName", REST_SERVER_USER);
102 map.put("password", REST_SERVER_PASSWORD);
109 * Returns a property map for a PdpParameters map for test cases.
111 * @return a property map suitable for constructing an object
113 public Map<String, Object> getPdpParametersMap() {
114 final Map<String, Object> map = new TreeMap<>();
116 map.put("updateParameters", getPdpUpdateParametersMap());
117 map.put("stateChangeParameters", getPdpStateChangeParametersMap());
123 * Returns a property map for a PdpUpdateParameters map for test cases.
125 * @return a property map suitable for constructing an object
127 public Map<String, Object> getPdpUpdateParametersMap() {
128 return getPdpRequestParametersMap();
132 * Returns a property map for a PdpStateChangeParameters map for test cases.
134 * @return a property map suitable for constructing an object
136 public Map<String, Object> getPdpStateChangeParametersMap() {
137 return getPdpRequestParametersMap();
141 * Returns a property map for a PdpParameters map for test cases.
143 * @return a property map suitable for constructing an object
145 public Map<String, Object> getPdpRequestParametersMap() {
146 final Map<String, Object> map = new HashMap<>();
147 map.put("maxRetryCount", "1");
148 map.put("maxWaitMs", "2");
154 * Returns a property map for a PdpGroupDeploymentParameters map for test cases.
156 * @return a property map suitable for constructing an object
158 public Map<String, Object> getPdpGroupDeploymentParametersMap() {
159 final Map<String, Object> map = new TreeMap<>();
160 map.put("waitResponseMs", "1");
166 * Returns a property map for a PolicyModelsProviderParameters map for test cases.
168 * @return a property map suitable for constructing an object
170 public Map<String, Object> getPolicyModelsProviderParametersMap() {
171 final Map<String, Object> map = new TreeMap<>();
172 map.put("name", PolicyModelsProviderParameters.class.getSimpleName());
173 map.put("implementation", DatabasePolicyModelsProviderImpl.class.getCanonicalName());
174 map.put("databaseUrl", "jdbc:h2:mem:testdb");
175 map.put("databaseUser", "policy");
176 map.put("databasePassword", Base64.getEncoder().encodeToString("P01icY".getBytes()));
177 map.put("persistenceUnit", "ToscaConceptTest");