Add PDP Group Deploy and Delete REST API stubs
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / parameters / CommonTestData.java
1 /*-
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.pap.main.parameters;
23
24 import java.util.Map;
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;
30
31 /**
32  * Class to hold/create all parameters for test cases.
33  *
34  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
35  */
36 public class CommonTestData {
37
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";
45
46     private static final Coder coder = new StandardCoder();
47
48     /**
49      * Converts the contents of a map to a parameter class.
50      *
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
54      */
55     public <T extends ParameterGroup> T toObject(Map<String, Object> source, Class<T> clazz) {
56         try {
57             return coder.decode(coder.encode(source), clazz);
58
59         } catch (CoderException e) {
60             throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
61         }
62     }
63
64     /**
65      * Returns a property map for a PapParameterGroup map for test cases.
66      * @param name name of the parameters
67      *
68      * @return a property map suitable for constructing an object
69      */
70     public Map<String, Object> getPapParameterGroupMap(String name) {
71         Map<String,Object> map = new TreeMap<>();
72
73         map.put("name", name);
74         map.put("restServerParameters", getRestServerParametersMap(false));
75         map.put("pdpGroupDeploymentParameters", getPdpGroupDeploymentParametersMap());
76
77         return map;
78     }
79
80     /**
81      * Returns a property map for a RestServerParameters map for test cases.
82      *
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
85      */
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);
90
91         if (!isEmpty) {
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);
96         }
97
98         return map;
99     }
100
101     /**
102      * Returns a property map for a PdpGroupDeploymentParameters map for test cases.
103      *
104      * @return a property map suitable for constructing an object
105      */
106     public Map<String,Object> getPdpGroupDeploymentParametersMap() {
107         Map<String,Object> map = new TreeMap<>();
108         map.put("waitResponseMs", "1");
109
110         return map;
111     }
112 }