aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/policy/clamp/loop/PolicyModelServiceItCase.java58
-rw-r--r--src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java130
-rw-r--r--src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupTest.java86
-rw-r--r--src/test/java/org/onap/policy/clamp/policy/pdpgroup/PolicyModelKeyTest.java55
4 files changed, 160 insertions, 169 deletions
diff --git a/src/test/java/org/onap/policy/clamp/loop/PolicyModelServiceItCase.java b/src/test/java/org/onap/policy/clamp/loop/PolicyModelServiceItCase.java
index e7df80cd8..a98291be0 100644
--- a/src/test/java/org/onap/policy/clamp/loop/PolicyModelServiceItCase.java
+++ b/src/test/java/org/onap/policy/clamp/loop/PolicyModelServiceItCase.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -43,9 +43,11 @@ import org.onap.policy.clamp.loop.template.PolicyModel;
import org.onap.policy.clamp.loop.template.PolicyModelId;
import org.onap.policy.clamp.loop.template.PolicyModelsRepository;
import org.onap.policy.clamp.loop.template.PolicyModelsService;
-import org.onap.policy.clamp.policy.pdpgroup.PdpGroup;
-import org.onap.policy.clamp.policy.pdpgroup.PdpSubgroup;
-import org.onap.policy.clamp.policy.pdpgroup.PolicyModelKey;
+import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpGroups;
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;
+import org.onap.policy.models.pdp.enums.PdpState;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@@ -242,54 +244,54 @@ public class PolicyModelServiceItCase {
@Test
@Transactional
public void shouldAddPdpGroupInfo() {
- PolicyModel policyModel1 = getPolicyModel(POLICY_MODEL_TYPE_1, "yaml",
- POLICY_MODEL_TYPE_1_VERSION_1, "TEST", "VARIANT", "user");
- policyModelsService.saveOrUpdatePolicyModel(policyModel1);
- PolicyModel policyModel2 = getPolicyModel(POLICY_MODEL_TYPE_2, "yaml",
- POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user");
- policyModelsService.saveOrUpdatePolicyModel(policyModel2);
- PolicyModel policyModel3 = getPolicyModel(POLICY_MODEL_TYPE_3, "yaml",
- POLICY_MODEL_TYPE_3_VERSION_1, "TEST", "VARIANT", "user");
- policyModelsService.saveOrUpdatePolicyModel(policyModel3);
+ policyModelsService.saveOrUpdatePolicyModel(getPolicyModel(POLICY_MODEL_TYPE_1, "yaml",
+ POLICY_MODEL_TYPE_1_VERSION_1, "TEST", "VARIANT", "user"));
+ policyModelsService.saveOrUpdatePolicyModel(getPolicyModel(POLICY_MODEL_TYPE_2, "yaml",
+ POLICY_MODEL_TYPE_2_VERSION_2, "TEST", "VARIANT", "user"));
+ policyModelsService.saveOrUpdatePolicyModel(getPolicyModel(POLICY_MODEL_TYPE_3, "yaml",
+ POLICY_MODEL_TYPE_3_VERSION_1, "TEST", "VARIANT", "user"));
- PolicyModelKey type1 = new PolicyModelKey("org.onap.testos", "1.0.0");
- PolicyModelKey type2 = new PolicyModelKey("org.onap.testos2", "2.0.0");
+ ToscaPolicyTypeIdentifier type1 = new ToscaPolicyTypeIdentifier("org.onap.testos", "1.0.0");
+ ToscaPolicyTypeIdentifier type2 = new ToscaPolicyTypeIdentifier("org.onap.testos2", "2.0.0");
- PdpSubgroup pdpSubgroup1 = new PdpSubgroup();
+ PdpSubGroup pdpSubgroup1 = new PdpSubGroup();
pdpSubgroup1.setPdpType("subGroup1");
- List<PolicyModelKey> pdpTypeList = new LinkedList<PolicyModelKey>();
+ List<ToscaPolicyTypeIdentifier> pdpTypeList = new LinkedList<>();
pdpTypeList.add(type1);
pdpTypeList.add(type2);
pdpSubgroup1.setSupportedPolicyTypes(pdpTypeList);
- PolicyModelKey type3 = new PolicyModelKey("org.onap.testos3", "2.0.0");
- PdpSubgroup pdpSubgroup2 = new PdpSubgroup();
+ ToscaPolicyTypeIdentifier type3 = new ToscaPolicyTypeIdentifier("org.onap.testos3", "2.0.0");
+ PdpSubGroup pdpSubgroup2 = new PdpSubGroup();
pdpSubgroup2.setPdpType("subGroup2");
- List<PolicyModelKey> pdpTypeList2 = new LinkedList<PolicyModelKey>();
+ List<ToscaPolicyTypeIdentifier> pdpTypeList2 = new LinkedList<>();
pdpTypeList2.add(type2);
pdpTypeList2.add(type3);
pdpSubgroup2.setSupportedPolicyTypes(pdpTypeList2);
- List<PdpSubgroup> pdpSubgroupList = new LinkedList<PdpSubgroup>();
+ List<PdpSubGroup> pdpSubgroupList = new LinkedList<>();
pdpSubgroupList.add(pdpSubgroup1);
PdpGroup pdpGroup1 = new PdpGroup();
pdpGroup1.setName("pdpGroup1");
- pdpGroup1.setPdpGroupState("ACTIVE");
+ pdpGroup1.setPdpGroupState(PdpState.ACTIVE);
pdpGroup1.setPdpSubgroups(pdpSubgroupList);
- List<PdpSubgroup> pdpSubgroupList2 = new LinkedList<PdpSubgroup>();
+ List<PdpSubGroup> pdpSubgroupList2 = new LinkedList<>();
pdpSubgroupList2.add(pdpSubgroup1);
pdpSubgroupList2.add(pdpSubgroup2);
PdpGroup pdpGroup2 = new PdpGroup();
pdpGroup2.setName("pdpGroup2");
- pdpGroup2.setPdpGroupState("ACTIVE");
+ pdpGroup2.setPdpGroupState(PdpState.ACTIVE);
pdpGroup2.setPdpSubgroups(pdpSubgroupList2);
- List<PdpGroup> pdpGroupList = new LinkedList<PdpGroup>();
- pdpGroupList.add(pdpGroup1);
- pdpGroupList.add(pdpGroup2);
- policyModelsService.updatePdpGroupInfo(pdpGroupList);
+ List<PdpGroup> pdpGroupsList = new LinkedList<>();
+ pdpGroupsList.add(pdpGroup1);
+ pdpGroupsList.add(pdpGroup2);
+
+ PdpGroups pdpGroups = new PdpGroups();
+ pdpGroups.setGroups(pdpGroupsList);
+ policyModelsService.updatePdpGroupInfo(pdpGroups);
JsonObject res1 =
policyModelsService.getPolicyModel("org.onap.testos", "1.0.0").getPolicyPdpGroup();
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
new file mode 100644
index 000000000..1af048da5
--- /dev/null
+++ b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java
@@ -0,0 +1,130 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2021 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.policy.clamp.policy.pdpgroup;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import javax.transaction.Transactional;
+import org.junit.Test;
+import org.onap.policy.clamp.clds.util.JsonUtils;
+import org.onap.policy.clamp.loop.template.PolicyModel;
+import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpGroups;
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;
+import org.onap.policy.models.pdp.enums.PdpState;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+
+/**
+ * This test class validates the PdpGroupAnalyzer class.
+ */
+public class PdpGroupAnalyzerTest {
+
+ private PolicyModel createPolicyModel(String policyType, String policyModelTosca, String version,
+ String policyAcronym, String policyVariant, String createdBy) {
+ PolicyModel policyModel = new PolicyModel();
+ policyModel.setCreatedBy(createdBy);
+ policyModel.setPolicyAcronym(policyAcronym);
+ policyModel.setPolicyModelTosca(policyModelTosca);
+ policyModel.setPolicyModelType(policyType);
+ policyModel.setUpdatedBy(createdBy);
+ policyModel.setVersion(version);
+ return policyModel;
+ }
+
+ /**
+ * This tests the pdpgroup GSON encode/decode and saving.
+ */
+ @Test
+ @Transactional
+ public void testUpdatePdpGroup() {
+ // 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");
+
+ // Create Pdp Groups
+ // Those that do not work first
+ PdpSubGroup pdpSubgroupBad = new PdpSubGroup();
+ pdpSubgroupBad.setPdpType("subGroupBad");
+ pdpSubgroupBad.setSupportedPolicyTypes(Arrays.asList(new ToscaPolicyTypeIdentifier("org.onap.test", "2.0.0"),
+ new ToscaPolicyTypeIdentifier("org.onap.test.*", "1.0.0"),
+ new ToscaPolicyTypeIdentifier("org.onip.testos", "1.0.0"),
+ new ToscaPolicyTypeIdentifier("org.onap.testos3", "2.0.0"),
+ new ToscaPolicyTypeIdentifier("org.onap.tes", "1.0.0"),
+ new ToscaPolicyTypeIdentifier("org.onap", "1.0.0")
+ ));
+
+
+ PdpSubGroup pdpSubgroup1 = new PdpSubGroup();
+ pdpSubgroup1.setPdpType("subGroup1");
+ pdpSubgroup1.setSupportedPolicyTypes(
+ Arrays.asList(new ToscaPolicyTypeIdentifier("org.onap.*", "1.0.0")));
+
+ PdpSubGroup pdpSubgroup2 = new PdpSubGroup();
+ pdpSubgroup2.setPdpType("subGroup2");
+ pdpSubgroup2.setSupportedPolicyTypes(Arrays.asList(new ToscaPolicyTypeIdentifier("org.onap.test", "1.0.0")));
+
+ PdpSubGroup pdpSubgroup3 = new PdpSubGroup();
+ pdpSubgroup3.setPdpType("subGroup3");
+ pdpSubgroup3.setSupportedPolicyTypes(Arrays.asList(new ToscaPolicyTypeIdentifier("org.onap.test*", "1.0.0")));
+
+
+ PdpGroup pdpGroup1 = new PdpGroup();
+ pdpGroup1.setName("pdpGroup1");
+ pdpGroup1.setPdpGroupState(PdpState.ACTIVE);
+ pdpGroup1.setPdpSubgroups(Arrays.asList(pdpSubgroup1, pdpSubgroupBad));
+
+ PdpGroup pdpGroup2 = new PdpGroup();
+ pdpGroup2.setName("pdpGroup2");
+ pdpGroup2.setPdpGroupState(PdpState.ACTIVE);
+ pdpGroup2.setPdpSubgroups(Arrays.asList(pdpSubgroup1, pdpSubgroup2, pdpSubgroup3, pdpSubgroupBad));
+
+ PdpGroup pdpGroup3 = new PdpGroup();
+ pdpGroup3.setName("pdpGroup3");
+ pdpGroup3.setPdpGroupState(PdpState.ACTIVE);
+ pdpGroup3.setPdpSubgroups(Arrays.asList(pdpSubgroupBad));
+
+ PdpGroup pdpGroup4 = new PdpGroup();
+ pdpGroup4.setName("pdpGroup4");
+ pdpGroup4.setPdpGroupState(PdpState.PASSIVE);
+ pdpGroup4.setPdpSubgroups(Arrays.asList(pdpSubgroup1));
+
+ PdpGroups pdpGroups = new PdpGroups();
+ pdpGroups.setGroups(Arrays.asList(pdpGroup1, pdpGroup2, pdpGroup3, pdpGroup4));
+ PdpGroupsAnalyzer.updatePdpGroup(Arrays.asList(policyModel), pdpGroups);
+
+ assertThat(policyModel.getPolicyPdpGroup().toString()).isEqualTo(
+ "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},"
+ + "{\"pdpGroup2\":[\"subGroup1\",\"subGroup2\",\"subGroup3\"]}]}");
+ }
+}
diff --git a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupTest.java b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupTest.java
deleted file mode 100644
index 699693de0..000000000
--- a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupTest.java
+++ /dev/null
@@ -1,86 +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.policy.clamp.policy.pdpgroup;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-import org.junit.Test;
-
-public class PdpGroupTest {
-
-
- @Test
- public void testGetSupportedSubgroups() throws IOException {
- PdpGroup pdpGroup1 = new PdpGroup();
- pdpGroup1.setName("pdpGroup1");
- pdpGroup1.setPdpGroupState("INACTIVE");
- assertThat(pdpGroup1.getSupportedSubgroups("test", "1.0.0")).isNull();
-
- PdpGroup pdpGroup2 = new PdpGroup();
- pdpGroup2.setName("pdpGroup2");
- pdpGroup2.setPdpGroupState("ACTIVE");
-
- PolicyModelKey type1 = new PolicyModelKey("type1", "1.0.0");
- PolicyModelKey type2 = new PolicyModelKey("type2", "2.0.0");
-
- PdpSubgroup pdpSubgroup1 = new PdpSubgroup();
- pdpSubgroup1.setPdpType("subGroup1");
- List<PolicyModelKey> pdpTypeList = new LinkedList<PolicyModelKey>();
- pdpTypeList.add(type1);
- pdpTypeList.add(type2);
- pdpSubgroup1.setSupportedPolicyTypes(pdpTypeList);
-
- PolicyModelKey type3 = new PolicyModelKey("type3", "1.0.0");
- PdpSubgroup pdpSubgroup2 = new PdpSubgroup();
- pdpSubgroup2.setPdpType("subGroup2");
- List<PolicyModelKey> pdpTypeList2 = new LinkedList<PolicyModelKey>();
- pdpTypeList2.add(type2);
- pdpTypeList2.add(type3);
- pdpSubgroup2.setSupportedPolicyTypes(pdpTypeList2);
-
- List<PdpSubgroup> pdpSubgroupList = new LinkedList<PdpSubgroup>();
- pdpSubgroupList.add(pdpSubgroup1);
- pdpSubgroupList.add(pdpSubgroup2);
- pdpGroup2.setPdpSubgroups(pdpSubgroupList);
-
- JsonObject res1 = pdpGroup2.getSupportedSubgroups("type2", "2.0.0");
- assertThat(res1.get("pdpGroup2")).isNotNull();
- JsonArray resSubList = res1.getAsJsonArray("pdpGroup2");
- assertThat(resSubList.size()).isEqualTo(2);
- assertThat(resSubList.toString().contains("subGroup1")).isTrue();
- assertThat(resSubList.toString().contains("subGroup2")).isTrue();
-
- JsonObject res2 = pdpGroup2.getSupportedSubgroups("type1", "1.0.0");
- assertThat(res2.get("pdpGroup2")).isNotNull();
- JsonArray resSubList2 = res2.getAsJsonArray("pdpGroup2");
- assertThat(resSubList2.size()).isEqualTo(1);
-
- assertThat(pdpGroup2.getSupportedSubgroups("type3", "1.0.1")).isNull();
- }
-}
diff --git a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PolicyModelKeyTest.java b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PolicyModelKeyTest.java
deleted file mode 100644
index d4cf27392..000000000
--- a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PolicyModelKeyTest.java
+++ /dev/null
@@ -1,55 +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.policy.clamp.policy.pdpgroup;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.IOException;
-import org.junit.Test;
-
-public class PolicyModelKeyTest {
-
- @Test
- public void testEqualsMethod() throws IOException {
- PolicyModelKey key1 = new PolicyModelKey("name1", "1.0.0");
- PolicyModelKey key2 = new PolicyModelKey(null, "1.0.0");
- PolicyModelKey key3 = new PolicyModelKey("name1", null);
-
- assertThat(key1.equals(null)).isFalse();
- assertThat(key1.equals("key2")).isFalse();
-
- assertThat(key2.equals(key1)).isFalse();
- assertThat(key3.equals(key1)).isFalse();
-
- PolicyModelKey key4 = new PolicyModelKey("name2", "1.0.0");
- PolicyModelKey key5 = new PolicyModelKey("name1", "2.0.0");
- assertThat(key1.equals(key4)).isFalse();
- assertThat(key1.equals(key5)).isFalse();
-
- PolicyModelKey key6 = new PolicyModelKey("name(.*)", "1.0.0");
- PolicyModelKey key7 = new PolicyModelKey("name1", "1.0.0");
- assertThat(key1.equals(key6)).isTrue();
- assertThat(key1.equals(key7)).isTrue();
- }
-}