9353cde8136670cd7e9ee70bb4436642432fccb0
[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.controlloop.participant.intermediary.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.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
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 = "ControlLoopParticipantGroup";
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 ParticipantIntermediaryParameters.
47      *
48      * @return ParticipantIntermediaryParameters
49      */
50     public ParticipantIntermediaryParameters getParticipantIntermediaryParameters() {
51         try {
52             return CODER.convert(getIntermediaryParametersMap(PARTICIPANT_GROUP_NAME),
53                     ParticipantIntermediaryParameters.class);
54         } catch (final CoderException e) {
55             throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e);
56         }
57     }
58
59     /**
60      * Returns a property map for a intermediaryParameters map for test cases.
61      *
62      * @param name name of the parameters
63      * @return a property map suitable for constructing an object
64      */
65     public Map<String, Object> getIntermediaryParametersMap(final String name) {
66         final Map<String, Object> map = new TreeMap<>();
67         map.put("name", name);
68         map.put("participantId", getParticipantId());
69         map.put("description", DESCRIPTION);
70         map.put("participantType", getParticipantId());
71         map.put("reportingTimeIntervalMs", TIME_INTERVAL);
72         map.put("clampControlLoopTopics", getTopicParametersMap(false));
73
74         return map;
75     }
76
77     /**
78      * Returns a property map for a TopicParameters map for test cases.
79      *
80      * @param isEmpty boolean value to represent that object created should be empty or not
81      * @return a property map suitable for constructing an object
82      */
83     public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
84         final Map<String, Object> map = new TreeMap<>();
85         if (!isEmpty) {
86             map.put("topicSources", TOPIC_PARAMS);
87             map.put("topicSinks", TOPIC_PARAMS);
88         }
89         return map;
90     }
91
92     /**
93      * Returns topic parameters for test cases.
94      *
95      * @return topic parameters
96      */
97     public static TopicParameters getTopicParams() {
98         final TopicParameters topicParams = new TopicParameters();
99         topicParams.setTopic("POLICY-CLRUNTIME-PARTICIPANT");
100         topicParams.setTopicCommInfrastructure("dmaap");
101         topicParams.setServers(Arrays.asList("localhost"));
102         return topicParams;
103     }
104
105     /**
106      * Returns participantId for test cases.
107      *
108      * @return participant Id
109      */
110     public static ToscaConceptIdentifier getParticipantId() {
111         return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.1");
112     }
113 }