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 TemplateManagementTest 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 TemplateManagement templateManagement =
43 new TemplateManagement(
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/defaultToscaTypes.yaml"),
48 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
49 assertNull(templateManagement.getParseToJson());
50 String componentName = "onap.policies.monitoring.cdap.tca.hi.lo.app";
51 templateManagement.launchTranslation(componentName);
52 assertNotNull(templateManagement.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 TemplateManagement templateManagement =
63 new TemplateManagement(
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/defaultToscaTypes.yaml"),
68 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
69 assertNull(templateManagement.getParseToJson());
70 String componentName = "onap.policies.controlloop.guard.common.FrequencyLimiter";
71 templateManagement.launchTranslation(componentName);
72 assertNotNull(templateManagement.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 TemplateManagement templateManagement =
83 new TemplateManagement(
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/defaultToscaTypes.yaml"),
88 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
89 assertNull(templateManagement.getParseToJson());
90 String componentName = "onap.policies.controlloop.operational.common.Apex";
91 templateManagement.launchTranslation(componentName);
92 assertNotNull(templateManagement.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 TemplateManagement templateManagement =
103 new TemplateManagement(
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/defaultToscaTypes.yaml"),
108 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
109 assertNull(templateManagement.getParseToJson());
110 String componentName = "onap.policies.controlloop.operational.common.Drools";
111 templateManagement.launchTranslation(componentName);
112 assertNotNull(templateManagement.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 TemplateManagement templateManagement =
123 new TemplateManagement(
124 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
125 ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
126 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
127 assertNull(templateManagement.getParseToJson());
128 String componentName = "onap.policies.controlloop.operational.common.Drools";
129 templateManagement.launchTranslation(componentName);
130 assertNotNull(templateManagement.getParseToJson());
136 * @throws IOException In case of failure
138 public void testAddTemplate() throws IOException {
139 TemplateManagement templateManagement =
140 new TemplateManagement(
141 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
142 ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
143 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
144 int count = templateManagement.getTemplates().size();
145 List<Field> templateFields = new ArrayList<>(Arrays.asList(new Field("type"), new Field("description"),
148 new Field("metadata"), new Field("constraints")));
149 templateManagement.addTemplate("test", templateFields);
150 assertNotSame(count, templateManagement.getTemplates().size());
154 * test Remove template.
156 * @throws IOException In case of failure
158 public void testRemoveTemplate() throws IOException {
159 TemplateManagement templateManagement =
160 new TemplateManagement(
161 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
162 ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
163 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
164 int count = templateManagement.getTemplates().size();
165 templateManagement.removeTemplate("string");
166 assertNotSame(count, templateManagement.getTemplates().size());
170 * Test update template.
172 * @throws IOException In case of failure
174 public void testUpdateTemplate() throws IOException {
175 TemplateManagement templateManagement =
176 new TemplateManagement(
177 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
178 ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
179 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
180 int count = templateManagement.getTemplates().get("integer").getFields().size();
181 templateManagement.updateTemplate("integer", new Field("type"), false);
182 assertNotSame(count, templateManagement.getTemplates().get("integer").getFields().size());
188 * @throws IOException In case of failure
190 public void testHasTemplate() throws IOException {
191 TemplateManagement templateManagement =
192 new TemplateManagement(
193 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
194 ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
195 ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
197 List<Field> templateFieldsString =
198 new ArrayList<>(Arrays.asList(new Field("type"), new Field("description"), new Field("required"),
199 new Field("metadata"), new Field("constraints")));
200 Template templateTest = new Template("String", templateFieldsString);
201 has = templateManagement.hasTemplate(templateTest);
202 assertEquals(false, has);