diff options
author | sebdet <sebastien.determe@intl.att.com> | 2020-02-26 15:47:30 -0800 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2020-02-27 06:17:02 -0800 |
commit | d2a4df0b62b6a32c42bac45b4bee344016faa8fb (patch) | |
tree | a4d49be5501c1016de3af41f7e8935cd5187ec85 /src/test/java | |
parent | c11160ecfdce03091917e2728f80848f4d8feb95 (diff) |
Add Create loop dialog
Add create loop dialog and backend part associated (this is based on this PR https://gerrit.onap.org/r/c/clamp/+/102156)
Issue-ID: CLAMP-587
Change-Id: I58524bc2d5bfbf5ca5a3acf5c59823df06fd4cd9
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/test/java')
10 files changed, 58 insertions, 36 deletions
diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java index 63209e9f9..2ccecf3e8 100644 --- a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java +++ b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java @@ -70,7 +70,7 @@ public class ClampGraphBuilderTest { null); OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new Loop(), new JsonObject(), - new PolicyModel("org.onap.opolicy", null, "1.0.0", "opolicy1")); + new PolicyModel("org.onap.opolicy", null, "1.0.0", "opolicy1"), null); final Set<OperationalPolicy> opPolicies = Set.of(opPolicy); final Set<MicroServicePolicy> microServices = Set.of(ms1, ms2); diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java index aad11adb2..7b83a4c35 100644 --- a/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java +++ b/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java @@ -24,10 +24,8 @@ package org.onap.clamp.clds.util.drawing; import static org.assertj.core.api.Assertions.assertThat; - import com.google.gson.JsonObject; import java.io.IOException; -import java.util.HashSet; import javax.xml.parsers.ParserConfigurationException; import org.junit.Test; import org.onap.clamp.loop.Loop; @@ -41,12 +39,12 @@ public class SvgLoopGeneratorTest { MicroServicePolicy ms1 = new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0", "short.ms1"), false, - new HashSet<Loop>()); + null); MicroServicePolicy ms2 = new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0", "short.ms2"), - false, new HashSet<Loop>()); + false, null); OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new Loop(), new JsonObject(), - new PolicyModel("org.onap.opolicy", null, "1.0.0", "short.OperationalPolicy")); + new PolicyModel("org.onap.opolicy", null, "1.0.0", "short.OperationalPolicy"), null); Loop loop = new Loop(); loop.addMicroServicePolicy(ms1); loop.addMicroServicePolicy(ms2); diff --git a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java index 57e99a3da..50e2e8d39 100644 --- a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java +++ b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java @@ -28,7 +28,6 @@ import static org.assertj.core.api.Assertions.assertThat; import com.google.gson.Gson; import com.google.gson.JsonObject; import java.io.IOException; -import java.util.HashSet; import java.util.List; import org.apache.camel.Exchange; import org.apache.camel.Message; @@ -55,7 +54,7 @@ public class DcaeComponentTest { MicroServicePolicy microServicePolicy = new MicroServicePolicy("configPolicyTest", new PolicyModel("policy1", "tosca_definitions_version: tosca_simple_yaml_1_0_0","1.0.0"), true, - new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), new HashSet<>()); + new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), null); microServicePolicy.setConfigurationsJson(new Gson().fromJson("{\"param1\":\"value1\"}", JsonObject.class)); loopTest.addMicroServicePolicy(microServicePolicy); diff --git a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java index 4fd78d18a..3c2ce17ed 100644 --- a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java +++ b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java @@ -29,7 +29,6 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import java.io.IOException; -import java.util.HashSet; import java.util.Set; import javax.transaction.Transactional; import org.apache.camel.CamelContext; @@ -298,7 +297,7 @@ public class DeployFlowTestItCase { policyModelsService.saveOrUpdatePolicyModel(policyModel); MicroServicePolicy microService = new MicroServicePolicy(name, policyModel, shared, - gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>()); + gson.fromJson(jsonRepresentation, JsonObject.class), null); microService.setConfigurationsJson(new Gson().fromJson(jsonProperties, JsonObject.class)); return microService; diff --git a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java index fa4909cb4..acde66d9a 100644 --- a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java +++ b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java @@ -31,7 +31,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import java.time.Instant; -import java.util.HashSet; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.clamp.clds.Application; @@ -91,7 +90,7 @@ public class LoopRepositoriesItCase { } private OperationalPolicy getOperationalPolicy(String configJson, String name, PolicyModel policyModel) { - return new OperationalPolicy(name, null, new Gson().fromJson(configJson, JsonObject.class), policyModel); + return new OperationalPolicy(name, null, new Gson().fromJson(configJson, JsonObject.class), policyModel, null); } private LoopElementModel getLoopElementModel(String yaml, String name, String policyType, String createdBy, @@ -131,7 +130,7 @@ public class LoopRepositoriesItCase { private MicroServicePolicy getMicroServicePolicy(String name, String jsonRepresentation, String jsonProperties, boolean shared, PolicyModel policyModel) { MicroServicePolicy microService = new MicroServicePolicy(name, policyModel, shared, - gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>()); + gson.fromJson(jsonRepresentation, JsonObject.class), null); microService.setConfigurationsJson(new Gson().fromJson(jsonProperties, JsonObject.class)); return microService; } diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java index 5eca90c7f..849ca5cfe 100644 --- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java +++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java @@ -46,7 +46,6 @@ import org.onap.clamp.policy.operational.OperationalPolicy; import org.onap.clamp.policy.operational.OperationalPolicyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.Commit; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -102,7 +101,7 @@ public class LoopServiceTestItCase { // given saveTestLoopToDb(); OperationalPolicy operationalPolicy = new OperationalPolicy("policyName", null, - JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null); + JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null); // when Loop actualLoop = loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, @@ -233,11 +232,11 @@ public class LoopServiceTestItCase { JsonObject newJsonConfiguration = JsonUtils.GSON.fromJson("{}", JsonObject.class); OperationalPolicy firstOperationalPolicy = new OperationalPolicy("firstPolicyName", null, - JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null); + JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null); loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy)); OperationalPolicy secondOperationalPolicy = new OperationalPolicy("secondPolicyName", null, - newJsonConfiguration, null); + newJsonConfiguration, null, null); // when firstOperationalPolicy.setConfigurationsJson(newJsonConfiguration); @@ -264,11 +263,11 @@ public class LoopServiceTestItCase { saveTestLoopToDb(); OperationalPolicy firstOperationalPolicy = new OperationalPolicy("firstPolicyName", null, - JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null); + JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null); loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy)); OperationalPolicy secondOperationalPolicy = new OperationalPolicy("policyName", null, - JsonUtils.GSON.fromJson("{}", JsonObject.class), null); + JsonUtils.GSON.fromJson("{}", JsonObject.class), null, null); // when Loop actualLoop = loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, @@ -320,7 +319,7 @@ public class LoopServiceTestItCase { loop = loopService.saveOrUpdateLoop(loop); // Add op policy OperationalPolicy operationalPolicy = new OperationalPolicy("opPolicy", null, - JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null); + JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null); loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(operationalPolicy)); PolicyModel policyModel = new PolicyModel("org.policies.microPolicy", diff --git a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java index a2a4536ff..34d524a6d 100644 --- a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java +++ b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java @@ -33,7 +33,6 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import java.io.IOException; -import java.util.HashSet; import java.util.Random; import org.junit.Test; import org.onap.clamp.clds.util.JsonUtils; @@ -55,7 +54,7 @@ public class LoopToJsonTest { private OperationalPolicy getOperationalPolicy(String configJson, String name) { return new OperationalPolicy(name, null, gson.fromJson(configJson, JsonObject.class), - getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1")); + getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1"), null); } private Loop getLoop(String name, String svgRepresentation, String blueprint, String globalPropertiesJson, @@ -73,7 +72,7 @@ public class LoopToJsonTest { String policyTosca, String jsonProperties, boolean shared) { MicroServicePolicy microService = new MicroServicePolicy(name, new PolicyModel(modelType, policyTosca, "1.0.0"), shared, - gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>()); + gson.fromJson(jsonRepresentation, JsonObject.class), null); microService.setConfigurationsJson(new Gson().fromJson(jsonProperties, JsonObject.class)); return microService; } @@ -106,6 +105,10 @@ public class LoopToJsonTest { return log; } + /** + * This tests a GSON encode/decode. + * @throws IOException In case of failure + */ @Test public void loopGsonTest() throws IOException { Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}", @@ -146,6 +149,11 @@ public class LoopToJsonTest { assertThat(loopTestDeserialized.getLoopTemplate()).isEqualTo(loopTemplate); } + /** + * This tests the service object GSON encode/decode. + * + * @throws IOException In case of issues + */ @Test public void loopServiceTest() throws IOException { Loop loopTest2 = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}", @@ -166,6 +174,11 @@ public class LoopToJsonTest { "blueprint", "components"); } + /** + * This tests the GSON encode/decode of pdpGroup. + * + * @throws IOException In case of issues + */ @Test public void createPoliciesPayloadPdpGroupTest() throws IOException { Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}", diff --git a/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java b/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java index f8aadbad5..80545c112 100644 --- a/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java +++ b/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java @@ -25,6 +25,7 @@ package org.onap.clamp.loop; import static org.assertj.core.api.Assertions.assertThat; +import com.google.gson.JsonObject; import java.util.LinkedList; import java.util.List; import java.util.SortedSet; @@ -46,8 +47,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import com.google.gson.JsonObject; - @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) public class PolicyModelServiceItCase { @@ -68,7 +67,7 @@ public class PolicyModelServiceItCase { private static final String POLICY_MODEL_TYPE_2_VERSION_2 = "2.0.0"; private PolicyModel getPolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym, - String policyVariant, String createdBy) { + String policyVariant, String createdBy) { PolicyModel policyModel = new PolicyModel(); policyModel.setCreatedBy(createdBy); policyModel.setPolicyAcronym(policyAcronym); @@ -110,6 +109,9 @@ public class PolicyModelServiceItCase { .isEqualToIgnoringGivenFields(policyModel, "createdDate", "updatedDate", "createdBy", "updatedBy"); } + /** + * This tests a getAllPolicyModelTypes get. + */ @Test @Transactional public void shouldReturnAllPolicyModelTypes() { @@ -125,6 +127,9 @@ public class PolicyModelServiceItCase { assertThat(policyModelTypesList).contains(policyModel1.getPolicyModelType(), policyModel2.getPolicyModelType()); } + /** + * This tests a getAllPolicyModels get. + */ @Test @Transactional public void shouldReturnAllPolicyModels() { @@ -138,6 +143,9 @@ public class PolicyModelServiceItCase { assertThat(policyModelsService.getAllPolicyModels()).contains(policyModel1, policyModel2); } + /** + * This tests a getAllPolicyModelsByType get. + */ @Test @Transactional public void shouldReturnAllModelsByType() { @@ -152,6 +160,9 @@ public class PolicyModelServiceItCase { policyModel2); } + /** + * This tests the sorting of policyModel. + */ @Test @Transactional public void shouldReturnSortedSet() { @@ -167,14 +178,17 @@ public class PolicyModelServiceItCase { SortedSet<PolicyModel> sortedSet = new TreeSet<>(); policyModelsService.getAllPolicyModels().forEach(sortedSet::add); - List<PolicyModel> listToCheck = sortedSet.stream().filter( - policy -> policy.equals(policyModel3) || policy.equals(policyModel2) || policy.equals(policyModel1)) - .collect(Collectors.toList()); + List<PolicyModel> listToCheck = sortedSet.stream() + .filter(policy -> policy.equals(policyModel3) || policy.equals(policyModel2) + || policy.equals(policyModel1)).collect(Collectors.toList()); assertThat(listToCheck.get(0)).isEqualByComparingTo(policyModel2); assertThat(listToCheck.get(1)).isEqualByComparingTo(policyModel1); assertThat(listToCheck.get(2)).isEqualByComparingTo(policyModel3); } + /** + * This tests the pdpgroup GSON encode/decode and saving. + */ @Test @Transactional public void shouldAddPdpGroupInfo() { @@ -229,12 +243,14 @@ public class PolicyModelServiceItCase { policyModelsService.updatePdpGroupInfo(pdpGroupList); JsonObject res1 = policyModelsService.getPolicyModel("org.onap.testos", "1.0.0").getPolicyPdpGroup(); - String expectedRes1 = "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},{\"pdpGroup2\":[\"subGroup1\"]}]}"; + String expectedRes1 = + "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},{\"pdpGroup2\":[\"subGroup1\"]}]}"; JsonObject expectedJson1 = JsonUtils.GSON.fromJson(expectedRes1, JsonObject.class); assertThat(res1).isEqualTo(expectedJson1); JsonObject res2 = policyModelsService.getPolicyModel("org.onap.testos2", "2.0.0").getPolicyPdpGroup(); - String expectedRes2 = "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},{\"pdpGroup2\":[\"subGroup1\",\"subGroup2\"]}]}"; + String expectedRes2 = + "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},{\"pdpGroup2\":[\"subGroup1\",\"subGroup2\"]}]}"; JsonObject expectedJson2 = JsonUtils.GSON.fromJson(expectedRes2, JsonObject.class); assertThat(res2).isEqualTo(expectedJson2); diff --git a/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java b/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java index 3911494f4..ea1218206 100644 --- a/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java +++ b/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java @@ -25,7 +25,6 @@ package org.onap.clamp.policy.microservice; import com.google.gson.JsonObject; import java.io.IOException; -import java.util.HashSet; import org.junit.Test; import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.clds.util.ResourceFileUtil; @@ -38,7 +37,7 @@ public class MicroServicePayloadTest { public void testPayloadConstruction() throws IOException { MicroServicePolicy policy = new MicroServicePolicy("testPolicy", new PolicyModel( "onap.policies.monitoring.cdap.tca.hi.lo.app", - ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml"),"1.0.0"), false, new HashSet<>()); + ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml"),"1.0.0"), false, null); policy.setConfigurationsJson(JsonUtils.GSON.fromJson( ResourceFileUtil.getResourceAsString("tosca/micro-service-policy-properties.json"), JsonObject.class)); JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/micro-service-policy-payload.json"), diff --git a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java index f42bbc1c0..bdc7e80de 100644 --- a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java +++ b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java @@ -41,7 +41,7 @@ public class OperationalPolicyPayloadTest { public void testOperationalPolicyPayloadConstruction() throws IOException { JsonObject jsonConfig = new GsonBuilder().create().fromJson( ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class); - OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null); + OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null); assertThat(policy.createPolicyPayloadYaml()) .isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.yaml")); @@ -63,7 +63,7 @@ public class OperationalPolicyPayloadTest { JsonObject jsonConfig = new GsonBuilder().create().fromJson( ResourceFileUtil.getResourceAsString("tosca/operational-policy-no-guard-properties.json"), JsonObject.class); - OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null); + OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null); Map<String, String> guardsMap = policy.createGuardPolicyPayloads(); assertThat(guardsMap).isEmpty(); assertThat(guardsMap.entrySet()).isEmpty(); @@ -73,7 +73,7 @@ public class OperationalPolicyPayloadTest { public void testGuardPolicyPayloadConstruction() throws IOException { JsonObject jsonConfig = new GsonBuilder().create().fromJson( ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class); - OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null); + OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null); Map<String, String> guardsMap = policy.createGuardPolicyPayloads(); |