2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
4 * Modifications Copyright (C) 2019 Nordix Foundation.
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.pdpx.main.parameters;
24 import java.util.Arrays;
25 import java.util.Collections;
26 import java.util.List;
28 import java.util.TreeMap;
29 import org.onap.policy.common.endpoints.parameters.TopicParameters;
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;
35 * Class to hold/create all parameters for test cases.
38 public class CommonTestData {
40 private static final String PASS_KEY = "password";
41 private static final String USER_KEY = "userName";
42 private static final String PORT_KEY = "port";
43 private static final String SERVER_HOST_KEY = "host";
44 private static final String API_HOST_KEY = "hostname";
45 private static final String AAF_KEY = "aaf";
46 private static final String HTTPS_KEY = "useHttps";
48 private static final String REST_SERVER_PASS = "zb!XztG34";
49 private static final String REST_SERVER_USER = "healthcheck";
50 private static final int REST_SERVER_PORT = 6969;
51 private static final String REST_SERVER_HOST = "0.0.0.0";
52 private static final boolean REST_SERVER_HTTPS = false;
53 private static final boolean REST_SERVER_AAF = false;
55 private static final String POLICY_API_PASS = "zb!XztG34";
56 private static final String POLICY_API_USER = "healthcheck";
57 private static final int POLICY_API_PORT = 6970;
58 private static final String POLICY_API_HOST = "0.0.0.0";
59 private static final boolean POLICY_API_HTTPS = false;
60 private static final boolean POLICY_API_AAF = false;
62 public static final String PDPX_PARAMETER_GROUP_NAME = "XacmlPdpParameters";
63 public static final String PDPX_GROUP = "XacmlPdpGroup";
64 public static final String PDPX_TYPE = "xacml";
65 public static final List<TopicParameters> TOPIC_PARAMS =
66 Collections.unmodifiableList(Arrays.asList(getTopicParams()));
68 public static final Coder coder = new StandardCoder();
71 * Returns topic parameters for test cases.
73 * @return topic parameters
75 public static TopicParameters getTopicParams() {
76 final TopicParameters topicParams = new TopicParameters();
77 topicParams.setTopic("POLICY-PDP-PAP");
78 topicParams.setTopicCommInfrastructure("noop");
79 topicParams.setServers(Arrays.asList("message-router"));
84 * Returns a property map for a RestServerParameters map for test cases.
86 * @param isEmpty boolean value to represent that object created should be empty or not
87 * @return a property map suitable for constructing an object
89 public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
90 final Map<String, Object> map = new TreeMap<>();
91 map.put(HTTPS_KEY, REST_SERVER_HTTPS);
92 map.put(AAF_KEY, REST_SERVER_AAF);
95 map.put(SERVER_HOST_KEY, REST_SERVER_HOST);
96 map.put(PORT_KEY, REST_SERVER_PORT);
97 map.put(USER_KEY, REST_SERVER_USER);
98 map.put(PASS_KEY, REST_SERVER_PASS);
105 * Returns a property map for a RestServerParameters map for test cases.
107 * @param port the port for RestServer
108 * @return a property map suitable for constructing an object
110 public Map<String, Object> getRestServerParametersMap(final int port) {
111 final Map<String, Object> map = new TreeMap<>();
112 map.put(HTTPS_KEY, REST_SERVER_HTTPS);
113 map.put(AAF_KEY, REST_SERVER_AAF);
114 map.put(SERVER_HOST_KEY, REST_SERVER_HOST);
115 map.put(PORT_KEY, port);
116 map.put(USER_KEY, REST_SERVER_USER);
117 map.put(PASS_KEY, REST_SERVER_PASS);
123 * Converts the contents of a map to a parameter class.
125 * @param source property map
126 * @param clazz class of object to be created from the map
127 * @return a new object represented by the map
129 public <T> T toObject(final Map<String, Object> source, final Class<T> clazz) {
131 return coder.decode(coder.encode(source), clazz);
133 } catch (final CoderException e) {
134 throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
139 * Returns a property map for a RestServerParameters 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> getPolicyApiParametersMap(final boolean isEmpty) {
145 final Map<String, Object> map = new TreeMap<>();
146 map.put(HTTPS_KEY, POLICY_API_HTTPS);
147 map.put(AAF_KEY, POLICY_API_AAF);
150 map.put(API_HOST_KEY, POLICY_API_HOST);
151 map.put(PORT_KEY, POLICY_API_PORT);
152 map.put(USER_KEY, POLICY_API_USER);
153 map.put(PASS_KEY, POLICY_API_PASS);
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);
175 * Returns a property map for a XacmlApplicationParameters map for test cases.
177 * @param isEmpty boolean value to represent that object created should be empty or not
178 * @param tempPath Application Path string
179 * @return a property map suitable for constructing an object
181 public Map<String, Object> getXacmlapplicationParametersMap(boolean isEmpty, String tempPath) {
182 final Map<String, Object> map = new TreeMap<>();
184 map.put("applicationPath", tempPath);