blob: b4f8b12458deb2315f84e545542abaf957165b40 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*-
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
* ===================================================================
*
*/
package org.onap.clamp.clds.tosca.update;
import com.google.gson.JsonObject;
import java.io.IOException;
import javax.transaction.Transactional;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.clamp.clds.Application;
import org.onap.clamp.clds.tosca.update.parser.metadata.ToscaMetadataParserWithDictionarySupport;
import org.onap.clamp.clds.tosca.update.templates.JsonTemplateManager;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.clamp.tosca.Dictionary;
import org.onap.clamp.tosca.DictionaryElement;
import org.onap.clamp.tosca.DictionaryService;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class ToscaConverterWithDictionarySupportItCase {
@Autowired
private DictionaryService dictionaryService;
@Autowired
private ToscaMetadataParserWithDictionarySupport toscaMetadataParserWithDictionarySupport;
/**
* This Test validates Tosca yaml with metadata tag that contains policy_model_type and acronym
* parameters which defines the Tosca Policy name and its short name.
*
* @throws IOException In case of issue when opening the tosca yaml file and
* converted json file
*/
@Test
@Transactional
public final void testMetadataClampPossibleValues() throws IOException, UnknownComponentException {
// Set up dictionary elements
Dictionary dictionaryTest = new Dictionary();
dictionaryTest.setName("Context");
dictionaryTest.setSecondLevelDictionary(0);
DictionaryElement element = new DictionaryElement();
element.setName("PROD");
element.setShortName("PROD");
element.setType("string");
element.setDescription("Production");
dictionaryTest.addDictionaryElements(element);
dictionaryService.saveOrUpdateDictionary(dictionaryTest);
Dictionary dictionaryTest1 = new Dictionary();
dictionaryTest1.setName("EventDictionary");
dictionaryTest1.setSecondLevelDictionary(0);
DictionaryElement element1 = new DictionaryElement();
element1.setName("alarmCondition");
element1.setShortName("alarmCondition");
element1.setType("string");
element1.setDescription("Alarm Condition");
dictionaryTest1.addDictionaryElements(element1);
dictionaryService.saveOrUpdateDictionary(dictionaryTest1);
Dictionary dictionaryTest2 = new Dictionary();
dictionaryTest2.setName("Operators");
dictionaryTest2.setSecondLevelDictionary(0);
DictionaryElement element2 = new DictionaryElement();
element2.setName("equals");
element2.setShortName("equals");
element2.setType("string");
element2.setDescription("equals");
dictionaryTest2.addDictionaryElements(element2);
dictionaryService.saveOrUpdateDictionary(dictionaryTest2);
JsonTemplateManager jsonTemplateManager =
new JsonTemplateManager(
ResourceFileUtil.getResourceAsString("tosca/tosca_metadata_clamp_possible_values.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
JsonObject jsonSchema = jsonTemplateManager.getJsonSchemaForPolicyType(
"onap.policies.monitoring.cdap.tca.hi.lo.app", toscaMetadataParserWithDictionarySupport);
JSONAssert.assertEquals(
ResourceFileUtil
.getResourceAsString("tosca/new-converter/tca-with-metadata.json"),
JsonUtils.GSON.toJson(jsonSchema), true);
}
}
|