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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.participant.kubernetes.parameters;
23 import java.util.Arrays;
24 import java.util.List;
26 import java.util.TreeMap;
27 import org.onap.policy.common.endpoints.parameters.TopicParameters;
28 import org.onap.policy.common.utils.coder.Coder;
29 import org.onap.policy.common.utils.coder.CoderException;
30 import org.onap.policy.common.utils.coder.StandardCoder;
31 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
33 public class CommonTestData {
35 public static final String PARTICIPANT_GROUP_NAME = "ControlLoopParticipantGroup";
36 public static final String DESCRIPTION = "Participant description";
37 public static final long TIME_INTERVAL = 2000;
38 public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
39 public static final Coder CODER = new StandardCoder();
43 * Get ParticipantK8sParameters.
45 * @return ParticipantK8sParameters
47 public ParticipantK8sParameters getParticipantK8sParameters() {
49 return CODER.convert(getParticipantK8sParametersMap(PARTICIPANT_GROUP_NAME),
50 ParticipantK8sParameters.class);
51 } catch (final CoderException e) {
52 throw new RuntimeException("cannot create ParticipantK8sParameters from map", e);
57 * Returns a property map for a ParticipantK8sParameters map for test cases.
59 * @param name name of the parameters
61 * @return a property map suitable for constructing an object
63 public Map<String, Object> getParticipantK8sParametersMap(final String name) {
64 final Map<String, Object> map = new TreeMap<>();
66 map.put("name", name);
67 map.put("intermediaryParameters", getIntermediaryParametersMap(false));
68 map.put("localChartDirectory", getLocalChartDir());
69 map.put("infoFileName", getInfoFileName());
75 * Returns string value of local chart Directory.
76 * @return a string value
78 public String getLocalChartDir() {
79 return "/var/helm-manager/local-charts";
83 * Returns string value of Info file name.
84 * @return string value
86 public String getInfoFileName() {
87 return "CHART-INFO.json";
93 * Returns a property map for a intermediaryParameters map for test cases.
95 * @param isEmpty boolean value to represent that object created should be empty or not
96 * @return a property map suitable for constructing an object
98 public Map<String, Object> getIntermediaryParametersMap(final boolean isEmpty) {
99 final Map<String, Object> map = new TreeMap<>();
101 map.put("name", "Participant parameters");
102 map.put("reportingTimeIntervalMs", TIME_INTERVAL);
103 map.put("description", DESCRIPTION);
104 map.put("participantId", getParticipantId());
105 map.put("participantType", getParticipantId());
106 map.put("clampControlLoopTopics", getTopicParametersMap(false));
113 * Returns participantId for test cases.
115 * @return participant Id
117 public static ToscaConceptIdentifier getParticipantId() {
118 final ToscaConceptIdentifier participantId = new ToscaConceptIdentifier();
119 participantId.setName("K8sParticipant0");
120 participantId.setVersion("1.0.0");
121 return participantId;
126 * Returns a property map for a TopicParameters map for test cases.
128 * @param isEmpty boolean value to represent that object created should be empty or not
129 * @return a property map suitable for constructing an object
131 public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
132 final Map<String, Object> map = new TreeMap<>();
134 map.put("topicSources", TOPIC_PARAMS);
135 map.put("topicSinks", TOPIC_PARAMS);
141 * Returns topic parameters for test cases.
143 * @return topic parameters
145 public static TopicParameters getTopicParams() {
146 final TopicParameters topicParams = new TopicParameters();
147 topicParams.setTopic("POLICY-CLRUNTIME-PARTICIPANT");
148 topicParams.setTopicCommInfrastructure("dmaap");
149 topicParams.setServers(Arrays.asList("localhost"));