Changes to PAP infrastructure to support PDP
[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.HashMap;
25 import java.util.Map;
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;
31
32 /**
33  * Class to hold/create all parameters for test cases.
34  *
35  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
36  */
37 public class CommonTestData {
38
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";
46
47     private static final Coder coder = new StandardCoder();
48
49     /**
50      * Converts the contents of a map to a parameter class.
51      *
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
55      */
56     public <T extends ParameterGroup> T toObject(Map<String, Object> source, Class<T> clazz) {
57         try {
58             return coder.decode(coder.encode(source), clazz);
59
60         } catch (CoderException e) {
61             throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
62         }
63     }
64
65     /**
66      * Returns a property map for a PapParameterGroup map for test cases.
67      * @param name name of the parameters
68      *
69      * @return a property map suitable for constructing an object
70      */
71     public Map<String, Object> getPapParameterGroupMap(String name) {
72         Map<String,Object> map = new TreeMap<>();
73
74         map.put("name", name);
75         map.put("restServerParameters", getRestServerParametersMap(false));
76         map.put("pdpParameters", getPdpParametersMap());
77
78         return map;
79     }
80
81     /**
82      * Returns a property map for a RestServerParameters map for test cases.
83      *
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
86      */
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);
91
92         if (!isEmpty) {
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);
97         }
98
99         return map;
100     }
101
102     /**
103      * Returns a property map for a PdpParameters map for test cases.
104      * @return a property map suitable for constructing an object
105      */
106     public Map<String,Object> getPdpParametersMap() {
107         Map<String,Object> map = new TreeMap<>();
108
109         map.put("updateParameters", getPdpUpdateParametersMap());
110         map.put("stateChangeParameters", getPdpStateChangeParametersMap());
111
112         return map;
113     }
114
115     /**
116      * Returns a property map for a PdpUpdateParameters map for test cases.
117      * @return a property map suitable for constructing an object
118      */
119     public Map<String,Object> getPdpUpdateParametersMap() {
120         return getPdpRequestParametersMap();
121     }
122
123     /**
124      * Returns a property map for a PdpStateChangeParameters map for test cases.
125      * @return a property map suitable for constructing an object
126      */
127     public Map<String,Object> getPdpStateChangeParametersMap() {
128         return getPdpRequestParametersMap();
129     }
130
131     /**
132      * Returns a property map for a PdpParameters map for test cases.
133      * @return a property map suitable for constructing an object
134      */
135     public Map<String,Object> getPdpRequestParametersMap() {
136         Map<String, Object> map = new HashMap<>();
137         map.put("maxRetryCount", "1");
138         map.put("maxWaitMs", "2");
139
140         return map;
141     }
142
143     /**
144      * Returns a property map for a PdpGroupDeploymentParameters map for test cases.
145      *
146      * @return a property map suitable for constructing an object
147      */
148     public Map<String,Object> getPdpGroupDeploymentParametersMap() {
149         Map<String,Object> map = new TreeMap<>();
150         map.put("waitResponseMs", "1");
151
152         return map;
153     }
154 }