925214ec1232368410f522781e8427096a56660b
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021-2023 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.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 = List.of(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", getParticipantType());
127             map.put("clampAutomationCompositionTopics", getTopicParametersMap(false));
128             map.put("participantSupportedElementTypes", new ArrayList<>());
129         }
130
131         return map;
132     }
133
134     /**
135      * Returns a property map for a TopicParameters map for test cases.
136      *
137      * @param isEmpty boolean value to represent that object created should be empty or not
138      * @return a property map suitable for constructing an object
139      */
140     public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
141         final Map<String, Object> map = new TreeMap<>();
142         if (!isEmpty) {
143             map.put("topicSources", TOPIC_PARAMS);
144             map.put("topicSinks", TOPIC_PARAMS);
145         }
146         return map;
147     }
148
149     /**
150      * Returns topic parameters for test cases.
151      *
152      * @return topic parameters
153      */
154     public static TopicParameters getTopicParams() {
155         final TopicParameters topicParams = new TopicParameters();
156         topicParams.setTopic("POLICY-ACRUNTIME-PARTICIPANT");
157         topicParams.setTopicCommInfrastructure("dmaap");
158         topicParams.setServers(List.of("localhost"));
159         return topicParams;
160     }
161
162     /**
163      * Returns participantType for test cases.
164      *
165      * @return participant Type
166      */
167     public static ToscaConceptIdentifier getParticipantType() {
168         return new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
169     }
170
171
172     /**
173      * Returns participantId for test cases.
174      *
175      * @return participant Id
176      */
177     public static UUID getParticipantId() {
178         return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c03");
179     }
180 }