diff options
Diffstat (limited to 'src/test/java/org')
7 files changed, 124 insertions, 23 deletions
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..a99d4ab56 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,8 +38,9 @@ public class ArrayFieldTest extends TestCase { */ public void testDeploy() throws IOException { TemplateManagement templateManagement = new TemplateManagement(ResourceFileUtil.getResourceAsString( - "tosca/new-converter/sampleOperationalPoliciesEXTENTED.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); + "tosca/new-converter/sampleOperationalPoliciesEXTENTED.yaml"),ResourceFileUtil.getResourceAsString( + "clds/tosca_update/defaultToscaTypes.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Actor"); Property property = component.getProperties().get("actor"); ArrayField arrayParser = new ArrayField((ArrayList<Object>) property.getItems().get("default")); 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..565547e4b 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,7 +41,8 @@ public class ComponentTest extends TestCase { TemplateManagement templateManagement =
new TemplateManagement(
ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
- ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties"));
+ 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 a71ea8ac4..a4d329e29 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,7 +33,8 @@ public class ConstraintTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/constraints.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); 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..62def32b8 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,7 +42,8 @@ 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/templates.properties")); + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Actor"); Property property = component.getProperties().get("actor"); JsonArray toTest = property.parseArray((ArrayList<Object>) property.getItems().get("default")); @@ -57,7 +58,8 @@ 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/templates.properties")); + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.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"); 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..aaa549386 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 @@ -26,12 +26,93 @@ 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 @@ -41,7 +122,8 @@ public class TemplateManagementTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); + 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); @@ -57,10 +139,13 @@ public class TemplateManagementTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); int count = templateManagement.getTemplates().size(); - ArrayList<String> templateFields = - new ArrayList<>(Arrays.asList("type", "description", "required", "metadata", "constraints")); + List<Field> 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()); } @@ -74,7 +159,8 @@ public class TemplateManagementTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); + 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()); @@ -89,9 +175,10 @@ public class TemplateManagementTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); + 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", "type", false); + templateManagement.updateTemplate("integer", new Field("type"), false); assertNotSame(count, templateManagement.getTemplates().get("integer").getFields().size()); } @@ -104,10 +191,12 @@ public class TemplateManagementTest extends TestCase { TemplateManagement templateManagement = new TemplateManagement( ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"), - ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.properties")); + ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"), + ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json")); boolean has = true; - ArrayList<String> templateFieldsString = - new ArrayList<>(Arrays.asList("type", "description", "required", "metadata", "constraints")); + List<Field> 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 ebc119f0d..4ffb4e28e 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 @@ -25,6 +25,7 @@ package org.onap.clamp.clds.tosca.update; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import junit.framework.TestCase; public class TemplateTest extends TestCase { @@ -34,7 +35,8 @@ public class TemplateTest extends TestCase { */ public void testCheckFields() { Template toTest = new Template("toTest"); - ArrayList<String> fields = new ArrayList<>(Arrays.asList("type", "description", "enum")); + List<Field> fields = new ArrayList<>(Arrays.asList(new Field("type"), new Field("description"),new Field( + "enum"))); toTest.setFields(fields); Template reference = new Template("toTest"); reference.setFields(fields); 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..03b2e506d 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,16 @@ public class PolicyEngineControllerTestItCase { assertThat(firstExecution).isNotNull(); List<PolicyModel> 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(); |