summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2021-03-22 18:55:46 +0100
committersebdet <sebastien.determe@intl.att.com>2021-04-01 16:53:14 +0200
commitee233569e74e4620cb35ce4e9c4320b30d108824 (patch)
tree5c0dbbbe575381d9696ae3f6cf841bea499c0254 /src/test/java/org/onap
parent1da36e7c13bc7efac7bdd8425cede0e69d3f1335 (diff)
Rework the backend to support PDP updates
Add new mem structure so that we do not need to parse the same Json for each policy/type + rework the camel flows so that we use the same code for loop and policies related calls Issue-ID: POLICY-2930 Issue-ID: POLICY-2931 Signed-off-by: sebdet <sebastien.determe@intl.att.com> Change-Id: I3c30c4f87cf669b40511472d518fe5ccc89f56f0
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r--src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java150
-rw-r--r--src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java12
2 files changed, 121 insertions, 41 deletions
diff --git a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java
index e6717418a..c7ada58cf 100644
--- a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java
+++ b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java
@@ -25,9 +25,14 @@ package org.onap.policy.clamp.policy.pdpgroup;
import static org.assertj.core.api.Assertions.assertThat;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.clamp.clds.util.JsonUtils;
+import org.onap.policy.clamp.clds.util.ResourceFileUtils;
import org.onap.policy.clamp.loop.template.PolicyModel;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroups;
@@ -41,6 +46,15 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
public class PdpGroupAnalyzerTest {
private static PdpGroups pdpGroups;
+ private static PdpGroup pdpGroup1;
+ private static PdpGroup pdpGroup2;
+ private static PdpGroup pdpGroup3;
+ private static PdpGroup pdpGroup4;
+
+ private static PdpSubGroup pdpSubgroupBad;
+ private static PdpSubGroup pdpSubgroup1;
+ private static PdpSubGroup pdpSubgroup2;
+ private static PdpSubGroup pdpSubgroup3;
/**
* This method preloads the pdpGroups for the tests.
@@ -49,7 +63,7 @@ public class PdpGroupAnalyzerTest {
public static void setupPdpGroup() {
// Create Pdp Groups
// Those that do not work first
- PdpSubGroup pdpSubgroupBad = new PdpSubGroup();
+ pdpSubgroupBad = new PdpSubGroup();
pdpSubgroupBad.setPdpType("subGroupBad");
pdpSubgroupBad.setSupportedPolicyTypes(Arrays.asList(new ToscaConceptIdentifier("org.onap.test", "2.0.0"),
new ToscaConceptIdentifier("org.onap.test.*", "1.0.0"),
@@ -58,50 +72,54 @@ public class PdpGroupAnalyzerTest {
new ToscaConceptIdentifier("org.onap.tes", "1.0.0"),
new ToscaConceptIdentifier("org.onap", "1.0.0")
));
- pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap", "1.0.0")));
- pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")));
- pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")));
- pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap.testos.new", "1.0.0")));
- pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap.*", "1.0.0")));
-
- PdpSubGroup pdpSubgroup1 = new PdpSubGroup();
+ pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap", "1.0.0"),
+ new ToscaConceptIdentifier("org.onap.testos", "2.0.0"),
+ new ToscaConceptIdentifier("org.onap.testos", "1.0.1"),
+ new ToscaConceptIdentifier("org.onap.testos.new", "1.0.0"),
+ new ToscaConceptIdentifier("org.onap.", "1.0.0")));
+ pdpSubgroupBad.setPdpInstances(Collections.emptyList());
+
+ pdpSubgroup1 = new PdpSubGroup();
pdpSubgroup1.setPdpType("subGroup1");
pdpSubgroup1.setSupportedPolicyTypes(
Arrays.asList(new ToscaConceptIdentifier("org.onap.*", "1.0.0")));
+ pdpSubgroup1.setPdpInstances(Collections.emptyList());
- PdpSubGroup pdpSubgroup2 = new PdpSubGroup();
+ pdpSubgroup2 = new PdpSubGroup();
pdpSubgroup2.setPdpType("subGroup2");
pdpSubgroup2.setSupportedPolicyTypes(Arrays.asList(new ToscaConceptIdentifier("org.onap.test", "1.0.0")));
pdpSubgroup2.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap.testos", "1.0.0")));
+ pdpSubgroup2.setPdpInstances(Collections.emptyList());
- PdpSubGroup pdpSubgroup3 = new PdpSubGroup();
+ pdpSubgroup3 = new PdpSubGroup();
pdpSubgroup3.setPdpType("subGroup3");
pdpSubgroup3.setSupportedPolicyTypes(Arrays.asList(new ToscaConceptIdentifier("org.onap.test*", "1.0.0")));
pdpSubgroup3.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")));
+ pdpSubgroup3.setPdpInstances(Collections.emptyList());
// Should match pdpSubgroup1
- PdpGroup pdpGroup1 = new PdpGroup();
+ pdpGroup1 = new PdpGroup();
pdpGroup1.setName("pdpGroup1");
pdpGroup1.setPdpGroupState(PdpState.ACTIVE);
pdpGroup1.setPdpSubgroups(Arrays.asList(pdpSubgroup1, pdpSubgroupBad));
// Should match pdpSubgroup1, pdpSubgroup2, pdpSubgroup3
// Should match also for the policy (pdpSubgroup2)
- PdpGroup pdpGroup2 = new PdpGroup();
+ pdpGroup2 = new PdpGroup();
pdpGroup2.setName("pdpGroup2");
pdpGroup2.setPdpGroupState(PdpState.ACTIVE);
pdpGroup2.setPdpSubgroups(Arrays.asList(pdpSubgroup1, pdpSubgroup2, pdpSubgroup3, pdpSubgroupBad));
/// Should not match
- PdpGroup pdpGroup3 = new PdpGroup();
+ pdpGroup3 = new PdpGroup();
pdpGroup3.setName("pdpGroup3");
pdpGroup3.setPdpGroupState(PdpState.ACTIVE);
pdpGroup3.setPdpSubgroups(Arrays.asList(pdpSubgroupBad));
// Should not match
- PdpGroup pdpGroup4 = new PdpGroup();
+ pdpGroup4 = new PdpGroup();
pdpGroup4.setName("pdpGroup4");
- pdpGroup4.setPdpGroupState(PdpState.PASSIVE);
+ pdpGroup4.setPdpGroupState(PdpState.TERMINATED);
pdpGroup4.setPdpSubgroups(Arrays.asList(pdpSubgroup1));
pdpGroups = new PdpGroups();
@@ -109,8 +127,67 @@ public class PdpGroupAnalyzerTest {
}
@Test
- public void testUpdatePdpGroupOfPolicyModels() {
- // Create policyModel
+ public void testStructuresConstruction() {
+ PdpGroupsAnalyzer pdpGroupsAnalyzer = new PdpGroupsAnalyzer(pdpGroups);
+ assertThat(pdpGroupsAnalyzer).isNotNull();
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()).hasSize(6);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0"))).hasSize(3);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup1").getPdpSubgroups().size())
+ .isEqualTo(1);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup1").getPdpSubgroups())
+ .contains(pdpSubgroupBad);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup2").getPdpSubgroups().size())
+ .isEqualTo(2);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup2").getPdpSubgroups())
+ .contains(pdpSubgroup3);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup2").getPdpSubgroups())
+ .contains(pdpSubgroupBad);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup3").getPdpSubgroups().size())
+ .isEqualTo(1);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup3").getPdpSubgroups())
+ .contains(pdpSubgroupBad);
+
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.0"))).hasSize(1);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.0")).get("pdpGroup2").getPdpSubgroups().size())
+ .isEqualTo(1);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.0")).get("pdpGroup2").getPdpSubgroups())
+ .contains(pdpSubgroup2);
+
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1"))).hasSize(3);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup1").getPdpSubgroups().size())
+ .isEqualTo(1);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup1").getPdpSubgroups())
+ .contains(pdpSubgroupBad);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup2").getPdpSubgroups().size())
+ .isEqualTo(1);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup2").getPdpSubgroups())
+ .contains(pdpSubgroupBad);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup3").getPdpSubgroups().size())
+ .isEqualTo(1);
+ assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()
+ .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup3").getPdpSubgroups())
+ .contains(pdpSubgroupBad);
+ }
+
+ @Test
+ public void testGetSupportedPdpGroupsForPolicy() throws IOException {
PolicyModel policyModel = new PolicyModel();
policyModel.setCreatedBy("user");
policyModel.setPolicyAcronym("TEST");
@@ -118,24 +195,37 @@ public class PdpGroupAnalyzerTest {
policyModel.setPolicyModelType("org.onap.test");
policyModel.setUpdatedBy("user");
policyModel.setVersion("1.0.0");
- PdpGroupsAnalyzer.updatePdpGroupOfPolicyModels(Arrays.asList(policyModel), pdpGroups);
- assertThat(policyModel.getPolicyPdpGroup().toString()).isEqualTo(
- "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},"
- + "{\"pdpGroup2\":[\"subGroup1\",\"subGroup2\",\"subGroup3\"]}]}");
- }
+ PdpGroupsAnalyzer pdpGroupsAnalyzer = new PdpGroupsAnalyzer(pdpGroups);
+ assertThat(pdpGroupsAnalyzer).isNotNull();
- @Test
- public void testGetPdpGroupDeploymentsOfOnePolicy() {
assertThat(
- PdpGroupsAnalyzer.getPdpGroupDeploymentOfOnePolicy(pdpGroups, "org.onap.testos", "1.0.0").toString())
- .isEqualTo("{\"pdpGroupInfo\":{\"pdpGroup\":\"pdpGroup2\",\"pdpSubGroup\":\"subGroup2\"}}");
- }
+ JsonUtils.GSON.toJson(pdpGroupsAnalyzer.getPdpGroupsForPolicy("org.onap.testos", "2.0.0")))
+ .isEqualTo(ResourceFileUtils.getResourceAsString("example/policy/pdp-deployment-testos-2_0_0.json"));
+
+ assertThat(
+ JsonUtils.GSON.toJson(pdpGroupsAnalyzer.getPdpGroupsForPolicy("org.onap.testos", "1.0.0")))
+ .isEqualTo(ResourceFileUtils.getResourceAsString("example/policy/pdp-deployment-testos-1_0_0.json"));
- @Test
- public void testGetPdpGroupDeploymentsOfOnePolicyNull() {
assertThat(
- PdpGroupsAnalyzer.getPdpGroupDeploymentOfOnePolicy(pdpGroups, "org.onap.DoNotExist", "1.0.0"))
+ pdpGroupsAnalyzer.getPdpGroupsForPolicy("org.onap.donotexist", "1.0.0"))
.isNull();
}
+
+ @Test
+ public void testUpdatePdpGroupOfPolicyModels() {
+ // Create policyModel
+ PolicyModel policyModel = new PolicyModel();
+ policyModel.setCreatedBy("user");
+ policyModel.setPolicyAcronym("TEST");
+ policyModel.setPolicyModelTosca("yaml");
+ policyModel.setPolicyModelType("org.onap.test");
+ policyModel.setUpdatedBy("user");
+ policyModel.setVersion("1.0.0");
+ PdpGroupsAnalyzer.updatePdpGroupOfPolicyModels(Arrays.asList(policyModel), pdpGroups);
+
+ assertThat(policyModel.getPolicyPdpGroup()).hasToString(
+ "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},"
+ + "{\"pdpGroup2\":[\"subGroup1\",\"subGroup2\",\"subGroup3\"]}]}");
+ }
}
diff --git a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java
index 7b8cbd824..be7a9d674 100644
--- a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java
+++ b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java
@@ -93,20 +93,10 @@ public class PoliciesPdpMergerTest {
}
@Test
- public void testUpdatePdpGroupOfPolicyModels() throws IOException {
+ public void testMergePoliciesAndPdpGroupStates() throws IOException {
JSONAssert.assertEquals(ResourceFileUtils.getResourceAsString("example/policy/policy-merger.json"),
PoliciesPdpMerger.mergePoliciesAndPdpGroupStates(
ResourceFileUtils.getResourceAsString("http-cache/example/policy/api/v1/policies/.file"),
pdpGroupsJson).toString(), true);
}
-
- @Test
- public void testRemovePdpStatesOnePolicy() throws IOException {
- JsonObject policiesList = PoliciesPdpMerger.removePdpStatesOnePolicy(JsonUtils.GSON.fromJson(
- ResourceFileUtils.getResourceAsString("example/policy/single-policy-enriched.json"), JsonObject.class));
-
- assertThat(policiesList.get(PdpGroupsAnalyzer.ASSIGNED_PDP_GROUPS_INFO)).isNull();
- assertThat(policiesList.get(PdpGroupsAnalyzer.SUPPORTED_PDP_GROUPS_INFO)).isNull();
- assertThat(policiesList.size()).isEqualTo(6);
- }
}