From 2dd4e997c1ccf5dab4dfb7665ce74c0fd1f13e49 Mon Sep 17 00:00:00 2001 From: sebdet Date: Wed, 4 Mar 2020 15:47:39 -0800 Subject: Rework tosca converter New code to convert the Policy Tosca Yaml to Json Schema for the Clamp UI Issue-ID: CLAMP-647 Signed-off-by: sebdet Change-Id: Id15ddedc1910f6a40bf6e407b34e343e00135571 --- .../clamp/clds/tosca/update/ArrayFieldTest.java | 3 +- .../clamp/clds/tosca/update/ComponentTest.java | 1 + .../clamp/clds/tosca/update/ConstraintTest.java | 3 +- .../onap/clamp/clds/tosca/update/PropertyTest.java | 2 + .../clds/tosca/update/TemplateManagementTest.java | 85 ++++++++++++++++++++++ .../PolicyEngineControllerTestItCase.java | 14 ++-- 6 files changed, 101 insertions(+), 7 deletions(-) (limited to 'src/test/java/org/onap') 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 abf65c366..c65c84a45 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 @@ -38,7 +38,8 @@ public class ArrayFieldTest extends TestCase { */ public void testDeploy() throws IOException { TemplateManagement templateManagement = new TemplateManagement(ResourceFileUtil.getResourceAsString( - "tosca/new-converter/sampleOperationalPoliciesEXTENTED.yaml"), + "tosca/new-converter/sampleOperationalPoliciesEXTENTED.yaml"),ResourceFileUtil.getResourceAsString( + "clds/tosca_update/defaultToscaTypes.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Actor"); Property property = component.getProperties().get("actor"); 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 index 0494ee11d..f5d2fe6ee 100644 --- a/src/test/java/org/onap/clamp/clds/tosca/update/ComponentTest.java +++ b/src/test/java/org/onap/clamp/clds/tosca/update/ComponentTest.java @@ -41,6 +41,7 @@ public class ComponentTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); 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 a71ea8ac4..6f1046ea9 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 @@ -33,6 +33,7 @@ public class ConstraintTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/constraints.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Operation"); @@ -41,7 +42,7 @@ public class ConstraintTest extends TestCase { } /** - * Test get value array. + * Test get value array. */ public void testGetValuesArray() { Property property = component.getProperties().get("timeout"); 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 cf183af81..5a9955999 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 @@ -42,6 +42,7 @@ public class PropertyTest extends TestCase { public void testParseArray() throws IOException { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPoliciesEXTENTED.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Actor"); Property property = component.getProperties().get("actor"); @@ -57,6 +58,7 @@ public class PropertyTest extends TestCase { public void testAddConstraintsAsJson() 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.properties")); Component component = templateManagement.getComponents().get("onap.datatype.controlloop.operation.Failure"); Property property = component.getProperties().get("category"); 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 index 8e411069c..4447a98cd 100644 --- a/src/test/java/org/onap/clamp/clds/tosca/update/TemplateManagementTest.java +++ b/src/test/java/org/onap/clamp/clds/tosca/update/TemplateManagementTest.java @@ -31,6 +31,86 @@ 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.properties")); + 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.properties")); + 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.properties")); + 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.properties")); + assertNull(templateManagement.getParseToJson()); + String componentName = "onap.policies.controlloop.operational.common.Drools"; + templateManagement.launchTranslation(componentName); + assertNotNull(templateManagement.getParseToJson()); + } + /** * Test the launch translation. * @@ -41,6 +121,7 @@ public class TemplateManagementTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); assertNull(templateManagement.getParseToJson()); String componentName = "onap.policies.controlloop.operational.common.Drools"; @@ -57,6 +138,7 @@ public class TemplateManagementTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); int count = templateManagement.getTemplates().size(); ArrayList templateFields = @@ -74,6 +156,7 @@ public class TemplateManagementTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); int count = templateManagement.getTemplates().size(); templateManagement.removeTemplate("string"); @@ -89,6 +172,7 @@ public class TemplateManagementTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); int count = templateManagement.getTemplates().get("integer").getFields().size(); templateManagement.updateTemplate("integer", "type", false); @@ -104,6 +188,7 @@ public class TemplateManagementTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); boolean has = true; ArrayList templateFieldsString = diff --git a/src/test/java/org/onap/clamp/policy/downloader/PolicyEngineControllerTestItCase.java b/src/test/java/org/onap/clamp/policy/downloader/PolicyEngineControllerTestItCase.java index 2cd301850..f08e86e8e 100644 --- a/src/test/java/org/onap/clamp/policy/downloader/PolicyEngineControllerTestItCase.java +++ b/src/test/java/org/onap/clamp/policy/downloader/PolicyEngineControllerTestItCase.java @@ -69,11 +69,15 @@ public class PolicyEngineControllerTestItCase { assertThat(firstExecution).isNotNull(); List policyModelsList = policyModelsRepository.findAll(); assertThat(policyModelsList.size()).isGreaterThanOrEqualTo(5); - assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.operational.Drools", null, "1.0.0")); - assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.operational.Apex", null, "1.0.0")); - assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.guard.FrequencyLimiter", null, "1.0.0")); - assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.guard.Blacklist", null, "1.0.0")); - assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.guard.MinMax", null, "2.0.0")); + assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.operational.common.Drools", + null, "1.0.0")); + assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.operational.common.Apex", + null, "1.0.0")); + assertThat(policyModelsList) + .contains(new PolicyModel("onap.policies.controlloop.guard.common.FrequencyLimiter", null, "1.0.0")); + assertThat(policyModelsList) + .contains(new PolicyModel("onap.policies.controlloop.guard.common.Blacklist", null, "1.0.0")); + assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.guard.common.MinMax", null, "2.0.0")); // Re-do it to check that there is no issue with duplicate key policyController.synchronizeAllPolicies(); -- cgit 1.2.3-korg