2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020, 2024 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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.sim.pdp.parameters;
24 import java.util.List;
26 import java.util.TreeMap;
27 import org.onap.policy.common.endpoints.parameters.TopicParameters;
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;
34 * Class to hold/create all parameters for test cases.
36 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
38 public class CommonTestData {
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 PDP_GROUP = "defaultGroup";
46 public static final String DESCRIPTION = "Pdp status for HealthCheck";
47 public static final String POLICY_NAME = "onap.controllloop.operational.apex.BBS";
48 public static final String POLICY_VERSION = "0.0.1";
49 protected static final List<ToscaPolicyTypeIdentifierParameters> SUPPORTED_POLICY_TYPES =
50 List.of(getSupportedPolicyTypes(POLICY_NAME, POLICY_VERSION));
51 public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
52 private static final String REST_SERVER_PASS = "zb!XztG34";
53 private static final String REST_SERVER_USER = "healthcheck";
54 private static final int REST_SERVER_PORT = 6969;
55 private static final String REST_SERVER_HOST = "0.0.0.0";
56 private static final boolean REST_SERVER_HTTPS = true;
58 public static final Coder coder = new StandardCoder();
61 * Returns supported policy types for test cases.
63 * @return supported policy types
65 public static ToscaPolicyTypeIdentifierParameters getSupportedPolicyTypes(final String name, final String version) {
66 final ToscaPolicyTypeIdentifierParameters policyTypeIdentParameters = new ToscaPolicyTypeIdentifierParameters();
67 policyTypeIdentParameters.setName(name);
68 policyTypeIdentParameters.setVersion(version);
69 return policyTypeIdentParameters;
73 * Returns topic parameters for test cases.
75 * @return topic parameters
77 public static TopicParameters getTopicParams() {
78 final TopicParameters topicParams = new TopicParameters();
79 topicParams.setTopic("POLICY-PDP-PAP");
80 topicParams.setTopicCommInfrastructure("kafka");
81 topicParams.setServers(List.of("localhost:9092"));
86 * Converts the contents of a map to a parameter class.
88 * @param source property map
89 * @param clazz class of object to be created from the map
90 * @return a new object represented by the map
92 public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
94 return coder.decode(coder.encode(source), clazz);
96 } catch (final CoderException e) {
97 throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
102 * Returns a property map for a PdpSimulatorParameterGroup map for test cases.
104 * @param name name of the parameters
106 * @return a property map suitable for constructing an object
108 public Map<String, Object> getPdpSimulatorParameterGroupMap(final String name) {
109 final Map<String, Object> map = new TreeMap<>();
111 map.put("name", name);
112 map.put("restServerParameters", getRestServerParametersMap(false));
113 map.put("pdpStatusParameters", getPdpStatusParametersMap(false));
114 map.put("topicParameterGroup", getTopicParametersMap(false));
119 * Returns a property map for a RestServerParameters map for test cases.
121 * @param isEmpty boolean value to represent that object created should be empty or not
122 * @return a property map suitable for constructing an object
124 public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
125 final Map<String, Object> map = new TreeMap<>();
126 map.put("https", REST_SERVER_HTTPS);
129 map.put("host", REST_SERVER_HOST);
130 map.put("port", REST_SERVER_PORT);
131 map.put("userName", REST_SERVER_USER);
132 map.put("password", REST_SERVER_PASS);
139 * Returns a property map for a PdpStatusParameters map for test cases.
141 * @param isEmpty boolean value to represent that object created should be empty or not
142 * @return a property map suitable for constructing an object
144 public Map<String, Object> getPdpStatusParametersMap(final boolean isEmpty) {
145 final Map<String, Object> map = new TreeMap<>();
147 map.put("timeIntervalMs", TIME_INTERVAL);
148 map.put("pdpName", PDP_NAME);
149 map.put("version", VERSION);
150 map.put("pdpType", PDP_TYPE);
151 map.put("pdpGroup", PDP_GROUP);
152 map.put("description", DESCRIPTION);
153 map.put("supportedPolicyTypes", SUPPORTED_POLICY_TYPES);
160 * Returns a property map for a TopicParameters map for test cases.
162 * @param isEmpty boolean value to represent that object created should be empty or not
163 * @return a property map suitable for constructing an object
165 public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
166 final Map<String, Object> map = new TreeMap<>();
168 map.put("topicSources", TOPIC_PARAMS);
169 map.put("topicSinks", TOPIC_PARAMS);