2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved.
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.
16 * ============LICENSE_END========================================================================
19 package com.oransc.rappmanager.models;
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.mockito.Mockito.mock;
24 import com.google.gson.JsonArray;
25 import com.google.gson.JsonParser;
26 import com.oransc.rappmanager.models.rapp.Rapp;
27 import com.oransc.rappmanager.models.rappinstance.RappInstance;
28 import java.util.HashMap;
30 import java.util.UUID;
31 import org.junit.jupiter.api.Test;
32 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
33 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
40 class AcmInterceptorTest implements AcmInterceptor {
43 void testInjectAutomationComposition() {
44 AutomationComposition automationComposition = new AutomationComposition();
45 Map<UUID, AutomationCompositionElement> elements =
46 new HashMap<>(Map.of(UUID.randomUUID(), new AutomationCompositionElement()));
47 automationComposition.setElements(elements);
48 assertEquals(1, automationComposition.getElements().size());
49 injectAutomationComposition(automationComposition, mock(Rapp.class), mock(RappInstance.class));
50 assertEquals(2, automationComposition.getElements().size());
54 void testInjectToscaServiceTemplate() {
55 ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate();
56 toscaServiceTemplate.setDataTypes(new HashMap<>(Map.of("datatype1", new ToscaDataType())));
57 toscaServiceTemplate.setNodeTypes(new HashMap<>(Map.of("nodetype1", new ToscaNodeType())));
58 ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate();
59 ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate();
60 String elements = "elements";
61 toscaNodeTemplate.setProperties(new HashMap<>(Map.of(elements, "[{}]")));
62 String nodeTemplateKey = "onap.policy.clamp.ac.element.AutomationCompositionDefinition";
64 toscaTopologyTemplate.setNodeTemplates(new HashMap<>(Map.of(nodeTemplateKey, toscaNodeTemplate)));
65 toscaServiceTemplate.setToscaTopologyTemplate(toscaTopologyTemplate);
67 toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().get(nodeTemplateKey).getProperties()
69 JsonArray elementArray = JsonParser.parseString(o.toString()).getAsJsonArray();
70 assertEquals(1, toscaServiceTemplate.getDataTypes().size());
71 assertEquals(1, toscaServiceTemplate.getNodeTypes().size());
72 assertEquals(1, elementArray.size());
73 injectToscaServiceTemplate(toscaServiceTemplate);
75 toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().get(nodeTemplateKey).getProperties()
77 JsonArray newElementArray = JsonParser.parseString(modObject.toString()).getAsJsonArray();
78 assertEquals(2, toscaServiceTemplate.getDataTypes().size());
79 assertEquals(2, toscaServiceTemplate.getNodeTypes().size());
80 assertEquals(2, newElementArray.size());
84 public void injectToscaServiceTemplate(ToscaServiceTemplate toscaServiceTemplate) {
85 injectToscaServiceTemplate(toscaServiceTemplate, "element1", "1.0.0");
89 public Map<String, ToscaNodeTemplate> getNodeTemplates() {
90 return new HashMap<>(Map.of(UUID.randomUUID().toString(), new ToscaNodeTemplate()));
94 public Map<String, ToscaNodeType> getNodeTypes() {
95 return new HashMap<>(Map.of(UUID.randomUUID().toString(), new ToscaNodeType()));
99 public Map<String, ToscaDataType> getDataTypes() {
100 return new HashMap<>(Map.of(UUID.randomUUID().toString(), new ToscaDataType()));
104 public Map<UUID, AutomationCompositionElement> getInstantiationElement(Rapp rapp, RappInstance rappInstance) {
105 return new HashMap<>(Map.of(UUID.randomUUID(), new AutomationCompositionElement()));