diff options
Diffstat (limited to 'models-pdp/src')
9 files changed, 37 insertions, 71 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java index 4e7fc4117..6d5f804f8 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java @@ -22,6 +22,7 @@ package org.onap.policy.models.pdp.concepts; import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -69,7 +70,7 @@ public class PdpGroup implements PfNameVersion, Comparable<PdpGroup> { this.description = source.description; this.pdpGroupState = source.pdpGroupState; this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties)); - this.pdpSubgroups = PfUtils.mapList(source.pdpSubgroups, PdpSubGroup::new); + this.pdpSubgroups = PfUtils.mapList(source.pdpSubgroups, PdpSubGroup::new, new ArrayList<>(0)); } @Override diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java index 3655aa796..e50694b93 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java @@ -21,6 +21,7 @@ package org.onap.policy.models.pdp.concepts; +import java.util.ArrayList; import java.util.List; import lombok.Getter; import lombok.Setter; @@ -78,8 +79,9 @@ public class PdpStatus extends PdpMessage { this.state = source.state; this.healthy = source.healthy; this.description = source.description; - this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, ToscaPolicyTypeIdentifier::new); - this.policies = PfUtils.mapList(source.policies, ToscaPolicyIdentifier::new); + this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, ToscaPolicyTypeIdentifier::new, + new ArrayList<>(0)); + this.policies = PfUtils.mapList(source.policies, ToscaPolicyIdentifier::new, new ArrayList<>(0)); this.deploymentInstanceInfo = source.deploymentInstanceInfo; this.properties = source.properties; this.statistics = (source.statistics == null ? null : new PdpStatistics(source.statistics)); 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 2618a5017..236cc858a 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 @@ -21,6 +21,7 @@ package org.onap.policy.models.pdp.concepts; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -64,12 +65,13 @@ public class PdpSubGroup { */ public PdpSubGroup(@NonNull final PdpSubGroup source) { this.pdpType = source.pdpType; - this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, ToscaPolicyTypeIdentifier::new); - this.policies = PfUtils.mapList(source.policies, ToscaPolicyIdentifier::new); + this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, ToscaPolicyTypeIdentifier::new, + new ArrayList<>(0)); + this.policies = PfUtils.mapList(source.policies, ToscaPolicyIdentifier::new, new ArrayList<>(0)); this.currentInstanceCount = source.currentInstanceCount; this.desiredInstanceCount = source.desiredInstanceCount; this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties)); - this.pdpInstances = PfUtils.mapList(source.pdpInstances, Pdp::new); + this.pdpInstances = PfUtils.mapList(source.pdpInstances, Pdp::new, new ArrayList<>(0)); } /** diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java index 7d90c03b1..5820a355b 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java @@ -25,21 +25,17 @@ package org.onap.policy.models.pdp.persistence.concepts; import java.io.Serializable; import java.util.List; - import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.Table; - import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; - import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.onap.policy.common.utils.validation.Assertions; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfKey; @@ -113,6 +109,10 @@ public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializabl */ public JpaPdp(@NonNull final JpaPdp copyConcept) { super(copyConcept); + this.key = new PfReferenceKey(copyConcept.key); + this.pdpState = copyConcept.pdpState; + this.healthy = copyConcept.healthy; + this.message = copyConcept.message; } /** @@ -230,17 +230,4 @@ public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializabl return ObjectUtils.compare(message, other.message); } - - @Override - public PfConcept copyTo(@NonNull final PfConcept target) { - Assertions.instanceOf(target, JpaPdp.class); - - final JpaPdp copy = ((JpaPdp) target); - copy.setKey(new PfReferenceKey(key)); - copy.setPdpState(pdpState); - copy.setHealthy(healthy); - copy.setMessage(message); - - return copy; - } } 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 36d5cc18e..0df620bcf 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 @@ -28,7 +28,6 @@ import java.util.LinkedHashMap; 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; @@ -41,14 +40,11 @@ import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.Table; - import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; - import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.onap.policy.common.utils.validation.Assertions; import org.onap.policy.common.utils.validation.ParameterValidationUtils; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; @@ -135,6 +131,11 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> { */ public JpaPdpGroup(@NonNull final JpaPdpGroup copyConcept) { super(copyConcept); + this.key = new PfConceptKey(copyConcept.key); + this.description = copyConcept.description; + this.pdpGroupState = copyConcept.pdpGroupState; + this.properties = (copyConcept.properties == null ? null : new LinkedHashMap<>(copyConcept.properties)); + this.pdpSubGroups = PfUtils.mapList(copyConcept.pdpSubGroups, JpaPdpSubGroup::new, new ArrayList<>(0)); } /** @@ -310,19 +311,4 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> { return PfUtils.compareObjects(pdpSubGroups, other.pdpSubGroups); } - - @Override - public PfConcept copyTo(@NonNull final PfConcept target) { - Assertions.instanceOf(target, JpaPdpGroup.class); - - final JpaPdpGroup copy = ((JpaPdpGroup) target); - copy.setKey(new PfConceptKey(key)); - - copy.setDescription(description); - copy.setPdpGroupState(pdpGroupState); - copy.setProperties(properties == null ? null : new LinkedHashMap<>(properties)); - copy.setPdpSubGroups(PfUtils.mapList(pdpSubGroups, JpaPdpSubGroup::new)); - - return copy; - } } 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 723d427de..3a81c0b30 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,7 +28,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; - import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.ElementCollection; @@ -44,8 +43,6 @@ 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; import org.onap.policy.models.base.PfConcept; @@ -145,6 +142,14 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro */ public JpaPdpSubGroup(@NonNull final JpaPdpSubGroup copyConcept) { super(copyConcept); + this.key = new PfReferenceKey(copyConcept.key); + this.supportedPolicyTypes = PfUtils.mapList(copyConcept.supportedPolicyTypes, + PfConceptKey::new, new ArrayList<>(0)); + this.policies = PfUtils.mapList(copyConcept.policies, PfConceptKey::new, new ArrayList<>(0)); + this.currentInstanceCount = copyConcept.currentInstanceCount; + this.desiredInstanceCount = copyConcept.desiredInstanceCount; + this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null); + this.pdpInstances = PfUtils.mapList(copyConcept.pdpInstances, JpaPdp::new, new ArrayList<>(0)); } /** @@ -393,21 +398,4 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro return PfUtils.compareObjects(pdpInstances, other.pdpInstances); } - - @Override - public PfConcept copyTo(@NonNull final PfConcept target) { - Assertions.instanceOf(target, JpaPdpSubGroup.class); - - final JpaPdpSubGroup copy = ((JpaPdpSubGroup) target); - copy.setKey(new PfReferenceKey(key)); - - copy.setSupportedPolicyTypes(PfUtils.mapList(supportedPolicyTypes, PfConceptKey::new)); - copy.setPolicies(PfUtils.mapList(policies, PfConceptKey::new)); - copy.setCurrentInstanceCount(currentInstanceCount); - copy.setDesiredInstanceCount(desiredInstanceCount); - copy.setProperties(properties == null ? null : new LinkedHashMap<>(properties)); - copy.setPdpInstances(PfUtils.mapList(pdpInstances, JpaPdp::new)); - - return copy; - } } diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java index a2f502bcc..b40c91982 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java @@ -119,9 +119,7 @@ public class JpaPdpGroupTest { testJpaPdpGroup.setKey(new PfConceptKey(PDP_GROUP0, VERSION)); testJpaPdpGroup.fromAuthorative(testPdpGroup); - assertThatThrownBy(() -> { - testJpaPdpGroup.copyTo(null); - }).hasMessage("target is marked @NonNull but is null"); + assertThatThrownBy(() -> new JpaPdpGroup((JpaPdpGroup) null)).isInstanceOf(NullPointerException.class); assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName()); assertEquals(PDP_GROUP0, new JpaPdpGroup(testPdpGroup).getKey().getName()); @@ -230,5 +228,7 @@ public class JpaPdpGroupTest { assertEquals(2, testJpaPdpGroup.getKeys().size()); testJpaPdpGroup.clean(); assertEquals(2, testJpaPdpGroup.getKeys().size()); + + assertEquals(testJpaPdpGroup, new JpaPdpGroup(testJpaPdpGroup)); } } diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java index 981f40f06..ad0164ad4 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java @@ -127,9 +127,7 @@ public class JpaPdpSubGroupTest { testJpaPdpSubGroup.fromAuthorative(null); }).hasMessage("pdpSubgroup is marked @NonNull but is null"); - assertThatThrownBy(() -> { - testJpaPdpSubGroup.copyTo(null); - }).hasMessage("target is marked @NonNull but is null"); + assertThatThrownBy(() -> new JpaPdpSubGroup((JpaPdpSubGroup) null)).isInstanceOf(NullPointerException.class); assertEquals(PDP_A, testJpaPdpSubGroup.getKey().getLocalName()); assertEquals(PDP_A, new JpaPdpSubGroup(testPdpSubgroup).getKey().getLocalName()); @@ -279,5 +277,7 @@ public class JpaPdpSubGroupTest { assertEquals("Prop Value", testJpaPdpSubGroup.getProperties().get("PropKey")); assertEquals(4, testJpaPdpSubGroup.getKeys().size()); + + assertEquals(testJpaPdpSubGroup, new JpaPdpSubGroup(testJpaPdpSubGroup)); } } diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java index 5ffba10b9..b6d5161f8 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java @@ -99,9 +99,7 @@ public class JpaPdpTest { testJpaPdp.fromAuthorative(null); }).hasMessage("pdp is marked @NonNull but is null"); - assertThatThrownBy(() -> { - testJpaPdp.copyTo(null); - }).hasMessage("target is marked @NonNull but is null"); + assertThatThrownBy(() -> new JpaPdp((JpaPdp) null)).isInstanceOf(NullPointerException.class); assertEquals(PDP1, testJpaPdp.getKey().getLocalName()); assertEquals(PDP1, new JpaPdp(testPdp).getKey().getLocalName()); @@ -184,5 +182,7 @@ public class JpaPdpTest { assertEquals(-13, testJpaPdp.compareTo(otherJpaPdp)); testJpaPdp.setMessage("Valid Message"); assertEquals(0, testJpaPdp.compareTo(otherJpaPdp)); + + assertEquals(testJpaPdp, new JpaPdp(testJpaPdp)); } } |