555383b424204ffc7221eb43cff89b5641515337
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021-2024 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.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.TreeMap;
27 import java.util.UUID;
28 import org.onap.policy.clamp.acm.participant.intermediary.parameters.Topics;
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;
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> SINK_TOPIC_PARAMS = List.of(getSinkTopicParams());
42     public static final List<TopicParameters> SOURCE_TOPIC_PARAMS = List.of(getSinkTopicParams(), getSyncTopicParams());
43
44     public static final Coder CODER = new StandardCoder();
45
46     /**
47      * Get ParticipantPolicyParameters.
48      *
49      * @return ParticipantPolicyParameters
50      */
51     public ParticipantPolicyParameters getParticipantPolicyParameters() {
52         try {
53             return CODER.convert(getParticipantPolicyParametersMap(PARTICIPANT_GROUP_NAME),
54                     ParticipantPolicyParameters.class);
55         } catch (final CoderException e) {
56             throw new RuntimeException("cannot create ParticipantPolicyParameters from map", e);
57         }
58     }
59
60     /**
61      * Returns a property map for a ParticipantPolicyParameters map for test cases.
62      *
63      * @param name name of the parameters
64      *
65      * @return a property map suitable for constructing an object
66      */
67     public Map<String, Object> getParticipantPolicyParametersMap(final String name) {
68         final Map<String, Object> map = new TreeMap<>();
69
70         map.put("name", name);
71         map.put("intermediaryParameters", getIntermediaryParametersMap(false));
72         map.put("policyApiParameters", getPolicyApiParametersMap());
73         map.put("policyPapParameters", getPolicyPapParametersMap());
74         map.put("pdpGroup", "defaultGroup");
75         map.put("pdpType", "apex");
76         return map;
77     }
78
79     /**
80      * Returns a property map for a policyPapParameters map for test cases.
81      *
82      * @return a property map suitable for constructing an object
83      */
84     public Map<String, Object> getPolicyPapParametersMap() {
85         final Map<String, Object> map = new TreeMap<>();
86         map.put("clientName", "pap");
87         map.put("hostname", "localhost");
88         map.put("port", 6968);
89         map.put("userName", "policyadmin");
90         map.put("password", "zb!XztG34");
91         map.put("https", false);
92         map.put("allowSelfSignedCerts", true);
93         return map;
94     }
95
96     /**
97      * Returns a property map for a policyApiParameters map for test cases.
98      *
99      * @return a property map suitable for constructing an object
100      */
101     public Map<String, Object> getPolicyApiParametersMap() {
102         final Map<String, Object> map = new TreeMap<>();
103         map.put("clientName", "api");
104         map.put("hostname", "localhost");
105         map.put("port", 6969);
106         map.put("userName", "policyadmin");
107         map.put("password", "zb!XztG34");
108         map.put("https", false);
109         map.put("allowSelfSignedCerts", true);
110
111         return map;
112     }
113
114     /**
115      * Returns a property map for a intermediaryParameters map for test cases.
116      *
117      * @param isEmpty boolean value to represent that object created should be empty or not
118      * @return a property map suitable for constructing an object
119      */
120     public Map<String, Object> getIntermediaryParametersMap(final boolean isEmpty) {
121         final Map<String, Object> map = new TreeMap<>();
122         if (!isEmpty) {
123             map.put("name", "Participant parameters");
124             map.put("reportingTimeIntervalMs", TIME_INTERVAL);
125             map.put("description", DESCRIPTION);
126             map.put("participantId", getParticipantId());
127             map.put("clampAutomationCompositionTopics", getTopicParametersMap(false));
128             map.put("participantSupportedElementTypes", new ArrayList<>());
129             map.put("topics", new Topics("policy-acruntime-participant", "acm-ppnt-sync"));
130         }
131
132         return map;
133     }
134
135     /**
136      * Returns a property map for a TopicParameters map for test cases.
137      *
138      * @param isEmpty boolean value to represent that object created should be empty or not
139      * @return a property map suitable for constructing an object
140      */
141     public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
142         final Map<String, Object> map = new TreeMap<>();
143         if (!isEmpty) {
144             map.put("topicSources", SOURCE_TOPIC_PARAMS);
145             map.put("topicSinks", SINK_TOPIC_PARAMS);
146         }
147         return map;
148     }
149
150     /**
151      * Returns topic parameters for test cases.
152      *
153      * @return topic parameters
154      */
155     public static TopicParameters getSinkTopicParams() {
156         final TopicParameters topicParams = new TopicParameters();
157         topicParams.setTopic("policy-acruntime-participant");
158         topicParams.setTopicCommInfrastructure("NOOP");
159         topicParams.setServers(List.of("localhost"));
160         return topicParams;
161     }
162
163     /**
164      * Returns sync topic parameters for test cases.
165      *
166      * @return topic parameters
167      */
168     public static TopicParameters getSyncTopicParams() {
169         final TopicParameters topicParams = new TopicParameters();
170         topicParams.setTopic("acm-ppnt-sync");
171         topicParams.setTopicCommInfrastructure("NOOP");
172         topicParams.setServers(List.of("localhost"));
173         return topicParams;
174     }
175
176     /**
177      * Returns participantId for test cases.
178      *
179      * @return participant Id
180      */
181     public static UUID getParticipantId() {
182         return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c03");
183     }
184 }