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 java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.List;
30 import junit.framework.TestCase;
31 import org.onap.clamp.clds.util.ResourceFileUtil;
33 public class ToscaConverterManagerTest extends TestCase {
36 * Test the launch translation wit operational policies.
38 * @throws IOException In case of failure
39 * @throws UnknownComponentException In case of failure
41 public void testLaunchTranslationTca() throws IOException, UnknownComponentException {
42 ToscaConverterManager toscaConverterManager =
43 new ToscaConverterManager(
44 ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
45 + ".policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0?"
46 + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString(
47 "clds/tosca_update/default-tosca-types.yaml"),
48 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
49 assertNull(toscaConverterManager.getParseToJson());
50 String componentName = "onap.policies.monitoring.cdap.tca.hi.lo.app";
51 toscaConverterManager.startConversionToJson(componentName);
52 assertNotNull(toscaConverterManager.getParseToJson());
56 * Test the launch translation wit operational policies.
58 * @throws IOException In case of failure
59 * @throws UnknownComponentException In case of failure
61 public void testLaunchTranslationFrequencyLimiter() throws IOException, UnknownComponentException {
62 ToscaConverterManager toscaConverterManager =
63 new ToscaConverterManager(
64 ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
65 + ".policies.controlloop.guard.common.FrequencyLimiter/versions/1.0.0?"
66 + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString(
67 "clds/tosca_update/default-tosca-types.yaml"),
68 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
69 assertNull(toscaConverterManager.getParseToJson());
70 String componentName = "onap.policies.controlloop.guard.common.FrequencyLimiter";
71 toscaConverterManager.startConversionToJson(componentName);
72 assertNotNull(toscaConverterManager.getParseToJson());
76 * Test the launch translation wit operational policies.
78 * @throws IOException In case of failure
79 * @throws UnknownComponentException In case of failure
81 public void testLaunchTranslationApex() throws IOException, UnknownComponentException {
82 ToscaConverterManager toscaConverterManager =
83 new ToscaConverterManager(
84 ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
85 + ".policies.controlloop.operational.common.Apex/versions/1.0.0?"
86 + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString(
87 "clds/tosca_update/default-tosca-types.yaml"),
88 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
89 assertNull(toscaConverterManager.getParseToJson());
90 String componentName = "onap.policies.controlloop.operational.common.Apex";
91 toscaConverterManager.startConversionToJson(componentName);
92 assertNotNull(toscaConverterManager.getParseToJson());
96 * Test the launch translation wit operational policies.
98 * @throws IOException In case of failure
99 * @throws UnknownComponentException In case of failure
101 public void testLaunchTranslationDrools() throws IOException, UnknownComponentException {
102 ToscaConverterManager toscaConverterManager =
103 new ToscaConverterManager(
104 ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
105 + ".policies.controlloop.operational.common.Drools/versions/1.0.0?"
106 + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString(
107 "clds/tosca_update/default-tosca-types.yaml"),
108 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
109 assertNull(toscaConverterManager.getParseToJson());
110 String componentName = "onap.policies.controlloop.operational.common.Drools";
111 toscaConverterManager.startConversionToJson(componentName);
112 assertNotNull(toscaConverterManager.getParseToJson());
116 * Test the launch translation.
118 * @throws IOException In case of failure
119 * @throws UnknownComponentException In case of failure
121 public void testLaunchTranslation() throws IOException, UnknownComponentException {
122 ToscaConverterManager toscaConverterManager =
123 new ToscaConverterManager(
124 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
125 ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
126 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
127 assertNull(toscaConverterManager.getParseToJson());
128 String componentName = "onap.policies.controlloop.operational.common.Drools";
129 toscaConverterManager.startConversionToJson(componentName);
130 assertNotNull(toscaConverterManager.getParseToJson());
136 * @throws IOException In case of failure
138 public void testAddTemplate() throws IOException {
139 ToscaConverterManager toscaConverterManager =
140 new ToscaConverterManager(
141 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
142 ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
143 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
144 int count = toscaConverterManager.getTemplates().size();
145 List<TemplateField> templateFields = new ArrayList<>(Arrays.asList(new TemplateField("type"), new TemplateField("description"),
148 new TemplateField("metadata"), new TemplateField("constraints")));
149 toscaConverterManager.addTemplate("test", templateFields);
150 assertNotSame(count, toscaConverterManager.getTemplates().size());
154 * test Remove template.
156 * @throws IOException In case of failure
158 public void testRemoveTemplate() throws IOException {
159 ToscaConverterManager toscaConverterManager =
160 new ToscaConverterManager(
161 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
162 ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
163 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
164 int count = toscaConverterManager.getTemplates().size();
165 toscaConverterManager.removeTemplate("string");
166 assertNotSame(count, toscaConverterManager.getTemplates().size());
170 * Test update template.
172 * @throws IOException In case of failure
174 public void testUpdateTemplate() throws IOException {
175 ToscaConverterManager toscaConverterManager =
176 new ToscaConverterManager(
177 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
178 ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
179 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
180 int count = toscaConverterManager.getTemplates().get("integer").getTemplateFields().size();
181 toscaConverterManager.updateTemplate("integer", new TemplateField("type"), false);
182 assertNotSame(count, toscaConverterManager.getTemplates().get("integer").getTemplateFields().size());
188 * @throws IOException In case of failure
190 public void testHasTemplate() throws IOException {
191 ToscaConverterManager toscaConverterManager =
192 new ToscaConverterManager(
193 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
194 ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
195 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
197 List<TemplateField> templateFieldsString =
198 new ArrayList<>(Arrays.asList(new TemplateField("type"), new TemplateField("description"), new TemplateField("required"),
199 new TemplateField("metadata"), new TemplateField("constraints")));
200 Template templateTest = new Template("String", templateFieldsString);
201 has = toscaConverterManager.hasTemplate(templateTest);
202 assertEquals(false, has);