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;
25 import java.util.TreeMap;
26 import org.onap.policy.common.parameters.ParameterGroup;
27 import org.onap.policy.common.utils.coder.Coder;
28 import org.onap.policy.common.utils.coder.CoderException;
29 import org.onap.policy.common.utils.coder.StandardCoder;
32 * Class to hold/create all parameters for test cases.
34 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
36 public class CommonTestData {
38 private static final String REST_SERVER_PASSWORD = "zb!XztG34";
39 private static final String REST_SERVER_USER = "healthcheck";
40 private static final int REST_SERVER_PORT = 6969;
41 private static final String REST_SERVER_HOST = "0.0.0.0";
42 private static final boolean REST_SERVER_HTTPS = true;
43 private static final boolean REST_SERVER_AAF = false;
44 public static final String PAP_GROUP_NAME = "PapGroup";
46 private static final Coder coder = new StandardCoder();
49 * Converts the contents of a map to a parameter class.
51 * @param source property map
52 * @param clazz class of object to be created from the map
53 * @return a new object represented by the map
55 public <T extends ParameterGroup> T toObject(Map<String, Object> source, Class<T> clazz) {
57 return coder.decode(coder.encode(source), clazz);
59 } catch (CoderException e) {
60 throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
65 * Returns a property map for a PapParameterGroup map for test cases.
66 * @param name name of the parameters
68 * @return a property map suitable for constructing an object
70 public Map<String, Object> getPapParameterGroupMap(String name) {
71 Map<String,Object> map = new TreeMap<>();
73 map.put("name", name);
74 map.put("restServerParameters", getRestServerParametersMap(false));
75 map.put("pdpGroupDeploymentParameters", getPdpGroupDeploymentParametersMap());
81 * Returns a property map for a RestServerParameters map for test cases.
83 * @param isEmpty boolean value to represent that object created should be empty or not
84 * @return a property map suitable for constructing an object
86 public Map<String,Object> getRestServerParametersMap(final boolean isEmpty) {
87 Map<String,Object> map = new TreeMap<>();
88 map.put("https", REST_SERVER_HTTPS);
89 map.put("aaf", REST_SERVER_AAF);
92 map.put("host", REST_SERVER_HOST);
93 map.put("port", REST_SERVER_PORT);
94 map.put("userName", REST_SERVER_USER);
95 map.put("password", REST_SERVER_PASSWORD);
102 * Returns a property map for a PdpGroupDeploymentParameters map for test cases.
104 * @return a property map suitable for constructing an object
106 public Map<String,Object> getPdpGroupDeploymentParametersMap() {
107 Map<String,Object> map = new TreeMap<>();
108 map.put("waitResponseMs", "1");