f73f7597047635cbc074c19c9d5ca02fc56672c7
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2023-2024 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.sim.comm;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.TreeMap;
27 import java.util.UUID;
28 import org.onap.policy.clamp.acm.participant.intermediary.parameters.Topics;
29 import org.onap.policy.clamp.acm.participant.sim.model.SimConfig;
30 import org.onap.policy.clamp.acm.participant.sim.parameters.ParticipantSimParameters;
31 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
32 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
33 import org.onap.policy.common.endpoints.parameters.TopicParameters;
34 import org.onap.policy.common.utils.coder.Coder;
35 import org.onap.policy.common.utils.coder.CoderException;
36 import org.onap.policy.common.utils.coder.StandardCoder;
37
38 public class CommonTestData {
39     public static final Coder CODER = new StandardCoder();
40     public static final String DESCRIPTION = "Participant description";
41     public static final long TIME_INTERVAL = 2000;
42     public static final List<TopicParameters> SINK_TOPIC_PARAMS = List.of(getSinkTopicParams());
43     public static final List<TopicParameters> SOURCE_TOPIC_PARAMS = List.of(getSinkTopicParams(), getSyncTopicParams());
44
45     /**
46      * Get ParticipantSimParameters.
47      *
48      * @return ParticipantSimParameters
49      */
50     public static ParticipantSimParameters getParticipantSimParameters() {
51         try {
52             return CODER.convert(getParticipantSimParametersMap(), ParticipantSimParameters.class);
53         } catch (final CoderException e) {
54             throw new RuntimeException("cannot create ParticipantSimParameters from map", e);
55         }
56     }
57
58     /**
59      * Returns a property map for a ParticipantSimParameters map for test cases.
60      *
61      * @return a property map suitable for constructing an object
62      */
63     private static Map<String, Object> getParticipantSimParametersMap() {
64         final Map<String, Object> map = new TreeMap<>();
65
66         map.put("intermediaryParameters", getIntermediaryParametersMap());
67         return map;
68     }
69
70     /**
71      * Returns a property map for a intermediaryParameters map for test cases.
72      *
73      * @return a property map suitable for constructing an object
74      */
75     private static Map<String, Object> getIntermediaryParametersMap() {
76         final Map<String, Object> map = new TreeMap<>();
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("clampAutomationCompositionTopics", getTopicParametersMap());
82         map.put("participantSupportedElementTypes", new ArrayList<>());
83         map.put("topics", new Topics("policy-acruntime-participant", "acm-ppnt-sync"));
84
85         return map;
86     }
87
88     /**
89      * Returns a property map for a TopicParameters map for test cases.
90      *
91      * @return a property map suitable for constructing an object
92      */
93     private static Map<String, Object> getTopicParametersMap() {
94         final Map<String, Object> map = new TreeMap<>();
95         map.put("topicSources", SOURCE_TOPIC_PARAMS);
96         map.put("topicSinks", SINK_TOPIC_PARAMS);
97         return map;
98     }
99
100     /**
101      * Returns topic parameters for test cases.
102      *
103      * @return topic parameters
104      */
105     private static TopicParameters getSinkTopicParams() {
106         final var topicParams = new TopicParameters();
107         topicParams.setTopic("policy-acruntime-participant");
108         topicParams.setTopicCommInfrastructure("NOOP");
109         topicParams.setServers(List.of("localhost"));
110         return topicParams;
111     }
112
113     /**
114      * Returns sync topic parameters for test cases.
115      *
116      * @return topic parameters
117      */
118     private static TopicParameters getSyncTopicParams() {
119         final var topicParams = new TopicParameters();
120         topicParams.setTopic("acm-ppnt-sync");
121         topicParams.setTopicCommInfrastructure("NOOP");
122         topicParams.setServers(List.of("localhost"));
123         return topicParams;
124     }
125
126     /**
127      * Returns participantId for test cases.
128      *
129      * @return participant Id
130      */
131     public static UUID getParticipantId() {
132         return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c01");
133     }
134
135     /**
136      * Returns a Map of ToscaConceptIdentifier and AutomationComposition for test cases.
137      *
138      * @return automationCompositionMap
139      */
140     public static Map<UUID, AutomationComposition> getTestAutomationCompositionMap() {
141         var automationComposition = getTestAutomationComposition();
142         return Map.of(automationComposition.getInstanceId(), automationComposition);
143     }
144
145     /**
146      * Returns List of AutomationComposition for test cases.
147      *
148      * @return AutomationCompositions
149      */
150     public static AutomationComposition getTestAutomationComposition() {
151         var automationComposition = new AutomationComposition();
152         automationComposition.setInstanceId(UUID.randomUUID());
153         var element = new AutomationCompositionElement();
154         element.setId(UUID.randomUUID());
155         automationComposition.setElements(Map.of(element.getId(), element));
156         return automationComposition;
157     }
158
159     /**
160      * Create a new SimConfig.
161      *
162      * @return a new SimConfig
163      */
164     public static SimConfig createSimConfig() {
165         var config = new SimConfig();
166         config.setPrepareTimerMs(1);
167         config.setDeployTimerMs(1);
168         config.setReviewTimerMs(1);
169         config.setUndeployTimerMs(1);
170         config.setLockTimerMs(1);
171         config.setUnlockTimerMs(1);
172         config.setUpdateTimerMs(1);
173         config.setDeleteTimerMs(1);
174         config.setPrimeTimerMs(1);
175         config.setDeprimeTimerMs(1);
176         config.setMigrateTimerMs(1);
177         config.setMigratePrecheckTimerMs(1);
178         return config;
179     }
180 }