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.HashMap;
26 import java.util.TreeMap;
27 import org.onap.policy.common.parameters.ParameterGroup;
28 import org.onap.policy.common.utils.coder.Coder;
29 import org.onap.policy.common.utils.coder.CoderException;
30 import org.onap.policy.common.utils.coder.StandardCoder;
33 * Class to hold/create all parameters for test cases.
35 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
37 public class CommonTestData {
39 private static final String REST_SERVER_PASSWORD = "zb!XztG34";
40 private static final String REST_SERVER_USER = "healthcheck";
41 private static final int REST_SERVER_PORT = 6969;
42 private static final String REST_SERVER_HOST = "0.0.0.0";
43 private static final boolean REST_SERVER_HTTPS = true;
44 private static final boolean REST_SERVER_AAF = false;
45 public static final String PAP_GROUP_NAME = "PapGroup";
47 private static final Coder coder = new StandardCoder();
50 * Converts the contents of a map to a parameter class.
52 * @param source property map
53 * @param clazz class of object to be created from the map
54 * @return a new object represented by the map
56 public <T extends ParameterGroup> T toObject(Map<String, Object> source, Class<T> clazz) {
58 return coder.decode(coder.encode(source), clazz);
60 } catch (CoderException e) {
61 throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
66 * Returns a property map for a PapParameterGroup map for test cases.
67 * @param name name of the parameters
69 * @return a property map suitable for constructing an object
71 public Map<String, Object> getPapParameterGroupMap(String name) {
72 Map<String,Object> map = new TreeMap<>();
74 map.put("name", name);
75 map.put("restServerParameters", getRestServerParametersMap(false));
76 map.put("pdpParameters", getPdpParametersMap());
82 * Returns a property map for a RestServerParameters map for test cases.
84 * @param isEmpty boolean value to represent that object created should be empty or not
85 * @return a property map suitable for constructing an object
87 public Map<String,Object> getRestServerParametersMap(final boolean isEmpty) {
88 Map<String,Object> map = new TreeMap<>();
89 map.put("https", REST_SERVER_HTTPS);
90 map.put("aaf", REST_SERVER_AAF);
93 map.put("host", REST_SERVER_HOST);
94 map.put("port", REST_SERVER_PORT);
95 map.put("userName", REST_SERVER_USER);
96 map.put("password", REST_SERVER_PASSWORD);
103 * Returns a property map for a PdpParameters map for test cases.
104 * @return a property map suitable for constructing an object
106 public Map<String,Object> getPdpParametersMap() {
107 Map<String,Object> map = new TreeMap<>();
109 map.put("updateParameters", getPdpUpdateParametersMap());
110 map.put("stateChangeParameters", getPdpStateChangeParametersMap());
116 * Returns a property map for a PdpUpdateParameters map for test cases.
117 * @return a property map suitable for constructing an object
119 public Map<String,Object> getPdpUpdateParametersMap() {
120 return getPdpRequestParametersMap();
124 * Returns a property map for a PdpStateChangeParameters map for test cases.
125 * @return a property map suitable for constructing an object
127 public Map<String,Object> getPdpStateChangeParametersMap() {
128 return getPdpRequestParametersMap();
132 * Returns a property map for a PdpParameters map for test cases.
133 * @return a property map suitable for constructing an object
135 public Map<String,Object> getPdpRequestParametersMap() {
136 Map<String, Object> map = new HashMap<>();
137 map.put("maxRetryCount", "1");
138 map.put("maxWaitMs", "2");
144 * Returns a property map for a PdpGroupDeploymentParameters map for test cases.
146 * @return a property map suitable for constructing an object
148 public Map<String,Object> getPdpGroupDeploymentParametersMap() {
149 Map<String,Object> map = new TreeMap<>();
150 map.put("waitResponseMs", "1");