Adding PdpGroup query & statechange providers
[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.Base64;
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.TreeMap;
28
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;
35
36 /**
37  * Class to hold/create all parameters for test cases.
38  *
39  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
40  */
41 public class CommonTestData {
42
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";
50
51     private static final Coder coder = new StandardCoder();
52
53     /**
54      * Converts the contents of a map to a parameter class.
55      *
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
59      */
60     public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
61         try {
62             return coder.decode(coder.encode(source), clazz);
63
64         } catch (final CoderException e) {
65             throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
66         }
67     }
68
69     /**
70      * Returns a property map for a PapParameterGroup map for test cases.
71      *
72      * @param name name of the parameters
73      *
74      * @return a property map suitable for constructing an object
75      */
76     public Map<String, Object> getPapParameterGroupMap(final String name) {
77         final Map<String, Object> map = new TreeMap<>();
78
79         map.put("name", name);
80         map.put("restServerParameters", getRestServerParametersMap(false));
81         map.put("pdpParameters", getPdpParametersMap());
82         map.put("databaseProviderParameters", getPolicyModelsProviderParametersMap());
83
84         return map;
85     }
86
87     /**
88      * Returns a property map for a RestServerParameters map for test cases.
89      *
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
92      */
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);
97
98         if (!isEmpty) {
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);
103         }
104
105         return map;
106     }
107
108     /**
109      * Returns a property map for a PdpParameters map for test cases.
110      *
111      * @return a property map suitable for constructing an object
112      */
113     public Map<String, Object> getPdpParametersMap() {
114         final Map<String, Object> map = new TreeMap<>();
115
116         map.put("updateParameters", getPdpUpdateParametersMap());
117         map.put("stateChangeParameters", getPdpStateChangeParametersMap());
118
119         return map;
120     }
121
122     /**
123      * Returns a property map for a PdpUpdateParameters map for test cases.
124      *
125      * @return a property map suitable for constructing an object
126      */
127     public Map<String, Object> getPdpUpdateParametersMap() {
128         return getPdpRequestParametersMap();
129     }
130
131     /**
132      * Returns a property map for a PdpStateChangeParameters map for test cases.
133      *
134      * @return a property map suitable for constructing an object
135      */
136     public Map<String, Object> getPdpStateChangeParametersMap() {
137         return getPdpRequestParametersMap();
138     }
139
140     /**
141      * Returns a property map for a PdpParameters map for test cases.
142      *
143      * @return a property map suitable for constructing an object
144      */
145     public Map<String, Object> getPdpRequestParametersMap() {
146         final Map<String, Object> map = new HashMap<>();
147         map.put("maxRetryCount", "1");
148         map.put("maxWaitMs", "2");
149
150         return map;
151     }
152
153     /**
154      * Returns a property map for a PdpGroupDeploymentParameters map for test cases.
155      *
156      * @return a property map suitable for constructing an object
157      */
158     public Map<String, Object> getPdpGroupDeploymentParametersMap() {
159         final Map<String, Object> map = new TreeMap<>();
160         map.put("waitResponseMs", "1");
161
162         return map;
163     }
164
165     /**
166      * Returns a property map for a PolicyModelsProviderParameters map for test cases.
167      *
168      * @return a property map suitable for constructing an object
169      */
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");
178
179         return map;
180     }
181 }