c2338d9fe1c30a9fc6aca720bb02a1221e698241
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2023 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.sim.parameters.ParticipantSimParameters;
29 import org.onap.policy.common.endpoints.parameters.TopicParameters;
30 import org.onap.policy.common.utils.coder.Coder;
31 import org.onap.policy.common.utils.coder.CoderException;
32 import org.onap.policy.common.utils.coder.StandardCoder;
33
34 public class CommonTestData {
35     public static final Coder CODER = new StandardCoder();
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     /**
41      * Get ParticipantSimParameters.
42      *
43      * @return ParticipantSimParameters
44      */
45     public static ParticipantSimParameters getParticipantSimParameters() {
46         try {
47             return CODER.convert(getParticipantSimParametersMap(), ParticipantSimParameters.class);
48         } catch (final CoderException e) {
49             throw new RuntimeException("cannot create ParticipantSimParameters from map", e);
50         }
51     }
52
53     /**
54      * Returns a property map for a ParticipantSimParameters map for test cases.
55      *
56      * @return a property map suitable for constructing an object
57      */
58     private static Map<String, Object> getParticipantSimParametersMap() {
59         final Map<String, Object> map = new TreeMap<>();
60
61         map.put("intermediaryParameters", getIntermediaryParametersMap());
62         return map;
63     }
64
65     /**
66      * Returns a property map for a intermediaryParameters map for test cases.
67      *
68      * @return a property map suitable for constructing an object
69      */
70     private static Map<String, Object> getIntermediaryParametersMap() {
71         final Map<String, Object> map = new TreeMap<>();
72         map.put("name", "Participant parameters");
73         map.put("reportingTimeIntervalMs", TIME_INTERVAL);
74         map.put("description", DESCRIPTION);
75         map.put("participantId", getParticipantId());
76         map.put("clampAutomationCompositionTopics", getTopicParametersMap());
77         map.put("participantSupportedElementTypes", new ArrayList<>());
78
79         return map;
80     }
81
82     /**
83      * Returns a property map for a TopicParameters map for test cases.
84      *
85      * @return a property map suitable for constructing an object
86      */
87     private static Map<String, Object> getTopicParametersMap() {
88         final Map<String, Object> map = new TreeMap<>();
89         map.put("topicSources", TOPIC_PARAMS);
90         map.put("topicSinks", TOPIC_PARAMS);
91         return map;
92     }
93
94     /**
95      * Returns topic parameters for test cases.
96      *
97      * @return topic parameters
98      */
99     private static TopicParameters getTopicParams() {
100         final TopicParameters topicParams = new TopicParameters();
101         topicParams.setTopic("POLICY-ACRUNTIME-PARTICIPANT");
102         topicParams.setTopicCommInfrastructure("dmaap");
103         topicParams.setServers(List.of("localhost"));
104         return topicParams;
105     }
106
107     /**
108      * Returns participantId for test cases.
109      *
110      * @return participant Id
111      */
112     public static UUID getParticipantId() {
113         return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c01");
114     }
115 }