2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.clds.tosca.update;
26 import com.google.gson.JsonObject;
27 import java.io.IOException;
28 import javax.transaction.Transactional;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.onap.clamp.clds.Application;
32 import org.onap.clamp.clds.tosca.update.execution.ToscaMetadataExecutor;
33 import org.onap.clamp.clds.tosca.update.parser.metadata.ToscaMetadataParserWithDictionarySupport;
34 import org.onap.clamp.clds.tosca.update.templates.JsonTemplateManager;
35 import org.onap.clamp.clds.util.JsonUtils;
36 import org.onap.clamp.clds.util.ResourceFileUtil;
37 import org.onap.clamp.loop.service.Service;
38 import org.onap.clamp.tosca.Dictionary;
39 import org.onap.clamp.tosca.DictionaryElement;
40 import org.onap.clamp.tosca.DictionaryService;
41 import org.skyscreamer.jsonassert.JSONAssert;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.boot.test.context.SpringBootTest;
44 import org.springframework.test.context.ActiveProfiles;
45 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
47 @RunWith(SpringJUnit4ClassRunner.class)
48 @SpringBootTest(classes = Application.class)
49 @ActiveProfiles(profiles = "clamp-default,clamp-default-user,default-dictionary-elements")
50 public class ToscaConverterWithDictionarySupportItCase {
53 private DictionaryService dictionaryService;
56 private ToscaMetadataParserWithDictionarySupport toscaMetadataParserWithDictionarySupport;
59 private ToscaMetadataExecutor toscaMetadataExecutor;
62 * This Test validates Tosca yaml with metadata tag that contains policy_model_type and acronym
63 * parameters which defines the Tosca Policy name and its short name.
65 * @throws IOException In case of issue when opening the tosca yaml file and
70 public final void testMetadataClampPossibleValues() throws IOException, UnknownComponentException {
72 // Set up dictionary elements
73 Dictionary dictionaryTest = new Dictionary();
74 dictionaryTest.setName("Context");
75 dictionaryTest.setSecondLevelDictionary(0);
77 DictionaryElement element = new DictionaryElement();
78 element.setName("PROD");
79 element.setShortName("PROD");
80 element.setType("string");
81 element.setDescription("Production");
82 dictionaryTest.addDictionaryElements(element);
84 dictionaryService.saveOrUpdateDictionary(dictionaryTest);
86 Dictionary dictionaryTest1 = new Dictionary();
87 dictionaryTest1.setName("EventDictionary");
88 dictionaryTest1.setSecondLevelDictionary(0);
90 DictionaryElement element1 = new DictionaryElement();
91 element1.setName("alarmCondition");
92 element1.setShortName("alarmCondition");
93 element1.setType("string");
94 element1.setDescription("Alarm Condition");
95 dictionaryTest1.addDictionaryElements(element1);
97 dictionaryService.saveOrUpdateDictionary(dictionaryTest1);
99 Dictionary dictionaryTest2 = new Dictionary();
100 dictionaryTest2.setName("Operators");
101 dictionaryTest2.setSecondLevelDictionary(0);
103 DictionaryElement element2 = new DictionaryElement();
104 element2.setName("equals");
105 element2.setShortName("equals");
106 element2.setType("string");
107 element2.setDescription("equals");
108 dictionaryTest2.addDictionaryElements(element2);
109 dictionaryService.saveOrUpdateDictionary(dictionaryTest2);
111 JsonTemplateManager jsonTemplateManager =
112 new JsonTemplateManager(
114 .getResourceAsString("tosca/new-converter/tosca_metadata_clamp_possible_values.yaml"),
115 ResourceFileUtil.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
116 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
118 JsonObject jsonSchema = jsonTemplateManager.getJsonSchemaForPolicyType(
119 "onap.policies.monitoring.cdap.tca.hi.lo.app", toscaMetadataParserWithDictionarySupport, null);
121 JSONAssert.assertEquals(
123 .getResourceAsString("tosca/new-converter/tca-with-metadata.json"),
124 JsonUtils.GSON.toJson(jsonSchema), true);
129 public final void testMetadataClampPossibleValueWithExecutor() throws IOException, UnknownComponentException {
130 Service service = new Service(ResourceFileUtil.getResourceAsString("tosca/service-details.json"),
131 ResourceFileUtil.getResourceAsString("tosca/resource-details.json"));
132 JsonTemplateManager jsonTemplateManager =
133 new JsonTemplateManager(
134 ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
135 + ".policies.controlloop.operational.common.Apex/versions/1.0"
136 + ".0?connectionTimeToLive=5000/.file"),
137 ResourceFileUtil.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
138 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
140 JsonObject jsonSchema = jsonTemplateManager.getJsonSchemaForPolicyType(
141 "onap.policies.controlloop.operational.common.Apex", toscaMetadataParserWithDictionarySupport, service);
143 JSONAssert.assertEquals(
145 .getResourceAsString("tosca/new-converter/tosca_apex_with_metadata.json"),
146 JsonUtils.GSON.toJson(jsonSchema), true);