7c740c4b2f177e8c4147574f906a530966fb130d
[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-2020 Nordix Foundation.
4  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
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.models.sim.pdp.parameters;
23
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.TreeMap;
28 import org.onap.policy.common.endpoints.parameters.TopicParameters;
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
34 /**
35  * Class to hold/create all parameters for test cases.
36  *
37  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
38  */
39 public class CommonTestData {
40
41     public static final String PDP_SIMULATOR_GROUP_NAME = "PdpSimulatorParameterGroup";
42     public static final long TIME_INTERVAL = 2000;
43     public static final String PDP_NAME = "apex-pdp";
44     public static final String VERSION = "0.0.1";
45     public static final String PDP_TYPE = "apex";
46     public static final String PDP_GROUP = "defaultGroup";
47     public static final String DESCRIPTION = "Pdp status for HealthCheck";
48     public static final String POLICY_NAME = "onap.controllloop.operational.apex.BBS";
49     public static final String POLICY_VERSION = "0.0.1";
50     protected static final List<ToscaPolicyTypeIdentifierParameters> SUPPORTED_POLICY_TYPES =
51             Arrays.asList(getSupportedPolicyTypes(POLICY_NAME, POLICY_VERSION));
52     public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
53     private static final String REST_SERVER_PASS = "zb!XztG34";
54     private static final String REST_SERVER_USER = "healthcheck";
55     private static final int REST_SERVER_PORT = 6969;
56     private static final String REST_SERVER_HOST = "0.0.0.0";
57     private static final boolean REST_SERVER_HTTPS = true;
58     private static final boolean REST_SERVER_AAF = false;
59
60     public static final Coder coder = new StandardCoder();
61
62     /**
63      * Returns supported policy types for test cases.
64      *
65      * @return supported policy types
66      */
67     public static ToscaPolicyTypeIdentifierParameters getSupportedPolicyTypes(final String name, final String version) {
68         final ToscaPolicyTypeIdentifierParameters policyTypeIdentParameters = new ToscaPolicyTypeIdentifierParameters();
69         policyTypeIdentParameters.setName(name);
70         policyTypeIdentParameters.setVersion(version);
71         return policyTypeIdentParameters;
72     }
73
74     /**
75      * Returns topic parameters for test cases.
76      *
77      * @return topic parameters
78      */
79     public static TopicParameters getTopicParams() {
80         final TopicParameters topicParams = new TopicParameters();
81         topicParams.setTopic("POLICY-PDP-PAP");
82         topicParams.setTopicCommInfrastructure("dmaap");
83         topicParams.setServers(Arrays.asList("message-router"));
84         return topicParams;
85     }
86
87     /**
88      * Converts the contents of a map to a parameter class.
89      *
90      * @param source property map
91      * @param clazz class of object to be created from the map
92      * @return a new object represented by the map
93      */
94     public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
95         try {
96             return coder.decode(coder.encode(source), clazz);
97
98         } catch (final CoderException e) {
99             throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
100         }
101     }
102
103     /**
104      * Returns a property map for a PdpSimulatorParameterGroup map for test cases.
105      *
106      * @param name name of the parameters
107      *
108      * @return a property map suitable for constructing an object
109      */
110     public Map<String, Object> getPdpSimulatorParameterGroupMap(final String name) {
111         final Map<String, Object> map = new TreeMap<>();
112
113         map.put("name", name);
114         map.put("restServerParameters", getRestServerParametersMap(false));
115         map.put("pdpStatusParameters", getPdpStatusParametersMap(false));
116         map.put("topicParameterGroup", getTopicParametersMap(false));
117         return map;
118     }
119
120     /**
121      * Returns a property map for a RestServerParameters map for test cases.
122      *
123      * @param isEmpty boolean value to represent that object created should be empty or not
124      * @return a property map suitable for constructing an object
125      */
126     public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
127         final Map<String, Object> map = new TreeMap<>();
128         map.put("https", REST_SERVER_HTTPS);
129         map.put("aaf", REST_SERVER_AAF);
130
131         if (!isEmpty) {
132             map.put("host", REST_SERVER_HOST);
133             map.put("port", REST_SERVER_PORT);
134             map.put("userName", REST_SERVER_USER);
135             map.put("password", REST_SERVER_PASS);
136         }
137
138         return map;
139     }
140
141     /**
142      * Returns a property map for a PdpStatusParameters map for test cases.
143      *
144      * @param isEmpty boolean value to represent that object created should be empty or not
145      * @return a property map suitable for constructing an object
146      */
147     public Map<String, Object> getPdpStatusParametersMap(final boolean isEmpty) {
148         final Map<String, Object> map = new TreeMap<>();
149         if (!isEmpty) {
150             map.put("timeIntervalMs", TIME_INTERVAL);
151             map.put("pdpName", PDP_NAME);
152             map.put("version", VERSION);
153             map.put("pdpType", PDP_TYPE);
154             map.put("pdpGroup", PDP_GROUP);
155             map.put("description", DESCRIPTION);
156             map.put("supportedPolicyTypes", SUPPORTED_POLICY_TYPES);
157         }
158
159         return map;
160     }
161
162     /**
163      * Returns a property map for a TopicParameters map for test cases.
164      *
165      * @param isEmpty boolean value to represent that object created should be empty or not
166      * @return a property map suitable for constructing an object
167      */
168     public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
169         final Map<String, Object> map = new TreeMap<>();
170         if (!isEmpty) {
171             map.put("topicSources", TOPIC_PARAMS);
172             map.put("topicSinks", TOPIC_PARAMS);
173         }
174         return map;
175     }
176 }