2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 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.policy.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.policy.clamp.clds.Application;
32 import org.onap.policy.clamp.clds.tosca.update.parser.metadata.ToscaMetadataParserWithDictionarySupport;
33 import org.onap.policy.clamp.clds.tosca.update.templates.JsonTemplateManager;
34 import org.onap.policy.clamp.clds.util.JsonUtils;
35 import org.onap.policy.clamp.clds.util.ResourceFileUtils;
36 import org.onap.policy.clamp.loop.service.Service;
37 import org.onap.policy.clamp.tosca.Dictionary;
38 import org.onap.policy.clamp.tosca.DictionaryElement;
39 import org.onap.policy.clamp.tosca.DictionaryService;
40 import org.skyscreamer.jsonassert.JSONAssert;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.boot.test.context.SpringBootTest;
43 import org.springframework.test.context.ActiveProfiles;
44 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
46 @RunWith(SpringJUnit4ClassRunner.class)
47 @SpringBootTest(classes = Application.class)
48 @ActiveProfiles({"clamp-default", "clamp-default-user", "default-dictionary-elements"})
49 public class ToscaConverterWithDictionarySupportItTestCase {
52 private DictionaryService dictionaryService;
55 private ToscaMetadataParserWithDictionarySupport toscaMetadataParserWithDictionarySupport;
58 * This Test validates Tosca yaml with metadata tag that contains policy_model_type and acronym
59 * parameters which defines the Tosca Policy name and its short name.
61 * @throws IOException In case of issue when opening the tosca yaml file and
66 public final void testMetadataClampPossibleValues() throws IOException, UnknownComponentException {
68 // Set up dictionary elements
69 Dictionary dictionaryTest = new Dictionary();
70 dictionaryTest.setName("Context");
71 dictionaryTest.setSecondLevelDictionary(0);
73 DictionaryElement element = new DictionaryElement();
74 element.setName("PROD");
75 element.setShortName("PROD");
76 element.setType("string");
77 element.setDescription("Production");
78 dictionaryTest.addDictionaryElements(element);
80 dictionaryService.saveOrUpdateDictionary(dictionaryTest);
82 Dictionary dictionaryTest1 = new Dictionary();
83 dictionaryTest1.setName("EventDictionary");
84 dictionaryTest1.setSecondLevelDictionary(0);
86 DictionaryElement element1 = new DictionaryElement();
87 element1.setName("alarmCondition");
88 element1.setShortName("alarmCondition");
89 element1.setType("string");
90 element1.setDescription("Alarm Condition");
91 dictionaryTest1.addDictionaryElements(element1);
93 dictionaryService.saveOrUpdateDictionary(dictionaryTest1);
95 Dictionary dictionaryTest2 = new Dictionary();
96 dictionaryTest2.setName("Operators");
97 dictionaryTest2.setSecondLevelDictionary(0);
99 DictionaryElement element2 = new DictionaryElement();
100 element2.setName("equals");
101 element2.setShortName("equals");
102 element2.setType("string");
103 element2.setDescription("equals");
104 dictionaryTest2.addDictionaryElements(element2);
105 dictionaryService.saveOrUpdateDictionary(dictionaryTest2);
107 JsonTemplateManager jsonTemplateManager =
108 new JsonTemplateManager(
110 .getResourceAsString("tosca/new-converter/tosca_metadata_clamp_possible_values.yaml"),
111 ResourceFileUtils.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
112 ResourceFileUtils.getResourceAsString("clds/tosca-converter/templates.json"));
114 JsonObject jsonSchema = jsonTemplateManager.getJsonSchemaForPolicyType(
115 "onap.policies.monitoring.cdap.tca.hi.lo.app", toscaMetadataParserWithDictionarySupport, null);
117 JSONAssert.assertEquals(
119 .getResourceAsString("tosca/new-converter/tca-with-metadata.json"),
120 JsonUtils.GSON.toJson(jsonSchema), true);
125 public final void testMetadataClampPossibleValueWithExecutor() throws IOException, UnknownComponentException {
126 Service service = new Service(ResourceFileUtils.getResourceAsString("tosca/service-details.json"),
127 ResourceFileUtils.getResourceAsString("tosca/resource-details-cds.json"));
128 JsonTemplateManager jsonTemplateManager =
129 new JsonTemplateManager(
130 ResourceFileUtils.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
131 + ".policies.controlloop.operational.common.Apex/versions/1.0.0/.file"),
132 ResourceFileUtils.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
133 ResourceFileUtils.getResourceAsString("clds/tosca-converter/templates.json"));
135 JsonObject jsonSchema = jsonTemplateManager.getJsonSchemaForPolicyType(
136 "onap.policies.controlloop.operational.common.Apex", toscaMetadataParserWithDictionarySupport, service);
138 JSONAssert.assertEquals(
140 .getResourceAsString("tosca/new-converter/tosca_apex_with_metadata.json"),
141 JsonUtils.GSON.toJson(jsonSchema), true);