Adding pdp simulator for testing purposes
[policy/models.git] / models-sim / policy-models-sim-pdp / src / test / java / org / onap / policy / models / sim / pdp / parameters / CommonTestData.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.sim.pdp.parameters;
22
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.TreeMap;
27
28 import org.onap.policy.common.parameters.ParameterGroup;
29 import org.onap.policy.common.utils.coder.Coder;
30 import org.onap.policy.common.utils.coder.CoderException;
31 import org.onap.policy.common.utils.coder.StandardCoder;
32
33 /**
34  * Class to hold/create all parameters for test cases.
35  *
36  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
37  */
38 public class CommonTestData {
39
40     public static final String PDP_SIMULATOR_GROUP_NAME = "PdpSimulatorParameterGroup";
41     public static final long TIME_INTERVAL = 2000;
42     public static final String PDP_NAME = "apex-pdp";
43     public static final String VERSION = "0.0.1";
44     public static final String PDP_TYPE = "apex";
45     public static final String DESCRIPTION = "Pdp status for HealthCheck";
46     public static final String POLICY_NAME = "onap.controllloop.operational.apex.BBS";
47     public static final String POLICY_VERSION = "0.0.1";
48     public static final List<ToscaPolicyTypeIdentifierParameters> SUPPORTED_POLICY_TYPES =
49             Arrays.asList(getSupportedPolicyTypes(POLICY_NAME, POLICY_VERSION));
50     private static final String REST_SERVER_PASSWORD = "zb!XztG34";
51     private static final String REST_SERVER_USER = "healthcheck";
52     private static final int REST_SERVER_PORT = 6969;
53     private static final String REST_SERVER_HOST = "0.0.0.0";
54     private static final boolean REST_SERVER_HTTPS = true;
55     private static final boolean REST_SERVER_AAF = false;
56
57     public static final Coder coder = new StandardCoder();
58
59     /**
60      * Returns supported policy types for test cases.
61      *
62      * @return supported policy types
63      */
64     public static ToscaPolicyTypeIdentifierParameters getSupportedPolicyTypes(final String name, final String version) {
65         final ToscaPolicyTypeIdentifierParameters policyTypeIdentParameters = new ToscaPolicyTypeIdentifierParameters();
66         policyTypeIdentParameters.setName(name);
67         policyTypeIdentParameters.setVersion(version);
68         return policyTypeIdentParameters;
69     }
70
71     /**
72      * Converts the contents of a map to a parameter class.
73      *
74      * @param source property map
75      * @param clazz class of object to be created from the map
76      * @return a new object represented by the map
77      */
78     public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
79         try {
80             return coder.decode(coder.encode(source), clazz);
81
82         } catch (final CoderException e) {
83             throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
84         }
85     }
86
87     /**
88      * Returns a property map for a PdpSimulatorParameterGroup map for test cases.
89      *
90      * @param name name of the parameters
91      *
92      * @return a property map suitable for constructing an object
93      */
94     public Map<String, Object> getPdpSimulatorParameterGroupMap(final String name) {
95         final Map<String, Object> map = new TreeMap<>();
96
97         map.put("name", name);
98         map.put("restServerParameters", getRestServerParametersMap(false));
99         map.put("pdpStatusParameters", getPdpStatusParametersMap(false));
100
101         return map;
102     }
103
104     /**
105      * Returns a property map for a RestServerParameters map for test cases.
106      *
107      * @param isEmpty boolean value to represent that object created should be empty or not
108      * @return a property map suitable for constructing an object
109      */
110     public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
111         final Map<String, Object> map = new TreeMap<>();
112         map.put("https", REST_SERVER_HTTPS);
113         map.put("aaf", REST_SERVER_AAF);
114
115         if (!isEmpty) {
116             map.put("host", REST_SERVER_HOST);
117             map.put("port", REST_SERVER_PORT);
118             map.put("userName", REST_SERVER_USER);
119             map.put("password", REST_SERVER_PASSWORD);
120         }
121
122         return map;
123     }
124
125     /**
126      * Returns a property map for a PdpStatusParameters map for test cases.
127      *
128      * @param isEmpty boolean value to represent that object created should be empty or not
129      * @return a property map suitable for constructing an object
130      */
131     public Map<String, Object> getPdpStatusParametersMap(final boolean isEmpty) {
132         final Map<String, Object> map = new TreeMap<>();
133         if (!isEmpty) {
134             map.put("timeIntervalMs", TIME_INTERVAL);
135             map.put("pdpName", PDP_NAME);
136             map.put("version", VERSION);
137             map.put("pdpType", PDP_TYPE);
138             map.put("description", DESCRIPTION);
139             map.put("supportedPolicyTypes", SUPPORTED_POLICY_TYPES);
140         }
141
142         return map;
143     }
144 }