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.parser.metadata.ToscaMetadataParserWithDictionarySupport;
33 import org.onap.clamp.clds.tosca.update.templates.JsonTemplateManager;
34 import org.onap.clamp.clds.util.JsonUtils;
35 import org.onap.clamp.clds.util.ResourceFileUtil;
36 import org.onap.clamp.tosca.Dictionary;
37 import org.onap.clamp.tosca.DictionaryElement;
38 import org.onap.clamp.tosca.DictionaryService;
39 import org.skyscreamer.jsonassert.JSONAssert;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.boot.test.context.SpringBootTest;
42 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
44 @RunWith(SpringJUnit4ClassRunner.class)
45 @SpringBootTest(classes = Application.class)
46 public class ToscaConverterWithDictionarySupportItCase {
49 private DictionaryService dictionaryService;
52 private ToscaMetadataParserWithDictionarySupport toscaMetadataParserWithDictionarySupport;
55 * This Test validates Tosca yaml with metadata tag that contains policy_model_type and acronym
56 * parameters which defines the Tosca Policy name and its short name.
58 * @throws IOException In case of issue when opening the tosca yaml file and
63 public final void testMetadataClampPossibleValues() throws IOException, UnknownComponentException {
65 // Set up dictionary elements
66 Dictionary dictionaryTest = new Dictionary();
67 dictionaryTest.setName("Context");
68 dictionaryTest.setSecondLevelDictionary(0);
70 DictionaryElement element = new DictionaryElement();
71 element.setName("PROD");
72 element.setShortName("PROD");
73 element.setType("string");
74 element.setDescription("Production");
75 dictionaryTest.addDictionaryElements(element);
77 dictionaryService.saveOrUpdateDictionary(dictionaryTest);
79 Dictionary dictionaryTest1 = new Dictionary();
80 dictionaryTest1.setName("EventDictionary");
81 dictionaryTest1.setSecondLevelDictionary(0);
83 DictionaryElement element1 = new DictionaryElement();
84 element1.setName("alarmCondition");
85 element1.setShortName("alarmCondition");
86 element1.setType("string");
87 element1.setDescription("Alarm Condition");
88 dictionaryTest1.addDictionaryElements(element1);
90 dictionaryService.saveOrUpdateDictionary(dictionaryTest1);
92 Dictionary dictionaryTest2 = new Dictionary();
93 dictionaryTest2.setName("Operators");
94 dictionaryTest2.setSecondLevelDictionary(0);
96 DictionaryElement element2 = new DictionaryElement();
97 element2.setName("equals");
98 element2.setShortName("equals");
99 element2.setType("string");
100 element2.setDescription("equals");
101 dictionaryTest2.addDictionaryElements(element2);
102 dictionaryService.saveOrUpdateDictionary(dictionaryTest2);
104 JsonTemplateManager jsonTemplateManager =
105 new JsonTemplateManager(
106 ResourceFileUtil.getResourceAsString("tosca/tosca_metadata_clamp_possible_values.yaml"),
107 ResourceFileUtil.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
108 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
110 JsonObject jsonSchema = jsonTemplateManager.getJsonSchemaForPolicyType(
111 "onap.policies.monitoring.cdap.tca.hi.lo.app", toscaMetadataParserWithDictionarySupport);
113 JSONAssert.assertEquals(
115 .getResourceAsString("tosca/new-converter/tca-with-metadata.json"),
116 JsonUtils.GSON.toJson(jsonSchema), true);