2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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.List;
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;
35 * Class to hold/create all parameters for test cases.
38 public class CommonTestData {
40 private static final String REST_SERVER_PASSWORD = "zb!XztG34";
41 private static final String REST_SERVER_USER = "healthcheck";
42 private static final int REST_SERVER_PORT = 6969;
43 private static final String REST_SERVER_HOST = "0.0.0.0";
44 private static final boolean REST_SERVER_HTTPS = false;
45 private static final boolean REST_SERVER_AAF = false;
46 public static final String PDPX_GROUP_NAME = "XacmlPdpGroup";
47 public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
49 public static final Coder coder = new StandardCoder();
52 * Returns topic parameters for test cases.
54 * @return topic parameters
56 public static TopicParameters getTopicParams() {
57 final TopicParameters topicParams = new TopicParameters();
58 topicParams.setTopic("POLICY-PDP-PAP");
59 topicParams.setTopicCommInfrastructure("dmaap");
60 topicParams.setServers(Arrays.asList("message-router"));
65 * Returns a property map for a RestServerParameters map for test cases.
67 * @param isEmpty boolean value to represent that object created should be empty or not
68 * @return a property map suitable for constructing an object
70 public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
71 final Map<String, Object> map = new TreeMap<>();
72 map.put("https", REST_SERVER_HTTPS);
73 map.put("aaf", REST_SERVER_AAF);
76 map.put("host", REST_SERVER_HOST);
77 map.put("port", REST_SERVER_PORT);
78 map.put("userName", REST_SERVER_USER);
79 map.put("password", REST_SERVER_PASSWORD);
86 * Returns a property map for a RestServerParameters map for test cases.
88 * @param port the port for RestServer
89 * @return a property map suitable for constructing an object
91 public Map<String, Object> getRestServerParametersMap(final int port) {
92 final Map<String, Object> map = new TreeMap<>();
93 map.put("https", REST_SERVER_HTTPS);
94 map.put("aaf", REST_SERVER_AAF);
95 map.put("host", REST_SERVER_HOST);
96 map.put("port", port);
97 map.put("userName", REST_SERVER_USER);
98 map.put("password", REST_SERVER_PASSWORD);
104 * Converts the contents of a map to a parameter class.
106 * @param source property map
107 * @param clazz class of object to be created from the map
108 * @return a new object represented by the map
110 public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
112 return coder.decode(coder.encode(source), clazz);
114 } catch (final CoderException e) {
115 throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
120 * Returns a property map for a TopicParameters map for test cases.
122 * @param isEmpty boolean value to represent that object created should be empty or not
123 * @return a property map suitable for constructing an object
125 public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
126 final Map<String, Object> map = new TreeMap<>();
128 map.put("topicSources", TOPIC_PARAMS);
129 map.put("topicSinks", TOPIC_PARAMS);