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.junit4.SpringJUnit4ClassRunner;
46 @RunWith(SpringJUnit4ClassRunner.class)
47 @SpringBootTest(classes = Application.class)
48 public class ToscaConverterWithDictionarySupportItCase {
51 private DictionaryService dictionaryService;
54 private ToscaMetadataParserWithDictionarySupport toscaMetadataParserWithDictionarySupport;
57 private ToscaMetadataExecutor toscaMetadataExecutor;
60 * This Test validates Tosca yaml with metadata tag that contains policy_model_type and acronym
61 * parameters which defines the Tosca Policy name and its short name.
63 * @throws IOException In case of issue when opening the tosca yaml file and
68 public final void testMetadataClampPossibleValues() throws IOException, UnknownComponentException {
70 // Set up dictionary elements
71 Dictionary dictionaryTest = new Dictionary();
72 dictionaryTest.setName("Context");
73 dictionaryTest.setSecondLevelDictionary(0);
75 DictionaryElement element = new DictionaryElement();
76 element.setName("PROD");
77 element.setShortName("PROD");
78 element.setType("string");
79 element.setDescription("Production");
80 dictionaryTest.addDictionaryElements(element);
82 dictionaryService.saveOrUpdateDictionary(dictionaryTest);
84 Dictionary dictionaryTest1 = new Dictionary();
85 dictionaryTest1.setName("EventDictionary");
86 dictionaryTest1.setSecondLevelDictionary(0);
88 DictionaryElement element1 = new DictionaryElement();
89 element1.setName("alarmCondition");
90 element1.setShortName("alarmCondition");
91 element1.setType("string");
92 element1.setDescription("Alarm Condition");
93 dictionaryTest1.addDictionaryElements(element1);
95 dictionaryService.saveOrUpdateDictionary(dictionaryTest1);
97 Dictionary dictionaryTest2 = new Dictionary();
98 dictionaryTest2.setName("Operators");
99 dictionaryTest2.setSecondLevelDictionary(0);
101 DictionaryElement element2 = new DictionaryElement();
102 element2.setName("equals");
103 element2.setShortName("equals");
104 element2.setType("string");
105 element2.setDescription("equals");
106 dictionaryTest2.addDictionaryElements(element2);
107 dictionaryService.saveOrUpdateDictionary(dictionaryTest2);
109 JsonTemplateManager jsonTemplateManager =
110 new JsonTemplateManager(
111 ResourceFileUtil.getResourceAsString("tosca/new-converter/tosca_metadata_clamp_possible_values.yaml"),
112 ResourceFileUtil.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
113 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
115 JsonObject jsonSchema = jsonTemplateManager.getJsonSchemaForPolicyType(
116 "onap.policies.monitoring.cdap.tca.hi.lo.app", toscaMetadataParserWithDictionarySupport, null);
118 JSONAssert.assertEquals(
120 .getResourceAsString("tosca/new-converter/tca-with-metadata.json"),
121 JsonUtils.GSON.toJson(jsonSchema), true);
126 public final void testMetadataClampPossibleValueWithExecutor() throws IOException, UnknownComponentException {
127 Service service = new Service(ResourceFileUtil.getResourceAsString("tosca/service-details.json"),
128 ResourceFileUtil.getResourceAsString("tosca/resource-details.json"));
129 JsonTemplateManager jsonTemplateManager =
130 new JsonTemplateManager(
131 ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
132 + ".policies.controlloop.operational.common.Apex/versions/1.0"
133 + ".0?connectionTimeToLive=5000/.file"),
134 ResourceFileUtil.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
135 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
137 JsonObject jsonSchema = jsonTemplateManager.getJsonSchemaForPolicyType(
138 "onap.policies.controlloop.operational.common.Apex", toscaMetadataParserWithDictionarySupport, service);
140 JSONAssert.assertEquals(
142 .getResourceAsString("tosca/new-converter/tosca_apex_with_metadata.json"),
143 JsonUtils.GSON.toJson(jsonSchema), true);