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.models.controlloop.concepts;
23 import static org.assertj.core.api.Assertions.assertThat;
26 import org.junit.jupiter.api.Test;
27 import org.onap.policy.common.utils.coder.Coder;
28 import org.onap.policy.common.utils.coder.CoderException;
29 import org.onap.policy.common.utils.coder.StandardCoder;
30 import org.onap.policy.common.utils.coder.StandardYamlCoder;
31 import org.onap.policy.common.utils.resources.ResourceUtils;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
36 class ParticipantUtilsTest {
38 private static final Coder CODER = new StandardCoder();
39 private static final String TOSCA_TEMPLATE_YAML = "examples/controlloop/PMSubscriptionHandling.yaml";
40 private static final String CONTROL_LOOP_JSON = "src/test/resources/providers/TestControlLoops.json";
41 private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement";
42 private static final String POLICY_CONTROL_LOOP_ELEMENT =
43 "org.onap.policy.clamp.controlloop.PolicyControlLoopElement";
44 private static final String PARTICIPANT_CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.Participant";
45 private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
48 void testFindParticipantType() throws CoderException {
49 var identifier = new ToscaConceptIdentifier("Identifier", "1.0.1");
50 var result = ParticipantUtils.findParticipantType(Map.of("participantType", CODER.encode(identifier)));
51 assertThat(result).isEqualTo(identifier);
55 void testFindStartPhase() {
57 var result = ParticipantUtils.findStartPhase(Map.of("startPhase", identifier));
58 assertThat(result).isEqualTo(identifier);
62 void testGetFirstStartPhase() throws CoderException {
63 var serviceTemplate = YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML),
64 ToscaServiceTemplate.class);
65 var controlLoops = CODER.decode(ResourceUtils.getResourceAsString(CONTROL_LOOP_JSON), ControlLoops.class);
66 var result = ParticipantUtils.getFirstStartPhase(controlLoops.getControlLoopList().get(0), serviceTemplate);
67 assertThat(result).isZero();
71 void testCheckIfNodeTemplateIsControlLoopElement() throws CoderException {
72 var serviceTemplate = YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML),
73 ToscaServiceTemplate.class);
74 var nodeTemplate = new ToscaNodeTemplate();
75 nodeTemplate.setType(CONTROL_LOOP_ELEMENT);
76 assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isTrue();
78 nodeTemplate.setType(POLICY_CONTROL_LOOP_ELEMENT);
79 assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isTrue();
81 nodeTemplate.setType(PARTICIPANT_CONTROL_LOOP_ELEMENT);
82 assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isFalse();