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
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.acm.participant.intermediary.handler;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
27 import java.util.ArrayList;
28 import java.util.List;
30 import java.util.UUID;
31 import org.junit.jupiter.api.Test;
32 import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData;
33 import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
34 import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
35 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
36 import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
39 class CacheProviderTest {
42 void testgetSupportedAcElementTypes() {
43 var parameter = CommonTestData.getParticipantParameters();
44 var cacheProvider = new CacheProvider(parameter);
45 assertEquals(parameter.getIntermediaryParameters().getParticipantId(), cacheProvider.getParticipantId());
46 assertEquals(parameter.getIntermediaryParameters().getParticipantSupportedElementTypes().get(0),
47 cacheProvider.getSupportedAcElementTypes().get(0));
52 var parameter = CommonTestData.getParticipantParameters();
53 var cacheProvider = new CacheProvider(parameter);
54 var instanceId = UUID.randomUUID();
55 assertThatThrownBy(() -> cacheProvider.initializeAutomationComposition(null, null, null))
56 .isInstanceOf(NullPointerException.class);
57 assertThatThrownBy(() -> cacheProvider.initializeAutomationComposition(instanceId, null, null))
58 .isInstanceOf(NullPointerException.class);
59 assertThatThrownBy(() -> cacheProvider.initializeAutomationComposition(instanceId, instanceId, null))
60 .isInstanceOf(NullPointerException.class);
62 assertThatThrownBy(() -> cacheProvider.addElementDefinition(null, null))
63 .isInstanceOf(NullPointerException.class);
64 assertThatThrownBy(() -> cacheProvider.addElementDefinition(instanceId, null))
65 .isInstanceOf(NullPointerException.class);
67 assertThatThrownBy(() -> cacheProvider.getAutomationComposition(null)).isInstanceOf(NullPointerException.class);
69 assertThatThrownBy(() -> cacheProvider.getCommonProperties(null, null))
70 .isInstanceOf(NullPointerException.class);
71 assertThatThrownBy(() -> cacheProvider.getCommonProperties(instanceId, null))
72 .isInstanceOf(NullPointerException.class);
74 assertThatThrownBy(() -> cacheProvider.removeAutomationComposition(null))
75 .isInstanceOf(NullPointerException.class);
77 assertThatThrownBy(() -> cacheProvider.removeElementDefinition(null)).isInstanceOf(NullPointerException.class);
81 void testinitCommonProperties() throws AutomationCompositionException {
82 var parameter = CommonTestData.getParticipantParameters();
83 var cacheProvider = new CacheProvider(parameter);
84 var participantDeploy = new ParticipantDeploy();
85 participantDeploy.setParticipantId(cacheProvider.getParticipantId());
87 var compositionId = UUID.randomUUID();
89 List<AutomationCompositionElementDefinition> definitions = new ArrayList<>();
90 var automationComposition =
91 CommonTestData.getTestAutomationCompositions().getAutomationCompositionList().get(0);
92 automationComposition.setInstanceId(UUID.randomUUID());
93 automationComposition.setCompositionId(compositionId);
94 for (var element : automationComposition.getElements().values()) {
95 var acElementDefinition = new AutomationCompositionElementDefinition();
96 acElementDefinition.setAcElementDefinitionId(element.getDefinition());
97 var nodeTemplate = new ToscaNodeTemplate();
98 nodeTemplate.setProperties(Map.of("key", "value"));
99 acElementDefinition.setAutomationCompositionElementToscaNodeTemplate(nodeTemplate);
100 definitions.add(acElementDefinition);
102 var acElement = new AcElementDeploy();
103 acElement.setId(element.getId());
104 acElement.setDefinition(element.getDefinition());
105 participantDeploy.getAcElementList().add(acElement);
107 cacheProvider.addElementDefinition(compositionId, definitions);
109 cacheProvider.initializeAutomationComposition(compositionId, automationComposition.getInstanceId(),
112 for (var element : automationComposition.getElements().values()) {
113 var commonProperties =
114 cacheProvider.getCommonProperties(automationComposition.getInstanceId(), element.getId());
115 assertEquals("value", commonProperties.get("key"));
118 assertEquals(automationComposition.getInstanceId(),
119 cacheProvider.getAutomationComposition(automationComposition.getInstanceId()).getInstanceId());
121 assertThat(cacheProvider.getAutomationCompositions()).hasSize(1);
122 cacheProvider.removeAutomationComposition(automationComposition.getInstanceId());
123 assertThat(cacheProvider.getAutomationCompositions()).isEmpty();
125 cacheProvider.removeElementDefinition(compositionId);
126 assertThat(cacheProvider.getAcElementsDefinitions()).isEmpty();