From 8604d37f2f6bdd011de62ec474b6883413d30348 Mon Sep 17 00:00:00 2001 From: sebdet Date: Tue, 10 Mar 2020 02:44:53 -0700 Subject: Fix the tosca converter Fix the new tosca converter to support metadata section Issue-ID: CLAMP-580 Signed-off-by: sebdet Change-Id: I9068bd9dc89851c630660a7f78fae1cb70bdc178 --- .../clamp/clds/tosca/update/ArrayFieldTest.java | 8 +- .../clamp/clds/tosca/update/ComponentTest.java | 50 ----- .../clamp/clds/tosca/update/ConstraintTest.java | 22 +-- .../onap/clamp/clds/tosca/update/PropertyTest.java | 18 +- .../clds/tosca/update/TemplateManagementTest.java | 205 --------------------- .../onap/clamp/clds/tosca/update/TemplateTest.java | 6 +- .../tosca/update/ToscaConverterManagerTest.java | 205 +++++++++++++++++++++ .../clamp/clds/tosca/update/ToscaElementTest.java | 50 +++++ .../org/onap/clamp/loop/CsarInstallerItCase.java | 5 +- 9 files changed, 284 insertions(+), 285 deletions(-) delete mode 100644 src/test/java/org/onap/clamp/clds/tosca/update/ComponentTest.java delete mode 100644 src/test/java/org/onap/clamp/clds/tosca/update/TemplateManagementTest.java create mode 100644 src/test/java/org/onap/clamp/clds/tosca/update/ToscaConverterManagerTest.java create mode 100644 src/test/java/org/onap/clamp/clds/tosca/update/ToscaElementTest.java (limited to 'src/test') diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/ArrayFieldTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/ArrayFieldTest.java index a99d4ab5..83c374e9 100644 --- a/src/test/java/org/onap/clamp/clds/tosca/update/ArrayFieldTest.java +++ b/src/test/java/org/onap/clamp/clds/tosca/update/ArrayFieldTest.java @@ -37,12 +37,12 @@ public class ArrayFieldTest extends TestCase { * @throws IOException in case of failure */ public void testDeploy() throws IOException { - TemplateManagement templateManagement = new TemplateManagement(ResourceFileUtil.getResourceAsString( + ToscaConverterManager toscaConverterManager = new ToscaConverterManager(ResourceFileUtil.getResourceAsString( "tosca/new-converter/sampleOperationalPoliciesEXTENTED.yaml"),ResourceFileUtil.getResourceAsString( - "clds/tosca_update/defaultToscaTypes.yaml"), + "clds/tosca_update/default-tosca-types.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Actor"); - Property property = component.getProperties().get("actor"); + ToscaElement toscaElement = toscaConverterManager.getComponents().get("onap.datatype.controlloop.Actor"); + Property property = toscaElement.getProperties().get("actor"); ArrayField arrayParser = new ArrayField((ArrayList) property.getItems().get("default")); JsonArray toTest = arrayParser.deploy(); String reference = "[1,\"String\",5.5,true]"; diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/ComponentTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/ComponentTest.java deleted file mode 100644 index 565547e4..00000000 --- a/src/test/java/org/onap/clamp/clds/tosca/update/ComponentTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============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 java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import junit.framework.TestCase; -import org.onap.clamp.clds.util.ResourceFileUtil; - -public class ComponentTest extends TestCase { - - /** - * Test propertiesName. - * - * @throws IOException In case of failure - */ - public void testPropertiesNames() throws IOException { - ArrayList reference = new ArrayList<>(Arrays.asList("actor", "operation", "target", "payload")); - TemplateManagement templateManagement = - new TemplateManagement( - ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Actor"); - assertEquals(reference, component.propertiesNames()); - } - -} diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/ConstraintTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/ConstraintTest.java index a4d329e2..a73fd673 100644 --- a/src/test/java/org/onap/clamp/clds/tosca/update/ConstraintTest.java +++ b/src/test/java/org/onap/clamp/clds/tosca/update/ConstraintTest.java @@ -31,12 +31,12 @@ import org.onap.clamp.clds.util.ResourceFileUtil; public class ConstraintTest extends TestCase { - TemplateManagement templateManagement = new TemplateManagement( + ToscaConverterManager toscaConverterManager = new ToscaConverterManager( ResourceFileUtil.getResourceAsString("tosca/new-converter/constraints.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Operation"); + ToscaElement toscaElement = toscaConverterManager.getComponents().get("onap.datatype.controlloop.Operation"); public ConstraintTest() throws IOException { } @@ -45,15 +45,15 @@ public class ConstraintTest extends TestCase { * Test get value array. */ public void testGetValuesArray() { - Property property = component.getProperties().get("timeout"); - Template template = templateManagement.getTemplates().get("integer"); + Property property = toscaElement.getProperties().get("timeout"); + Template template = toscaConverterManager.getTemplates().get("integer"); JsonObject resultProcess = new JsonObject(); property.addConstraintsAsJson(resultProcess, (ArrayList) property.getItems().get("constraints"), template); String reference = "{\"enum\":[3,4,5.5,6,10]}"; assertEquals(reference, String.valueOf(resultProcess)); - property = component.getProperties().get("success"); - template = templateManagement.getTemplates().get("string"); + property = toscaElement.getProperties().get("success"); + template = toscaConverterManager.getTemplates().get("string"); resultProcess = new JsonObject(); property.addConstraintsAsJson(resultProcess, (ArrayList) property.getItems().get("constraints"), template); @@ -66,8 +66,8 @@ public class ConstraintTest extends TestCase { */ public void testGetSpecificLength() { //Test for string type, same process for array - Property property = component.getProperties().get("id"); - Template template = templateManagement.getTemplates().get("string"); + Property property = toscaElement.getProperties().get("id"); + Template template = toscaConverterManager.getTemplates().get("string"); JsonObject resultProcess = new JsonObject(); property.addConstraintsAsJson(resultProcess, (ArrayList) property.getItems().get("constraints"), template); @@ -83,8 +83,8 @@ public class ConstraintTest extends TestCase { */ public void testGetLimitValue() { //Test for array type, same process for string - Property property = component.getProperties().get("description"); - Template template = templateManagement.getTemplates().get("array"); + Property property = toscaElement.getProperties().get("description"); + Template template = toscaConverterManager.getTemplates().get("array"); JsonObject resultProcess = new JsonObject(); property.addConstraintsAsJson(resultProcess, (ArrayList) property.getItems().get("constraints"), template); diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/PropertyTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/PropertyTest.java index 62def32b..bb1929f9 100644 --- a/src/test/java/org/onap/clamp/clds/tosca/update/PropertyTest.java +++ b/src/test/java/org/onap/clamp/clds/tosca/update/PropertyTest.java @@ -40,12 +40,12 @@ public class PropertyTest extends TestCase { * @throws IOException In case of failure */ public void testParseArray() throws IOException { - TemplateManagement templateManagement = new TemplateManagement( + ToscaConverterManager toscaConverterManager = new ToscaConverterManager( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPoliciesEXTENTED.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Actor"); - Property property = component.getProperties().get("actor"); + ToscaElement toscaElement = toscaConverterManager.getComponents().get("onap.datatype.controlloop.Actor"); + Property property = toscaElement.getProperties().get("actor"); JsonArray toTest = property.parseArray((ArrayList) property.getItems().get("default")); assertNotNull(toTest); } @@ -56,13 +56,13 @@ public class PropertyTest extends TestCase { * @throws IOException In case of failure */ public void testAddConstraintsAsJson() throws IOException { - TemplateManagement templateManagement = new TemplateManagement( + ToscaConverterManager toscaConverterManager = new ToscaConverterManager( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - Component component = templateManagement.getComponents().get("onap.datatype.controlloop.operation.Failure"); - Property property = component.getProperties().get("category"); - Template template = templateManagement.getTemplates().get("string"); + ToscaElement toscaElement = toscaConverterManager.getComponents().get("onap.datatype.controlloop.operation.Failure"); + Property property = toscaElement.getProperties().get("category"); + Template template = toscaConverterManager.getTemplates().get("string"); JsonObject toTest = new JsonObject(); property.addConstraintsAsJson(toTest, (ArrayList) property.getItems().get("constraints"), template); String test = "{\"enum\":[\"error\",\"timeout\",\"retries\",\"guard\",\"exception\"]}"; diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/TemplateManagementTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/TemplateManagementTest.java deleted file mode 100644 index aaa54938..00000000 --- a/src/test/java/org/onap/clamp/clds/tosca/update/TemplateManagementTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/*- - * ============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 java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import junit.framework.TestCase; -import org.onap.clamp.clds.util.ResourceFileUtil; - -public class TemplateManagementTest extends TestCase { - - /** - * Test the launch translation wit operational policies. - * - * @throws IOException In case of failure - * @throws UnknownComponentException In case of failure - */ - public void testLaunchTranslationTca() throws IOException, UnknownComponentException { - TemplateManagement templateManagement = - new TemplateManagement( - ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap" - + ".policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0?" - + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString( - "clds/tosca_update/defaultToscaTypes.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - assertNull(templateManagement.getParseToJson()); - String componentName = "onap.policies.monitoring.cdap.tca.hi.lo.app"; - templateManagement.launchTranslation(componentName); - assertNotNull(templateManagement.getParseToJson()); - } - - /** - * Test the launch translation wit operational policies. - * - * @throws IOException In case of failure - * @throws UnknownComponentException In case of failure - */ - public void testLaunchTranslationFrequencyLimiter() throws IOException, UnknownComponentException { - TemplateManagement templateManagement = - new TemplateManagement( - ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap" - + ".policies.controlloop.guard.common.FrequencyLimiter/versions/1.0.0?" - + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString( - "clds/tosca_update/defaultToscaTypes.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - assertNull(templateManagement.getParseToJson()); - String componentName = "onap.policies.controlloop.guard.common.FrequencyLimiter"; - templateManagement.launchTranslation(componentName); - assertNotNull(templateManagement.getParseToJson()); - } - - /** - * Test the launch translation wit operational policies. - * - * @throws IOException In case of failure - * @throws UnknownComponentException In case of failure - */ - public void testLaunchTranslationApex() throws IOException, UnknownComponentException { - TemplateManagement templateManagement = - new TemplateManagement( - ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap" - + ".policies.controlloop.operational.common.Apex/versions/1.0.0?" - + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString( - "clds/tosca_update/defaultToscaTypes.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - assertNull(templateManagement.getParseToJson()); - String componentName = "onap.policies.controlloop.operational.common.Apex"; - templateManagement.launchTranslation(componentName); - assertNotNull(templateManagement.getParseToJson()); - } - - /** - * Test the launch translation wit operational policies. - * - * @throws IOException In case of failure - * @throws UnknownComponentException In case of failure - */ - public void testLaunchTranslationDrools() throws IOException, UnknownComponentException { - TemplateManagement templateManagement = - new TemplateManagement( - ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap" - + ".policies.controlloop.operational.common.Drools/versions/1.0.0?" - + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString( - "clds/tosca_update/defaultToscaTypes.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - assertNull(templateManagement.getParseToJson()); - String componentName = "onap.policies.controlloop.operational.common.Drools"; - templateManagement.launchTranslation(componentName); - assertNotNull(templateManagement.getParseToJson()); - } - - /** - * Test the launch translation. - * - * @throws IOException In case of failure - * @throws UnknownComponentException In case of failure - */ - public void testLaunchTranslation() throws IOException, UnknownComponentException { - TemplateManagement templateManagement = - new TemplateManagement( - ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - assertNull(templateManagement.getParseToJson()); - String componentName = "onap.policies.controlloop.operational.common.Drools"; - templateManagement.launchTranslation(componentName); - assertNotNull(templateManagement.getParseToJson()); - } - - /** - * Test addTemplate. - * - * @throws IOException In case of failure - */ - public void testAddTemplate() throws IOException { - TemplateManagement templateManagement = - new TemplateManagement( - ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - int count = templateManagement.getTemplates().size(); - List templateFields = new ArrayList<>(Arrays.asList(new Field("type"), new Field("description"), - new Field( - "required"), - new Field("metadata"), new Field("constraints"))); - templateManagement.addTemplate("test", templateFields); - assertNotSame(count, templateManagement.getTemplates().size()); - } - - /** - * test Remove template. - * - * @throws IOException In case of failure - */ - public void testRemoveTemplate() throws IOException { - TemplateManagement templateManagement = - new TemplateManagement( - ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - int count = templateManagement.getTemplates().size(); - templateManagement.removeTemplate("string"); - assertNotSame(count, templateManagement.getTemplates().size()); - } - - /** - * Test update template. - * - * @throws IOException In case of failure - */ - public void testUpdateTemplate() throws IOException { - TemplateManagement templateManagement = - new TemplateManagement( - ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - int count = templateManagement.getTemplates().get("integer").getFields().size(); - templateManagement.updateTemplate("integer", new Field("type"), false); - assertNotSame(count, templateManagement.getTemplates().get("integer").getFields().size()); - } - - /** - * Test has template. - * - * @throws IOException In case of failure - */ - public void testHasTemplate() throws IOException { - TemplateManagement templateManagement = - new TemplateManagement( - ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); - boolean has = true; - List templateFieldsString = - new ArrayList<>(Arrays.asList(new Field("type"), new Field("description"), new Field("required"), - new Field("metadata"), new Field("constraints"))); - Template templateTest = new Template("String", templateFieldsString); - has = templateManagement.hasTemplate(templateTest); - assertEquals(false, has); - } - -} diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/TemplateTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/TemplateTest.java index 4ffb4e28..02c5747b 100644 --- a/src/test/java/org/onap/clamp/clds/tosca/update/TemplateTest.java +++ b/src/test/java/org/onap/clamp/clds/tosca/update/TemplateTest.java @@ -35,11 +35,11 @@ public class TemplateTest extends TestCase { */ public void testCheckFields() { Template toTest = new Template("toTest"); - List fields = new ArrayList<>(Arrays.asList(new Field("type"), new Field("description"),new Field( + List templateFields = new ArrayList<>(Arrays.asList(new TemplateField("type"), new TemplateField("description"),new TemplateField( "enum"))); - toTest.setFields(fields); + toTest.setTemplateFields(templateFields); Template reference = new Template("toTest"); - reference.setFields(fields); + reference.setTemplateFields(templateFields); assertTrue(toTest.checkFields(reference)); } diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/ToscaConverterManagerTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/ToscaConverterManagerTest.java new file mode 100644 index 00000000..49384121 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/tosca/update/ToscaConverterManagerTest.java @@ -0,0 +1,205 @@ +/*- + * ============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 java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import junit.framework.TestCase; +import org.onap.clamp.clds.util.ResourceFileUtil; + +public class ToscaConverterManagerTest extends TestCase { + + /** + * Test the launch translation wit operational policies. + * + * @throws IOException In case of failure + * @throws UnknownComponentException In case of failure + */ + public void testLaunchTranslationTca() throws IOException, UnknownComponentException { + ToscaConverterManager toscaConverterManager = + new ToscaConverterManager( + ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap" + + ".policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0?" + + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString( + "clds/tosca_update/default-tosca-types.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); + assertNull(toscaConverterManager.getParseToJson()); + String componentName = "onap.policies.monitoring.cdap.tca.hi.lo.app"; + toscaConverterManager.startConversionToJson(componentName); + assertNotNull(toscaConverterManager.getParseToJson()); + } + + /** + * Test the launch translation wit operational policies. + * + * @throws IOException In case of failure + * @throws UnknownComponentException In case of failure + */ + public void testLaunchTranslationFrequencyLimiter() throws IOException, UnknownComponentException { + ToscaConverterManager toscaConverterManager = + new ToscaConverterManager( + ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap" + + ".policies.controlloop.guard.common.FrequencyLimiter/versions/1.0.0?" + + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString( + "clds/tosca_update/default-tosca-types.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); + assertNull(toscaConverterManager.getParseToJson()); + String componentName = "onap.policies.controlloop.guard.common.FrequencyLimiter"; + toscaConverterManager.startConversionToJson(componentName); + assertNotNull(toscaConverterManager.getParseToJson()); + } + + /** + * Test the launch translation wit operational policies. + * + * @throws IOException In case of failure + * @throws UnknownComponentException In case of failure + */ + public void testLaunchTranslationApex() throws IOException, UnknownComponentException { + ToscaConverterManager toscaConverterManager = + new ToscaConverterManager( + ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap" + + ".policies.controlloop.operational.common.Apex/versions/1.0.0?" + + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString( + "clds/tosca_update/default-tosca-types.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); + assertNull(toscaConverterManager.getParseToJson()); + String componentName = "onap.policies.controlloop.operational.common.Apex"; + toscaConverterManager.startConversionToJson(componentName); + assertNotNull(toscaConverterManager.getParseToJson()); + } + + /** + * Test the launch translation wit operational policies. + * + * @throws IOException In case of failure + * @throws UnknownComponentException In case of failure + */ + public void testLaunchTranslationDrools() throws IOException, UnknownComponentException { + ToscaConverterManager toscaConverterManager = + new ToscaConverterManager( + ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap" + + ".policies.controlloop.operational.common.Drools/versions/1.0.0?" + + "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString( + "clds/tosca_update/default-tosca-types.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); + assertNull(toscaConverterManager.getParseToJson()); + String componentName = "onap.policies.controlloop.operational.common.Drools"; + toscaConverterManager.startConversionToJson(componentName); + assertNotNull(toscaConverterManager.getParseToJson()); + } + + /** + * Test the launch translation. + * + * @throws IOException In case of failure + * @throws UnknownComponentException In case of failure + */ + public void testLaunchTranslation() throws IOException, UnknownComponentException { + ToscaConverterManager toscaConverterManager = + new ToscaConverterManager( + ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); + assertNull(toscaConverterManager.getParseToJson()); + String componentName = "onap.policies.controlloop.operational.common.Drools"; + toscaConverterManager.startConversionToJson(componentName); + assertNotNull(toscaConverterManager.getParseToJson()); + } + + /** + * Test addTemplate. + * + * @throws IOException In case of failure + */ + public void testAddTemplate() throws IOException { + ToscaConverterManager toscaConverterManager = + new ToscaConverterManager( + ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); + int count = toscaConverterManager.getTemplates().size(); + List templateFields = new ArrayList<>(Arrays.asList(new TemplateField("type"), new TemplateField("description"), + new TemplateField( + "required"), + new TemplateField("metadata"), new TemplateField("constraints"))); + toscaConverterManager.addTemplate("test", templateFields); + assertNotSame(count, toscaConverterManager.getTemplates().size()); + } + + /** + * test Remove template. + * + * @throws IOException In case of failure + */ + public void testRemoveTemplate() throws IOException { + ToscaConverterManager toscaConverterManager = + new ToscaConverterManager( + ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); + int count = toscaConverterManager.getTemplates().size(); + toscaConverterManager.removeTemplate("string"); + assertNotSame(count, toscaConverterManager.getTemplates().size()); + } + + /** + * Test update template. + * + * @throws IOException In case of failure + */ + public void testUpdateTemplate() throws IOException { + ToscaConverterManager toscaConverterManager = + new ToscaConverterManager( + ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); + int count = toscaConverterManager.getTemplates().get("integer").getTemplateFields().size(); + toscaConverterManager.updateTemplate("integer", new TemplateField("type"), false); + assertNotSame(count, toscaConverterManager.getTemplates().get("integer").getTemplateFields().size()); + } + + /** + * Test has template. + * + * @throws IOException In case of failure + */ + public void testHasTemplate() throws IOException { + ToscaConverterManager toscaConverterManager = + new ToscaConverterManager( + ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); + boolean has = true; + List templateFieldsString = + new ArrayList<>(Arrays.asList(new TemplateField("type"), new TemplateField("description"), new TemplateField("required"), + new TemplateField("metadata"), new TemplateField("constraints"))); + Template templateTest = new Template("String", templateFieldsString); + has = toscaConverterManager.hasTemplate(templateTest); + assertEquals(false, has); + } + +} diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/ToscaElementTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/ToscaElementTest.java new file mode 100644 index 00000000..7ffba4e0 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/tosca/update/ToscaElementTest.java @@ -0,0 +1,50 @@ +/*- + * ============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 java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import junit.framework.TestCase; +import org.onap.clamp.clds.util.ResourceFileUtil; + +public class ToscaElementTest extends TestCase { + + /** + * Test propertiesName. + * + * @throws IOException In case of failure + */ + public void testPropertiesNames() throws IOException { + ArrayList reference = new ArrayList<>(Arrays.asList("actor", "operation", "target", "payload")); + ToscaConverterManager toscaConverterManager = + new ToscaConverterManager( + ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); + ToscaElement toscaElement = toscaConverterManager.getComponents().get("onap.datatype.controlloop.Actor"); + assertEquals(reference, toscaElement.propertiesNames()); + } + +} diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java index fd215dd3..a57a35ea 100644 --- a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java +++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java @@ -27,7 +27,6 @@ package org.onap.clamp.loop; import static org.assertj.core.api.Assertions.assertThat; - import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -50,7 +49,7 @@ import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact; import org.onap.clamp.clds.sdc.controller.installer.CsarHandler; import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.clds.util.ResourceFileUtil; -import org.onap.clamp.loop.service.ServiceRepository; +import org.onap.clamp.loop.service.ServicesRepository; import org.onap.clamp.loop.template.LoopTemplate; import org.onap.clamp.loop.template.LoopTemplateLoopElementModel; import org.onap.clamp.loop.template.LoopTemplatesRepository; @@ -87,7 +86,7 @@ public class CsarInstallerItCase { private LoopTemplatesRepository loopTemplatesRepo; @Autowired - ServiceRepository serviceRepository; + ServicesRepository serviceRepository; @Autowired PolicyModelsRepository policyModelsRepository; -- cgit 1.2.3-korg