b5cd9d4425ac1f628bb9be5d2d1074ed0f59d867
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.acm.participant.policy.main.parameters;
22
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.TreeMap;
27 import org.onap.policy.clamp.acm.participant.policy.main.parameters.ParticipantPolicyParameters;
28 import org.onap.policy.common.endpoints.parameters.TopicParameters;
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;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
33
34 /**
35  * Class to hold/create all parameters for test cases.
36  */
37 public class CommonTestData {
38     public static final String PARTICIPANT_GROUP_NAME = "AutomationCompositionParticipantGroup";
39     public static final String DESCRIPTION = "Participant description";
40     public static final long TIME_INTERVAL = 2000;
41     public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
42
43     public static final Coder CODER = new StandardCoder();
44
45     /**
46      * Get ParticipantPolicyParameters.
47      *
48      * @return ParticipantPolicyParameters
49      */
50     public ParticipantPolicyParameters getParticipantPolicyParameters() {
51         try {
52             return CODER.convert(getParticipantPolicyParametersMap(PARTICIPANT_GROUP_NAME),
53                     ParticipantPolicyParameters.class);
54         } catch (final CoderException e) {
55             throw new RuntimeException("cannot create ParticipantPolicyParameters from map", e);
56         }
57     }
58
59     /**
60      * Returns a property map for a ParticipantPolicyParameters map for test cases.
61      *
62      * @param name name of the parameters
63      *
64      * @return a property map suitable for constructing an object
65      */
66     public Map<String, Object> getParticipantPolicyParametersMap(final String name) {
67         final Map<String, Object> map = new TreeMap<>();
68
69         map.put("name", name);
70         map.put("intermediaryParameters", getIntermediaryParametersMap(false));
71         map.put("policyApiParameters", getPolicyApiParametersMap());
72         map.put("policyPapParameters", getPolicyPapParametersMap());
73         map.put("pdpGroup", "defaultGroup");
74         map.put("pdpType", "apex");
75         return map;
76     }
77
78     /**
79      * Returns a property map for a policyPapParameters map for test cases.
80      *
81      * @return a property map suitable for constructing an object
82      */
83     public Map<String, Object> getPolicyPapParametersMap() {
84         final Map<String, Object> map = new TreeMap<>();
85         map.put("clientName", "pap");
86         map.put("hostname", "localhost");
87         map.put("port", 6968);
88         map.put("userName", "policyadmin");
89         map.put("password", "zb!XztG34");
90         map.put("https", false);
91         map.put("allowSelfSignedCerts", true);
92         return map;
93     }
94
95     /**
96      * Returns a property map for a policyApiParameters map for test cases.
97      *
98      * @return a property map suitable for constructing an object
99      */
100     public Map<String, Object> getPolicyApiParametersMap() {
101         final Map<String, Object> map = new TreeMap<>();
102         map.put("clientName", "api");
103         map.put("hostname", "localhost");
104         map.put("port", 6969);
105         map.put("userName", "policyadmin");
106         map.put("password", "zb!XztG34");
107         map.put("https", false);
108         map.put("allowSelfSignedCerts", true);
109
110         return map;
111     }
112
113     /**
114      * Returns a property map for a intermediaryParameters map for test cases.
115      *
116      * @param isEmpty boolean value to represent that object created should be empty or not
117      * @return a property map suitable for constructing an object
118      */
119     public Map<String, Object> getIntermediaryParametersMap(final boolean isEmpty) {
120         final Map<String, Object> map = new TreeMap<>();
121         if (!isEmpty) {
122             map.put("name", "Participant parameters");
123             map.put("reportingTimeIntervalMs", TIME_INTERVAL);
124             map.put("description", DESCRIPTION);
125             map.put("participantId", getParticipantId());
126             map.put("participantType", getParticipantId());
127             map.put("clampAutomationCompositionTopics", getTopicParametersMap(false));
128         }
129
130         return map;
131     }
132
133     /**
134      * Returns a property map for a TopicParameters map for test cases.
135      *
136      * @param isEmpty boolean value to represent that object created should be empty or not
137      * @return a property map suitable for constructing an object
138      */
139     public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
140         final Map<String, Object> map = new TreeMap<>();
141         if (!isEmpty) {
142             map.put("topicSources", TOPIC_PARAMS);
143             map.put("topicSinks", TOPIC_PARAMS);
144         }
145         return map;
146     }
147
148     /**
149      * Returns topic parameters for test cases.
150      *
151      * @return topic parameters
152      */
153     public static TopicParameters getTopicParams() {
154         final TopicParameters topicParams = new TopicParameters();
155         topicParams.setTopic("POLICY-ACRUNTIME-PARTICIPANT");
156         topicParams.setTopicCommInfrastructure("dmaap");
157         topicParams.setServers(Arrays.asList("localhost"));
158         return topicParams;
159     }
160
161     /**
162      * Returns participantId for test cases.
163      *
164      * @return participant Id
165      */
166     public static ToscaConceptIdentifier getParticipantId() {
167         final ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
168         return participantId;
169     }
170
171     /**
172      * Nulls out a field within a JSON string.
173      *
174      * @param json JSON string
175      * @param field field to be nulled out
176      * @return a new JSON string with the field nulled out
177      */
178     public String nullifyField(String json, String field) {
179         return json.replace(field + "\"", field + "\":null, \"" + field + "Xxx\"");
180     }
181 }