diff options
Diffstat (limited to 'models-pdp')
11 files changed, 531 insertions, 112 deletions
diff --git a/models-pdp/pom.xml b/models-pdp/pom.xml index aaf9ee48f..029c76b8f 100644 --- a/models-pdp/pom.xml +++ b/models-pdp/pom.xml @@ -45,13 +45,12 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/Pdp.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/Pdp.java index 1eaa41547..034374c29 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/Pdp.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/Pdp.java @@ -21,10 +21,9 @@ package org.onap.policy.models.pdp.concepts; -import lombok.Getter; +import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; -import lombok.Setter; import lombok.ToString; import org.onap.policy.models.pdp.enums.PdpHealthStatus; import org.onap.policy.models.pdp.enums.PdpState; @@ -34,10 +33,9 @@ import org.onap.policy.models.pdp.enums.PdpState; * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ -@Getter -@Setter @ToString @NoArgsConstructor +@Data public class Pdp { @NonNull diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java index 5965b728d..3c07a9d0f 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java @@ -46,7 +46,7 @@ public class PdpGroupFilter implements PfObjectFilter<PdpGroup> { // Regular expression private String name; - // Regular Expression, set to LATEST_VERRSION to get the latest version + // Regular Expression, set to to get the latest version private String version; private PdpState groupState; @@ -67,9 +67,10 @@ public class PdpGroupFilter implements PfObjectFilter<PdpGroup> { // @formatter:off List<PdpGroup> returnList = originalList.stream() - .filter(p -> filterOnRegexp(p.getName(), name)) - .filter(p -> version.equals(LATEST_VERSION) || filterOnRegexp(p.getVersion(), version)) - .filter(p -> ObjectUtils.compare(p.getPdpGroupState(), groupState) == 0) + .filter(p -> filterString(p.getName(), name)) + .filter(p -> (version != null && LATEST_VERSION.equals(version)) + || filterString(p.getVersion(), version)) + .filter(p -> groupState == null || ObjectUtils.compare(p.getPdpGroupState(), groupState) == 0) .filter(p -> filterOnPdpType(p, pdpType)) .filter(p -> filterOnPolicyType(p, policyType)) .filter(p -> filterOnPolicy(p, policy)) diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java index 4e5843678..405408946 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java @@ -25,10 +25,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import lombok.Getter; +import lombok.Data; import lombok.NonNull; -import lombok.Setter; -import lombok.ToString; import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; @@ -39,9 +37,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifi * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ -@Getter -@Setter -@ToString +@Data public class PdpSubGroup { private String pdpType; private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes; diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java index 71f27c48b..d0fc216c2 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java @@ -29,11 +29,13 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import javax.persistence.CascadeType; import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.EmbeddedId; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; @@ -87,7 +89,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> { private Map<String, String> properties; // @formatter:off - @OneToMany + @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) @CollectionTable(joinColumns = { @JoinColumn(name = "pdpGroupParentKeyName", referencedColumnName = "parentKeyName"), @JoinColumn(name = "pdpGroupParentKeyVersion", referencedColumnName = "parentKeyVersion"), diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java index d51cfc67e..20e43f0b5 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java @@ -28,19 +28,23 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import javax.persistence.CollectionTable; + +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.EmbeddedId; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.OneToMany; import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; + import org.onap.policy.common.utils.validation.Assertions; import org.onap.policy.common.utils.validation.ParameterValidationUtils; import org.onap.policy.models.base.PfAuthorative; @@ -89,13 +93,16 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro @ElementCollection private Map<String, String> properties; - // @formatter:ofF - @OneToMany - @CollectionTable( - joinColumns = { @JoinColumn(name = "pdpSubGroupParentKeyName", referencedColumnName = "parentKeyName"), - @JoinColumn(name = "pdpSubGroupParentKeyVersion", referencedColumnName = "parentKeyVersion"), - @JoinColumn(name = "pdpSubGroupParentLocalName", referencedColumnName = "parentLocalName"), - @JoinColumn(name = "pdpSubGroupLocalName", referencedColumnName = "localName") }) + // @formatter:off + @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) + @JoinTable ( + joinColumns = { + @JoinColumn(name = "pdpParentKeyName", referencedColumnName = "parentKeyName"), + @JoinColumn(name = "pdpParentKeyVersion", referencedColumnName = "parentKeyVersion"), + @JoinColumn(name = "pdpParentLocalName", referencedColumnName = "parentLocalName"), + @JoinColumn(name = "pdpLocalName", referencedColumnName = "localName") + } + ) // formatter:on private List<JpaPdp> pdpInstances; diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupFilterTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupFilterTest.java new file mode 100644 index 000000000..61974dc89 --- /dev/null +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupFilterTest.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pdp.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; + +/** + * Test of the {@link PdpGroupFilter} class. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class PdpGroupFilterTest { + private List<PdpGroup> pdpGroupList; + + /** + * Set up a PDP group list for filtering. + * + * @throws CoderException on JSON decoding errors + */ + @Before + public void setupPdpGroupList() throws CoderException { + String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroupsForFiltering.json"); + PdpGroups pdpGroups = new StandardCoder().decode(originalJson, PdpGroups.class); + pdpGroupList = pdpGroups.getGroups(); + } + + @Test + public void testNullList() { + PdpGroupFilter filter = PdpGroupFilter.builder().build(); + + assertThatThrownBy(() -> { + filter.filter(null); + }).hasMessage("originalList is marked @NonNull but is null"); + } + + @Test + public void testFilterNothing() { + PdpGroupFilter filter = PdpGroupFilter.builder().build(); + + List<PdpGroup> filteredList = filter.filter(pdpGroupList); + assertTrue(filteredList.containsAll(pdpGroupList)); + } + + @Test + public void testFilterLatestVersion() { + PdpGroupFilter filter = PdpGroupFilter.builder().version(PdpGroupFilter.LATEST_VERSION).build(); + + List<PdpGroup> filteredList = filter.filter(pdpGroupList); + assertEquals(2, filteredList.size()); + assertEquals("1.2.4", filteredList.get(0).getVersion()); + assertEquals("1.2.3", filteredList.get(1).getVersion()); + } + + @Test + public void testFilterNameVersion() { + PdpGroupFilter filter = PdpGroupFilter.builder().name("PdpGroup0").build(); + List<PdpGroup> filteredList = filter.filter(pdpGroupList); + assertEquals(3, filteredList.size()); + + filter = PdpGroupFilter.builder().name("PdpGroup1").build(); + filteredList = filter.filter(pdpGroupList); + assertEquals(2, filteredList.size()); + + filter = PdpGroupFilter.builder().name("PdpGroup2").build(); + filteredList = filter.filter(pdpGroupList); + assertEquals(0, filteredList.size()); + + filter = PdpGroupFilter.builder().version("1.2.3").build(); + filteredList = filter.filter(pdpGroupList); + assertEquals(2, filteredList.size()); + + filter = PdpGroupFilter.builder().name("PdpGroup0").version("1.2.3").build(); + filteredList = filter.filter(pdpGroupList); + assertEquals(1, filteredList.size()); + + filter = PdpGroupFilter.builder().name("PdpGroup1").version("1.2.9").build(); + filteredList = filter.filter(pdpGroupList); + assertEquals(0, filteredList.size()); + } +} diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java index 4de1f2ee3..4698ece7b 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java @@ -25,7 +25,9 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.TreeMap; import org.junit.Test; @@ -83,4 +85,27 @@ public class TestPdpGroup { group.setDescription("B"); assertTrue(hash != group.hashCode()); } + + @Test + public void testCompareTo() { + PdpGroup pdpGroup0 = new PdpGroup(); + pdpGroup0.setName("Name0"); + pdpGroup0.setVersion("1.2.3"); + + PdpGroup pdpGroup1 = new PdpGroup(); + pdpGroup1.setName("Name0"); + pdpGroup1.setVersion("1.2.3"); + + assertEquals(0, pdpGroup0.compareTo(pdpGroup1)); + + PdpGroups pdpGroups = new PdpGroups(); + pdpGroups.setGroups(new ArrayList<>()); + pdpGroups.getGroups().add(pdpGroup0); + pdpGroups.getGroups().add(pdpGroup1); + + List<Map<String, PdpGroup>> mapList = pdpGroups.toMapList(); + + assertEquals(1, mapList.size()); + assertEquals(1, mapList.get(0).size()); + } } diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java index 468f3d4f9..4012eaa1c 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java @@ -24,10 +24,12 @@ package org.onap.policy.models.pdp.persistence.provider; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; import java.sql.Connection; import java.sql.DriverManager; import java.util.ArrayList; +import java.util.List; import org.junit.After; import org.junit.Before; @@ -38,8 +40,9 @@ import org.onap.policy.models.dao.DaoParameters; import org.onap.policy.models.dao.PfDao; import org.onap.policy.models.dao.PfDaoFactory; import org.onap.policy.models.dao.impl.DefaultPfDao; +import org.onap.policy.models.pdp.concepts.Pdp; +import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpGroups; -import org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup; import org.onap.policy.models.pdp.persistence.provider.PdpProvider; import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider; @@ -91,7 +94,7 @@ public class PdpProviderTest { } @Test - public void testPoliciesGet() throws Exception { + public void testGroupsGet() throws Exception { assertThatThrownBy(() -> { new PdpProvider().getPdpGroups(null, null, null); }).hasMessage("dao is marked @NonNull but is null"); @@ -105,7 +108,6 @@ public class PdpProviderTest { }).hasMessage("dao is marked @NonNull but is null"); String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json"); - PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class); PdpGroups createdPdpGroups0 = new PdpGroups(); @@ -122,7 +124,7 @@ public class PdpProviderTest { } @Test - public void testPolicyCreate() throws Exception { + public void testGroupsCreate() throws Exception { assertThatThrownBy(() -> { new PdpProvider().createPdpGroups(null, null); }).hasMessage("dao is marked @NonNull but is null"); @@ -136,7 +138,6 @@ public class PdpProviderTest { }).hasMessage("pdpGroups is marked @NonNull but is null"); String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json"); - PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class); PdpGroups createdPdpGroups0 = new PdpGroups(); @@ -152,7 +153,7 @@ public class PdpProviderTest { } @Test - public void testPolicyCreateNoPdp() throws Exception { + public void testGroupsCreateNoPdp() throws Exception { String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroupsNoPDPs.json"); PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class); @@ -171,82 +172,82 @@ public class PdpProviderTest { String gotJson = standardCoder.encode(gotPdpGroups0); assertEquals(originalTweakedJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", "")); } - /* - * @Test public void testPolicyUpdate() throws Exception { try { new SimpleToscaProvider().updatePolicies(null, - * null); fail("test should throw an exception here"); } catch (Exception exc) { - * assertEquals("dao is marked @NonNull but is null", exc.getMessage()); } - * - * try { new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate()); - * fail("test should throw an exception here"); } catch (Exception exc) { - * assertEquals("dao is marked @NonNull but is null", exc.getMessage()); } - * - * try { new SimpleToscaProvider().updatePolicies(pfDao, null); fail("test should throw an exception here"); } catch - * (Exception exc) { assertEquals("serviceTemplate is marked @NonNull but is null", exc.getMessage()); } - * - * ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - * ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), - * ToscaServiceTemplate.class); - * - * JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate(); - * originalServiceTemplate.fromAuthorative(toscaServiceTemplate); - * - * assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate updatedServiceTemplate = new - * SimpleToscaProvider().updatePolicies(pfDao, originalServiceTemplate); - * - * assertEquals(originalServiceTemplate, updatedServiceTemplate); } - * - * @Test public void testPoliciesDelete() throws Exception { try { new SimpleToscaProvider().deletePolicy(null, - * null); fail("test should throw an exception here"); } catch (Exception exc) { - * assertEquals("dao is marked @NonNull but is null", exc.getMessage()); } - * - * try { new SimpleToscaProvider().deletePolicy(null, new PfConceptKey()); - * fail("test should throw an exception here"); } catch (Exception exc) { - * assertEquals("dao is marked @NonNull but is null", exc.getMessage()); } - * - * try { new SimpleToscaProvider().deletePolicy(pfDao, null); fail("test should throw an exception here"); } catch - * (Exception exc) { assertEquals("policyKey is marked @NonNull but is null", exc.getMessage()); } - * - * ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - * ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), - * ToscaServiceTemplate.class); - * - * JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate(); - * originalServiceTemplate.fromAuthorative(toscaServiceTemplate); - * - * assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = new - * SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); - * - * assertEquals(originalServiceTemplate, createdServiceTemplate); - * - * PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); - * - * JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, new - * PfConceptKey(policyKey)); - * - * assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey), - * deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey)); - * - * try { new SimpleToscaProvider().getPolicies(pfDao, new PfConceptKey(policyKey)); - * fail("test should throw an exception here"); } catch (Exception exc) { - * assertEquals("policy not found: onap.restart.tca:1.0.0", exc.getMessage()); } } - * - * @Test public void testAssertPoliciesExist() throws PfModelException { JpaToscaServiceTemplate testServiceTemplate - * = new JpaToscaServiceTemplate(); - * - * try { new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate); - * fail("test should throw an exception here"); } catch (Exception exc) { - * assertEquals("topology template not specified on service template", exc.getMessage()); } - * - * testServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); try { new - * SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate); fail("test should throw an exception here"); } - * catch (Exception exc) { assertEquals("no policies specified on topology template of service template", - * exc.getMessage()); } - * - * testServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); try { new - * SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate); fail("test should throw an exception here"); } - * catch (Exception exc) { - * assertEquals("list of policies specified on topology template of service template is empty", exc.getMessage()); } - * - * } - */ + + @Test + public void testGroupsUpdate() throws Exception { + assertThatThrownBy(() -> { + new PdpProvider().updatePdpGroups(null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpGroups(null, new ArrayList<>()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpGroups(pfDao, null); + }).hasMessage("pdpGroups is marked @NonNull but is null"); + + String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json"); + PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class); + + PdpGroups createdPdpGroups0 = new PdpGroups(); + createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups())); + String createdJson = standardCoder.encode(createdPdpGroups0); + assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", "")); + + PdpGroups gotPdpGroups0 = new PdpGroups(); + gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3")); + + String gotJson = standardCoder.encode(gotPdpGroups0); + assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", "")); + + String updateJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0Update.json"); + PdpGroups updatePdpGroups0 = standardCoder.decode(updateJson, PdpGroups.class); + + PdpGroups updatedPdpGroups0 = new PdpGroups(); + updatedPdpGroups0.setGroups(new PdpProvider().updatePdpGroups(pfDao, updatePdpGroups0.getGroups())); + + List<Pdp> beforePdpInstances = updatePdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances(); + List<Pdp> afterPdpInstances = updatedPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances(); + assertTrue(beforePdpInstances.containsAll(afterPdpInstances)); + } + + @Test + public void testPoliciesDelete() throws Exception { + assertThatThrownBy(() -> { + new PdpProvider().deletePdpGroup(null, null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().deletePdpGroup(null, null, "version"); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().deletePdpGroup(null, "name", "version"); + }).hasMessage("dao is marked @NonNull but is null"); + + String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json"); + PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class); + + PdpGroups createdPdpGroups0 = new PdpGroups(); + createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups())); + String createdJson = standardCoder.encode(createdPdpGroups0); + assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", "")); + + PdpGroups gotPdpGroups0 = new PdpGroups(); + gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3")); + + String gotJson = standardCoder.encode(gotPdpGroups0); + assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", "")); + + PdpGroup deletedPdpGroup = new PdpProvider().deletePdpGroup(pfDao, "PdpGroup0", "1.2.3"); + + assertEquals(createdPdpGroups0.getGroups().get(0), deletedPdpGroup); + + assertEquals(0, new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3").size()); + + assertThatThrownBy(() -> { + new PdpProvider().deletePdpGroup(pfDao, "PdpGroup0", "1.2.3"); + }).hasMessage("delete of PDP group \"PdpGroup0:1.2.3\" failed, PDP group does not exist"); + } } diff --git a/models-pdp/src/test/resources/testdata/PdpGroups0Update.json b/models-pdp/src/test/resources/testdata/PdpGroups0Update.json new file mode 100644 index 000000000..a54ec53ea --- /dev/null +++ b/models-pdp/src/test/resources/testdata/PdpGroups0Update.json @@ -0,0 +1,83 @@ +{ + "groups": [ + { + "name": "PdpGroup0", + "version": "1.2.3", + "description": "group description", + "pdpGroupState": "PASSIVE", + "properties": { + "groupProperty0": "Value of Group Property 0" + }, + "pdpSubgroups": [ + { + "pdpType": "APEX", + "supportedPolicyTypes": [ + { + "name": "policy.type.0", + "version": "1.2.3" + } + ], + "policies": [ + { + "name": "Policy0", + "version": "4.5.6" + } + ], + "currentInstanceCount": 123, + "desiredInstanceCount": 456, + "properties": { + "subgroupProperty0": "Value of sub Group Property 0" + }, + "pdpInstances": [ + { + "instanceId": "apex-0", + "pdpState": "ACTIVE", + "healthy": "NOT_HEALTHY", + "message": "message from PDP" + }, + { + "instanceId": "apex-1", + "pdpState": "ACTIVE", + "healthy": "NOT_HEALTHY", + "message": "message from PDP" + }, + { + "instanceId": "apex-2", + "pdpState": "ACTIVE", + "healthy": "NOT_HEALTHY", + "message": "message from PDP" + } + ] + }, + { + "pdpType": "Drools", + "supportedPolicyTypes": [ + { + "name": "policy.type.1", + "version": "4.5.6" + } + ], + "policies": [ + { + "name": "Policy0", + "version": "4.5.6" + } + ], + "currentInstanceCount": 123, + "desiredInstanceCount": 456, + "properties": { + "subgroupProperty0": "Value of sub Group Property 0" + }, + "pdpInstances": [ + { + "instanceId": "drools-0", + "pdpState": "ACTIVE", + "healthy": "NOT_HEALTHY", + "message": "message from PDP" + } + ] + } + ] + } + ] +}
\ No newline at end of file diff --git a/models-pdp/src/test/resources/testdata/PdpGroupsForFiltering.json b/models-pdp/src/test/resources/testdata/PdpGroupsForFiltering.json new file mode 100644 index 000000000..c62e1ea58 --- /dev/null +++ b/models-pdp/src/test/resources/testdata/PdpGroupsForFiltering.json @@ -0,0 +1,199 @@ +{ + "groups": [ + { + "name": "PdpGroup0", + "version": "1.2.3", + "description": "group description", + "pdpGroupState": "PASSIVE", + "properties": { + "groupProperty0": "Value of Group Property 0" + }, + "pdpSubgroups": [ + { + "pdpType": "APEX", + "supportedPolicyTypes": [ + { + "name": "policy.type.0", + "version": "1.2.3" + } + ], + "policies": [ + { + "name": "Policy0", + "version": "4.5.6" + } + ], + "currentInstanceCount": 123, + "desiredInstanceCount": 456, + "properties": { + "subgroupProperty0": "Value of sub Group Property 0" + }, + "pdpInstances": [ + { + "instanceId": "apex-0", + "pdpState": "ACTIVE", + "healthy": "NOT_HEALTHY", + "message": "message from PDP" + } + ] + } + ] + }, + { + "name": "PdpGroup0", + "version": "1.2.4", + "description": "group description", + "pdpGroupState": "PASSIVE", + "properties": { + "groupProperty0": "Value of Group Property 0" + }, + "pdpSubgroups": [ + { + "pdpType": "APEX", + "supportedPolicyTypes": [ + { + "name": "policy.type.0", + "version": "1.2.3" + } + ], + "policies": [ + { + "name": "Policy0", + "version": "4.5.6" + } + ], + "currentInstanceCount": 123, + "desiredInstanceCount": 456, + "properties": { + "subgroupProperty0": "Value of sub Group Property 0" + }, + "pdpInstances": [ + { + "instanceId": "apex-0", + "pdpState": "ACTIVE", + "healthy": "NOT_HEALTHY", + "message": "message from PDP" + } + ] + } + ] + }, + { + "name": "PdpGroup0", + "version": "1.2.1", + "description": "group description", + "pdpGroupState": "PASSIVE", + "properties": { + "groupProperty0": "Value of Group Property 0" + }, + "pdpSubgroups": [ + { + "pdpType": "APEX", + "supportedPolicyTypes": [ + { + "name": "policy.type.0", + "version": "1.2.3" + } + ], + "policies": [ + { + "name": "Policy0", + "version": "4.5.6" + } + ], + "currentInstanceCount": 123, + "desiredInstanceCount": 456, + "properties": { + "subgroupProperty0": "Value of sub Group Property 0" + }, + "pdpInstances": [ + { + "instanceId": "apex-0", + "pdpState": "ACTIVE", + "healthy": "NOT_HEALTHY", + "message": "message from PDP" + } + ] + } + ] + }, + { + "name": "PdpGroup1", + "version": "1.2.1", + "description": "group description", + "pdpGroupState": "PASSIVE", + "properties": { + "groupProperty0": "Value of Group Property 0" + }, + "pdpSubgroups": [ + { + "pdpType": "APEX", + "supportedPolicyTypes": [ + { + "name": "policy.type.0", + "version": "1.2.3" + } + ], + "policies": [ + { + "name": "Policy0", + "version": "4.5.6" + } + ], + "currentInstanceCount": 123, + "desiredInstanceCount": 456, + "properties": { + "subgroupProperty0": "Value of sub Group Property 0" + }, + "pdpInstances": [ + { + "instanceId": "apex-0", + "pdpState": "ACTIVE", + "healthy": "NOT_HEALTHY", + "message": "message from PDP" + } + ] + } + ] + }, + { + "name": "PdpGroup1", + "version": "1.2.3", + "description": "group description", + "pdpGroupState": "PASSIVE", + "properties": { + "groupProperty0": "Value of Group Property 0" + }, + "pdpSubgroups": [ + { + "pdpType": "APEX", + "supportedPolicyTypes": [ + { + "name": "policy.type.0", + "version": "1.2.3" + } + ], + "policies": [ + { + "name": "Policy0", + "version": "4.5.6" + } + ], + "currentInstanceCount": 123, + "desiredInstanceCount": 456, + "properties": { + "subgroupProperty0": "Value of sub Group Property 0" + }, + "pdpInstances": [ + { + "instanceId": "apex-0", + "pdpState": "ACTIVE", + "healthy": "NOT_HEALTHY", + "message": "message from PDP" + } + ] + } + ] + } + ] +}
\ No newline at end of file |