ac6451260d1e01c403c18d7451922ddc6feaf526
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021-2022 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.List;
24 import java.util.Map;
25 import java.util.TreeMap;
26 import org.onap.policy.common.endpoints.parameters.TopicParameters;
27 import org.onap.policy.common.utils.coder.Coder;
28 import org.onap.policy.common.utils.coder.CoderException;
29 import org.onap.policy.common.utils.coder.StandardCoder;
30 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
31
32 /**
33  * Class to hold/create all parameters for test cases.
34  */
35 public class CommonTestData {
36     public static final String PARTICIPANT_GROUP_NAME = "AutomationCompositionParticipantGroup";
37     public static final String DESCRIPTION = "Participant description";
38     public static final long TIME_INTERVAL = 2000;
39     public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
40
41     public static final Coder CODER = new StandardCoder();
42
43     /**
44      * Get ParticipantPolicyParameters.
45      *
46      * @return ParticipantPolicyParameters
47      */
48     public ParticipantPolicyParameters getParticipantPolicyParameters() {
49         try {
50             return CODER.convert(getParticipantPolicyParametersMap(PARTICIPANT_GROUP_NAME),
51                     ParticipantPolicyParameters.class);
52         } catch (final CoderException e) {
53             throw new RuntimeException("cannot create ParticipantPolicyParameters from map", e);
54         }
55     }
56
57     /**
58      * Returns a property map for a ParticipantPolicyParameters map for test cases.
59      *
60      * @param name name of the parameters
61      *
62      * @return a property map suitable for constructing an object
63      */
64     public Map<String, Object> getParticipantPolicyParametersMap(final String name) {
65         final Map<String, Object> map = new TreeMap<>();
66
67         map.put("name", name);
68         map.put("intermediaryParameters", getIntermediaryParametersMap(false));
69         map.put("policyApiParameters", getPolicyApiParametersMap());
70         map.put("policyPapParameters", getPolicyPapParametersMap());
71         map.put("pdpGroup", "defaultGroup");
72         map.put("pdpType", "apex");
73         return map;
74     }
75
76     /**
77      * Returns a property map for a policyPapParameters map for test cases.
78      *
79      * @return a property map suitable for constructing an object
80      */
81     public Map<String, Object> getPolicyPapParametersMap() {
82         final Map<String, Object> map = new TreeMap<>();
83         map.put("clientName", "pap");
84         map.put("hostname", "localhost");
85         map.put("port", 6968);
86         map.put("userName", "policyadmin");
87         map.put("password", "zb!XztG34");
88         map.put("https", false);
89         map.put("allowSelfSignedCerts", true);
90         return map;
91     }
92
93     /**
94      * Returns a property map for a policyApiParameters map for test cases.
95      *
96      * @return a property map suitable for constructing an object
97      */
98     public Map<String, Object> getPolicyApiParametersMap() {
99         final Map<String, Object> map = new TreeMap<>();
100         map.put("clientName", "api");
101         map.put("hostname", "localhost");
102         map.put("port", 6969);
103         map.put("userName", "policyadmin");
104         map.put("password", "zb!XztG34");
105         map.put("https", false);
106         map.put("allowSelfSignedCerts", true);
107
108         return map;
109     }
110
111     /**
112      * Returns a property map for a intermediaryParameters map for test cases.
113      *
114      * @param isEmpty boolean value to represent that object created should be empty or not
115      * @return a property map suitable for constructing an object
116      */
117     public Map<String, Object> getIntermediaryParametersMap(final boolean isEmpty) {
118         final Map<String, Object> map = new TreeMap<>();
119         if (!isEmpty) {
120             map.put("name", "Participant parameters");
121             map.put("reportingTimeIntervalMs", TIME_INTERVAL);
122             map.put("description", DESCRIPTION);
123             map.put("participantId", getParticipantId());
124             map.put("participantType", getParticipantId());
125             map.put("clampAutomationCompositionTopics", getTopicParametersMap(false));
126         }
127
128         return map;
129     }
130
131     /**
132      * Returns a property map for a TopicParameters map for test cases.
133      *
134      * @param isEmpty boolean value to represent that object created should be empty or not
135      * @return a property map suitable for constructing an object
136      */
137     public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
138         final Map<String, Object> map = new TreeMap<>();
139         if (!isEmpty) {
140             map.put("topicSources", TOPIC_PARAMS);
141             map.put("topicSinks", TOPIC_PARAMS);
142         }
143         return map;
144     }
145
146     /**
147      * Returns topic parameters for test cases.
148      *
149      * @return topic parameters
150      */
151     public static TopicParameters getTopicParams() {
152         final TopicParameters topicParams = new TopicParameters();
153         topicParams.setTopic("POLICY-ACRUNTIME-PARTICIPANT");
154         topicParams.setTopicCommInfrastructure("dmaap");
155         topicParams.setServers(List.of("localhost"));
156         return topicParams;
157     }
158
159     /**
160      * Returns participantId for test cases.
161      *
162      * @return participant Id
163      */
164     public static ToscaConceptIdentifier getParticipantId() {
165         return new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
166     }
167
168 }