fbedbe633c92e62a7dce708ce1ee32e2ab039a7e
[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.simulator.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 DESCRIPTION = "Participant description";
37     public static final long TIME_INTERVAL = 2000;
38     public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
39
40     public static final Coder CODER = new StandardCoder();
41
42     /**
43      * Get ParticipantSimulatorParameters.
44      *
45      * @return ParticipantSimulatorParameters
46      */
47     public ParticipantSimulatorParameters getParticipantSimulatorParameters() {
48         try {
49             return CODER.convert(getParticipantParameterGroupMap(),
50                     ParticipantSimulatorParameters.class);
51         } catch (final CoderException e) {
52             throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e);
53         }
54     }
55
56     /**
57      * Returns a property map for a ApexStarterParameterGroup map for test cases.
58      *
59      * @return a property map suitable for constructing an object
60      */
61     public Map<String, Object> getParticipantParameterGroupMap() {
62         final Map<String, Object> map = new TreeMap<>();
63
64         map.put("intermediaryParameters", getIntermediaryParametersMap(false));
65         return map;
66     }
67
68     /**
69      * Returns a property map for a intermediaryParameters map for test cases.
70      *
71      * @param isEmpty boolean value to represent that object created should be empty or not
72      * @return a property map suitable for constructing an object
73      */
74     public Map<String, Object> getIntermediaryParametersMap(final boolean isEmpty) {
75         final Map<String, Object> map = new TreeMap<>();
76         if (!isEmpty) {
77             map.put("name", "Participant parameters");
78             map.put("reportingTimeIntervalMs", TIME_INTERVAL);
79             map.put("description", DESCRIPTION);
80             map.put("participantId", getParticipantId());
81             map.put("participantType", getParticipantId());
82             map.put("clampAutomationCompositionTopics", getTopicParametersMap(false));
83         }
84
85         return map;
86     }
87
88     /**
89      * Returns a property map for a TopicParameters map for test cases.
90      *
91      * @param isEmpty boolean value to represent that object created should be empty or not
92      * @return a property map suitable for constructing an object
93      */
94     public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
95         final Map<String, Object> map = new TreeMap<>();
96         if (!isEmpty) {
97             map.put("topicSources", TOPIC_PARAMS);
98             map.put("topicSinks", TOPIC_PARAMS);
99         }
100         return map;
101     }
102
103     /**
104      * Returns topic parameters for test cases.
105      *
106      * @return topic parameters
107      */
108     public static TopicParameters getTopicParams() {
109         final TopicParameters topicParams = new TopicParameters();
110         topicParams.setTopic("POLICY-ACRUNTIME-PARTICIPANT");
111         topicParams.setTopicCommInfrastructure("dmaap");
112         topicParams.setServers(List.of("localhost"));
113         return topicParams;
114     }
115
116     /**
117      * Returns participantId for test cases.
118      *
119      * @return participant Id
120      */
121     public static ToscaConceptIdentifier getParticipantId() {
122         return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.0");
123     }
124 }