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.intermediary.main.parameters;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.List;
27 import java.util.TreeMap;
28 import org.mockito.Mockito;
29 import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantMessagePublisher;
30 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ControlLoopHandler;
31 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.DummyParticipantParameters;
32 import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
33 import org.onap.policy.common.endpoints.event.comm.TopicSink;
34 import org.onap.policy.common.endpoints.parameters.TopicParameters;
35 import org.onap.policy.common.utils.coder.Coder;
36 import org.onap.policy.common.utils.coder.CoderException;
37 import org.onap.policy.common.utils.coder.StandardCoder;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
41 * Class to hold/create all parameters for test cases.
43 public class CommonTestData {
44 public static final String PARTICIPANT_GROUP_NAME = "ControlLoopParticipantGroup";
45 public static final String DESCRIPTION = "Participant description";
46 public static final long TIME_INTERVAL = 2000;
47 public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
49 public static final Coder CODER = new StandardCoder();
50 private static final Object lockit = new Object();
53 * Get ParticipantIntermediaryParameters.
55 * @return ParticipantIntermediaryParameters
57 public ParticipantIntermediaryParameters getParticipantIntermediaryParameters() {
59 return CODER.convert(getIntermediaryParametersMap(PARTICIPANT_GROUP_NAME),
60 ParticipantIntermediaryParameters.class);
61 } catch (final CoderException e) {
62 throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e);
67 * Get ParticipantParameters.
69 * @return ParticipantParameters
71 public static DummyParticipantParameters getParticipantParameters() {
73 return CODER.convert(getParametersMap(PARTICIPANT_GROUP_NAME),
74 DummyParticipantParameters.class);
75 } catch (final CoderException e) {
76 throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e);
81 * Returns a property map for a Parameters map for test cases.
83 * @param name name of the parameters
84 * @return a property map suitable for constructing an object
86 public static Map<String, Object> getParametersMap(final String name) {
87 final Map<String, Object> map = new TreeMap<>();
88 map.put("intermediaryParameters", getIntermediaryParametersMap(name));
93 * Returns a property map for a intermediaryParameters map for test cases.
95 * @param name name of the parameters
96 * @return a property map suitable for constructing an object
98 public static Map<String, Object> getIntermediaryParametersMap(final String name) {
99 final Map<String, Object> map = new TreeMap<>();
100 map.put("name", name);
101 map.put("participantId", getParticipantId());
102 map.put("description", DESCRIPTION);
103 map.put("participantType", getParticipantId());
104 map.put("reportingTimeIntervalMs", TIME_INTERVAL);
105 map.put("clampControlLoopTopics", getTopicParametersMap(false));
111 * Returns a property map for a TopicParameters map for test cases.
113 * @param isEmpty boolean value to represent that object created should be empty or not
114 * @return a property map suitable for constructing an object
116 public static Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
117 final Map<String, Object> map = new TreeMap<>();
119 map.put("topicSources", TOPIC_PARAMS);
120 map.put("topicSinks", TOPIC_PARAMS);
126 * Returns topic parameters for test cases.
128 * @return topic parameters
130 public static TopicParameters getTopicParams() {
131 final TopicParameters topicParams = new TopicParameters();
132 topicParams.setTopic("POLICY-CLRUNTIME-PARTICIPANT");
133 topicParams.setTopicCommInfrastructure("dmaap");
134 topicParams.setServers(Arrays.asList("localhost"));
139 * Returns participantId for test cases.
141 * @return participant Id
143 public static ToscaConceptIdentifier getParticipantId() {
144 return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.1");
148 * Returns a participantMessagePublisher for MessageSender.
150 * @return participant Message Publisher
152 private ParticipantMessagePublisher getParticipantMessagePublisher() {
153 synchronized (lockit) {
154 ParticipantMessagePublisher participantMessagePublisher =
155 new ParticipantMessagePublisher();
156 participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
157 return participantMessagePublisher;
162 * Returns a mocked ControlLoopHandler for test cases.
164 * @return ControlLoopHandler
166 public ControlLoopHandler getMockControlLoopHandler() {
167 return new ControlLoopHandler(
168 getParticipantParameters(),
169 getParticipantMessagePublisher());