diff options
Diffstat (limited to 'src/test/java/org')
4 files changed, 194 insertions, 0 deletions
diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java index 152648712..5eca90c7f 100644 --- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java +++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java @@ -46,6 +46,7 @@ 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) @@ -148,6 +149,7 @@ public class LoopServiceTestItCase { @Test @Transactional + //@Commit public void shouldCreateNewMicroservicePolicyAndUpdateJsonRepresentationOfOldOne() { // given saveTestLoopToDb(); diff --git a/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java b/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java index abeecd1b2..f8aadbad5 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 java.util.LinkedList; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; @@ -33,14 +34,20 @@ import javax.transaction.Transactional; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.clamp.clds.Application; +import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.loop.template.PolicyModel; import org.onap.clamp.loop.template.PolicyModelId; import org.onap.clamp.loop.template.PolicyModelsRepository; import org.onap.clamp.loop.template.PolicyModelsService; +import org.onap.clamp.policy.pdpgroup.PdpGroup; +import org.onap.clamp.policy.pdpgroup.PdpSubgroup; +import org.onap.clamp.policy.pdpgroup.PolicyModelKey; 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 { @@ -167,4 +174,71 @@ public class PolicyModelServiceItCase { assertThat(listToCheck.get(1)).isEqualByComparingTo(policyModel1); assertThat(listToCheck.get(2)).isEqualByComparingTo(policyModel3); } + + @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); + + + PolicyModelKey type1 = new PolicyModelKey("org.onap.testos", "1.0.0"); + PolicyModelKey type2 = new PolicyModelKey("org.onap.testos2", "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("org.onap.testos3", "2.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); + + PdpGroup pdpGroup1 = new PdpGroup(); + pdpGroup1.setName("pdpGroup1"); + pdpGroup1.setPdpGroupState("ACTIVE"); + pdpGroup1.setPdpSubgroups(pdpSubgroupList); + + List<PdpSubgroup> pdpSubgroupList2 = new LinkedList<PdpSubgroup>(); + pdpSubgroupList2.add(pdpSubgroup1); + pdpSubgroupList2.add(pdpSubgroup2); + PdpGroup pdpGroup2 = new PdpGroup(); + pdpGroup2.setName("pdpGroup2"); + pdpGroup2.setPdpGroupState("ACTIVE"); + pdpGroup2.setPdpSubgroups(pdpSubgroupList2); + + List<PdpGroup> pdpGroupList = new LinkedList<PdpGroup>(); + pdpGroupList.add(pdpGroup1); + pdpGroupList.add(pdpGroup2); + policyModelsService.updatePdpGroupInfo(pdpGroupList); + + JsonObject res1 = policyModelsService.getPolicyModel("org.onap.testos", "1.0.0").getPolicyPdpGroup(); + 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\"]}]}"; + JsonObject expectedJson2 = JsonUtils.GSON.fromJson(expectedRes2, JsonObject.class); + assertThat(res2).isEqualTo(expectedJson2); + + JsonObject res3 = policyModelsService.getPolicyModel("org.onap.testos3", "1.0.0").getPolicyPdpGroup(); + assertThat(res3).isNull(); + } } 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 b42e15367..3f502ff78 100644 --- a/src/test/java/org/onap/clamp/policy/downloader/PolicyEngineControllerTestItCase.java +++ b/src/test/java/org/onap/clamp/policy/downloader/PolicyEngineControllerTestItCase.java @@ -24,15 +24,19 @@ package org.onap.clamp.policy.downloader; import static org.assertj.core.api.Assertions.assertThat; +import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import java.io.IOException; import java.time.Instant; import java.util.List; import javax.transaction.Transactional; +import org.json.simple.parser.ParseException; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.clamp.clds.Application; +import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.loop.template.PolicyModel; +import org.onap.clamp.loop.template.PolicyModelId; import org.onap.clamp.loop.template.PolicyModelsRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -76,4 +80,30 @@ public class PolicyEngineControllerTestItCase { assertThat(firstExecution).isBefore(secondExecution); } + @Test + @Transactional + public void downloadPdpGroupsTest() throws JsonSyntaxException, IOException, InterruptedException, ParseException { + PolicyModel policyModel1 = new PolicyModel("onap.policies.monitoring.test", null, "1.0.0"); + policyModelsRepository.saveAndFlush(policyModel1); + PolicyModel policyModel2 = new PolicyModel("onap.policies.controlloop.Operational", null, "1.0.0"); + policyModelsRepository.saveAndFlush(policyModel2); + + policyController.downloadPdpGroups(); + + List<PolicyModel> policyModelsList = policyModelsRepository.findAll(); + assertThat(policyModelsList.size()).isGreaterThanOrEqualTo(2); + + PolicyModel policy1 = policyModelsRepository + .getOne(new PolicyModelId("onap.policies.monitoring.test", "1.0.0")); + PolicyModel policy2 = policyModelsRepository + .getOne(new PolicyModelId("onap.policies.controlloop.Operational", "1.0.0")); + + String expectedRes1 = "{\"supportedPdpGroups\":[{\"monitoring\":[\"xacml\"]}]}"; + JsonObject expectedJson1 = JsonUtils.GSON.fromJson(expectedRes1, JsonObject.class); + assertThat(policy1.getPolicyPdpGroup()).isEqualTo(expectedJson1); + String expectedRes2 = "{\"supportedPdpGroups\":[{\"controlloop\":[\"apex\",\"drools\"]}]}"; + JsonObject expectedJson2 = JsonUtils.GSON.fromJson(expectedRes2, JsonObject.class); + assertThat(policy2.getPolicyPdpGroup()).isEqualTo(expectedJson2); + + } } diff --git a/src/test/java/org/onap/clamp/policy/pdpgroup/PdpGroupTest.java b/src/test/java/org/onap/clamp/policy/pdpgroup/PdpGroupTest.java new file mode 100644 index 000000000..b6f7c5491 --- /dev/null +++ b/src/test/java/org/onap/clamp/policy/pdpgroup/PdpGroupTest.java @@ -0,0 +1,88 @@ +/*- + * ============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.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(); + } +} |