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.tosca.update.templates.JsonTemplate;
32 import org.onap.clamp.clds.tosca.update.templates.JsonTemplateField;
33 import org.onap.clamp.clds.tosca.update.templates.JsonTemplateManager;
34 import org.onap.clamp.clds.util.ResourceFileUtil;
36 public class JsonTemplateManagerTest extends TestCase {
39 * Test the launch translation wit operational policies.
41 * @throws IOException In case of failure
42 * @throws UnknownComponentException In case of failure
44 public void testLaunchTranslationTca() throws IOException, UnknownComponentException {
45 JsonTemplateManager jsonTemplateManager =
46 new JsonTemplateManager(
47 ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
48 + ".policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0?"
49 + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString(
50 "clds/tosca-converter/default-tosca-types.yaml"),
51 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
52 String componentName = "onap.policies.monitoring.cdap.tca.hi.lo.app";
53 jsonTemplateManager.getJsonSchemaForPolicyType(componentName, null, null);
57 * Test the launch translation wit operational policies.
59 * @throws IOException In case of failure
60 * @throws UnknownComponentException In case of failure
62 public void testLaunchTranslationFrequencyLimiter() throws IOException, UnknownComponentException {
63 JsonTemplateManager jsonTemplateManager =
64 new JsonTemplateManager(
65 ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
66 + ".policies.controlloop.guard.common.FrequencyLimiter/versions/1.0.0?"
67 + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString(
68 "clds/tosca-converter/default-tosca-types.yaml"),
69 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
70 String componentName = "onap.policies.controlloop.guard.common.FrequencyLimiter";
71 jsonTemplateManager.getJsonSchemaForPolicyType(componentName, null, null);
75 * Test the launch translation wit operational policies.
77 * @throws IOException In case of failure
78 * @throws UnknownComponentException In case of failure
80 public void testLaunchTranslationApex() throws IOException, UnknownComponentException {
81 JsonTemplateManager jsonTemplateManager =
82 new JsonTemplateManager(
83 ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
84 + ".policies.controlloop.operational.common.Apex/versions/1.0.0?"
85 + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString(
86 "clds/tosca-converter/default-tosca-types.yaml"),
87 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
88 String componentName = "onap.policies.controlloop.operational.common.Apex";
89 jsonTemplateManager.getJsonSchemaForPolicyType(componentName, null, null);
93 * Test the launch translation wit operational policies.
95 * @throws IOException In case of failure
96 * @throws UnknownComponentException In case of failure
98 public void testLaunchTranslationDrools() throws IOException, UnknownComponentException {
99 JsonTemplateManager jsonTemplateManager =
100 new JsonTemplateManager(
101 ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
102 + ".policies.controlloop.operational.common.Drools/versions/1.0.0?"
103 + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString(
104 "clds/tosca-converter/default-tosca-types.yaml"),
105 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
106 String componentName = "onap.policies.controlloop.operational.common.Drools";
107 jsonTemplateManager.getJsonSchemaForPolicyType(componentName, null, null);
112 * Test the launch translation.
114 * @throws IOException In case of failure
115 * @throws UnknownComponentException In case of failure
117 public void testLaunchTranslation() throws IOException, UnknownComponentException {
118 JsonTemplateManager jsonTemplateManager =
119 new JsonTemplateManager(
120 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
121 ResourceFileUtil.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
122 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
123 String componentName = "onap.policies.controlloop.operational.common.Drools";
124 jsonTemplateManager.getJsonSchemaForPolicyType(componentName, null, null);
130 * @throws IOException In case of failure
132 public void testAddTemplate() throws IOException {
133 JsonTemplateManager jsonTemplateManager =
134 new JsonTemplateManager(
135 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
136 ResourceFileUtil.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
137 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
138 int count = jsonTemplateManager.getJsonSchemaTemplates().size();
139 List<JsonTemplateField>
141 new ArrayList<>(Arrays.asList(new JsonTemplateField("type"), new JsonTemplateField("description"),
142 new JsonTemplateField(
144 new JsonTemplateField("metadata"), new JsonTemplateField("constraints")));
145 jsonTemplateManager.addTemplate("test", jsonTemplateFields);
146 assertNotSame(count, jsonTemplateManager.getJsonSchemaTemplates().size());
150 * test Remove template.
152 * @throws IOException In case of failure
154 public void testRemoveTemplate() throws IOException {
155 JsonTemplateManager jsonTemplateManager =
156 new JsonTemplateManager(
157 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
158 ResourceFileUtil.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
159 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
160 int count = jsonTemplateManager.getJsonSchemaTemplates().size();
161 jsonTemplateManager.removeTemplate("string");
162 assertNotSame(count, jsonTemplateManager.getJsonSchemaTemplates().size());
166 * Test update template.
168 * @throws IOException In case of failure
170 public void testUpdateTemplate() throws IOException {
171 JsonTemplateManager jsonTemplateManager =
172 new JsonTemplateManager(
173 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
174 ResourceFileUtil.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
175 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
176 int count = jsonTemplateManager.getJsonSchemaTemplates().get("integer").getJsonTemplateFields().size();
177 jsonTemplateManager.updateTemplate("integer", new JsonTemplateField("type"), false);
179 jsonTemplateManager.getJsonSchemaTemplates().get("integer").getJsonTemplateFields().size());
185 * @throws IOException In case of failure
187 public void testHasTemplate() throws IOException {
188 JsonTemplateManager jsonTemplateManager =
189 new JsonTemplateManager(
190 ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
191 ResourceFileUtil.getResourceAsString("clds/tosca-converter/default-tosca-types.yaml"),
192 ResourceFileUtil.getResourceAsString("clds/tosca-converter/templates.json"));
194 List<JsonTemplateField> jsonTemplateFieldsString =
195 new ArrayList<>(Arrays.asList(new JsonTemplateField("type"), new JsonTemplateField("description"),
196 new JsonTemplateField("required"),
197 new JsonTemplateField("metadata"), new JsonTemplateField("constraints")));
198 JsonTemplate jsonTemplateTest = new JsonTemplate("String", jsonTemplateFieldsString);
199 has = jsonTemplateManager.hasTemplate(jsonTemplateTest);
200 assertEquals(false, has);