XACML junit spews dmaap errors
[policy/xacml-pdp.git] / main / src / test / java / org / onap / policy / pdpx / main / parameters / CommonTestData.java
1 /*-
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
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.pdpx.main.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  */
38 public class CommonTestData {
39
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());
48
49     public static final Coder coder = new StandardCoder();
50
51     /**
52      * Returns topic parameters for test cases.
53      *
54      * @return topic parameters
55      */
56     public static TopicParameters getTopicParams() {
57         final TopicParameters topicParams = new TopicParameters();
58         topicParams.setTopic("POLICY-PDP-PAP");
59         topicParams.setTopicCommInfrastructure("noop");
60         topicParams.setServers(Arrays.asList("message-router"));
61         return topicParams;
62     }
63
64     /**
65      * Returns a property map for a RestServerParameters map for test cases.
66      *
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
69      */
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);
74
75         if (!isEmpty) {
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);
80         }
81
82         return map;
83     }
84
85     /**
86      * Returns a property map for a RestServerParameters map for test cases.
87      *
88      * @param port the port for RestServer
89      * @return a property map suitable for constructing an object
90      */
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);
99
100         return map;
101     }
102
103     /**
104      * Converts the contents of a map to a parameter class.
105      *
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
109      */
110     public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
111         try {
112             return coder.decode(coder.encode(source), clazz);
113
114         } catch (final CoderException e) {
115             throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
116         }
117     }
118
119     /**
120      * Returns a property map for a TopicParameters map for test cases.
121      *
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
124      */
125     public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
126         final Map<String, Object> map = new TreeMap<>();
127         if (!isEmpty) {
128             map.put("topicSources", TOPIC_PARAMS);
129             map.put("topicSinks", TOPIC_PARAMS);
130         }
131         return map;
132     }
133 }