diff options
Diffstat (limited to 'models-pdp')
21 files changed, 183 insertions, 462 deletions
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 new file mode 100644 index 000000000..b49bedefe --- /dev/null +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java @@ -0,0 +1,74 @@ +/*- + * ============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 java.util.List; +import java.util.stream.Collectors; + +import lombok.Builder; +import lombok.Data; +import lombok.NonNull; + +import org.onap.policy.models.base.PfObjectFiler; +import org.onap.policy.models.pdp.enums.PdpState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; + +/** + * Filter class for searches for {@link PdpGroup} instances. + * If any fields are null, they are ignored. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +@Builder +@Data +public class PdpGroupFilter implements PfObjectFiler<PdpGroup> { + public static final String LATEST_VERSION = "LATEST"; + + // Regular expression + private String name; + + // Regular Expression, set to LATEST_VERRSION to get the latest version + private String version; + + private PdpState groupState; + + // Regular expression + private String pdpType; + + // Set regular expressions on fields to match policy type names and versions + private ToscaPolicyTypeIdentifier policyType; + + // Set regular expressions on fields to match policy names and versions + private ToscaPolicyIdentifier policy; + + @Override + public List<PdpGroup> filter(@NonNull final List<PdpGroup> originalList) { + + // @formatter:off + return originalList.stream() + .filter(p -> name != null && p.getName() .matches(name)) + .filter(p -> version != null && p.getVersion().matches(version)) + .filter(p -> groupState != null && p.getPdpGroupState().equals(groupState)) + .collect(Collectors.toList()); + // @formatter:off + } +} diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java index 6160027ed..a48724e34 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java @@ -29,7 +29,8 @@ import lombok.ToString; import org.onap.policy.models.pdp.enums.PdpMessageType; /** - * Class to represent the base class for various messages that will ve exchanged between PAP and PDP. + * Class to represent the base class for various messages that will be exchanged between + * PAP and PDP. * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ @@ -50,6 +51,24 @@ public class PdpMessage { private long timestampMs = System.currentTimeMillis(); /** + * PDP name, or {@code null} for state-change broadcast messages. + */ + private String name; + + /** + * Group associated with the PDP. For state-change messages, this may be {@code null}, + * if the {@link #name} is provided. + */ + private String pdpGroup; + + /** + * Group associated with the PDP. For state-change messages, this may be {@code null}, + * if the {@link #name} is provided. + */ + private String pdpSubgroup; + + + /** * Constructor for instantiating PdpMessage class with message name. * * @param messageName the message name @@ -57,4 +76,17 @@ public class PdpMessage { public PdpMessage(final PdpMessageType messageName) { this.messageName = messageName; } + + /** + * Constructs the object, making a deep copy. Does <i>not</i> copy the request id or + * the time stamp. + * + * @param source source from which to copy + */ + public PdpMessage(final PdpMessage source) { + this.messageName = source.messageName; + this.name = source.name; + this.pdpGroup = source.pdpGroup; + this.pdpSubgroup = source.pdpSubgroup; + } } diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStateChange.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStateChange.java index d8f938bbc..fe953cb65 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStateChange.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStateChange.java @@ -35,13 +35,10 @@ import org.onap.policy.models.pdp.enums.PdpState; */ @Getter @Setter -@ToString +@ToString(callSuper = true) public class PdpStateChange extends PdpMessage { - private String name; private PdpState state; - private String pdpGroup; - private String pdpSubgroup; /** * Constructor for instantiating PdpStateChange class with message name. @@ -57,11 +54,8 @@ public class PdpStateChange extends PdpMessage { * @param source source from which to copy */ public PdpStateChange(PdpStateChange source) { - super(PdpMessageType.PDP_STATE_CHANGE); + super(source); - this.name = source.name; this.state = source.state; - this.pdpGroup = source.pdpGroup; - this.pdpSubgroup = source.pdpSubgroup; } } diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java index 6f9b9c9d6..36e8d00f8 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java @@ -35,9 +35,10 @@ import lombok.ToString; @ToString public class PdpStatistics { - private long policyDownloadCount; - private long policyDownloadSuccessCount; - private long policyDownloadFailCount; + private String pdpInstanceId; + private long policyDeployCount; + private long policyDeploySuccessCount; + private long policyDeployFailCount; private long policyExecutedCount; private long policyExecutedSuccessCount; private long policyExecutedFailCount; 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 d0fef4503..5858b6acd 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 @@ -22,14 +22,14 @@ package org.onap.policy.models.pdp.concepts; import java.util.List; - import lombok.Getter; import lombok.Setter; import lombok.ToString; - import org.onap.policy.models.pdp.enums.PdpHealthStatus; import org.onap.policy.models.pdp.enums.PdpMessageType; import org.onap.policy.models.pdp.enums.PdpState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; /** * Class to represent the PDP_STATUS message that all the PDP's will send to PAP. @@ -38,20 +38,20 @@ import org.onap.policy.models.pdp.enums.PdpState; */ @Getter @Setter -@ToString +@ToString(callSuper = true) public class PdpStatus extends PdpMessage { - private String name; - private String version; private String pdpType; private PdpState state; private PdpHealthStatus healthy; + + /** + * Description of the PDP or the PDP type. May be left {@code null}. + */ private String description; - private String pdpGroup; - private String pdpSubgroup; + private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes; private List<ToscaPolicyIdentifier> policies; - private String instance; private String deploymentInstanceInfo; private String properties; private PdpStatistics 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 b4f469388..4e5843678 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 @@ -31,6 +31,8 @@ import lombok.Setter; import lombok.ToString; import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; /** * Class to represent a group of all PDP's of the same pdp type running for a particular domain. diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java index 200515cc4..a28bd7640 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java @@ -36,14 +36,15 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; */ @Getter @Setter -@ToString +@ToString(callSuper = true) public class PdpUpdate extends PdpMessage { - private String name; + /** + * Description of the PDP group. + */ private String description; - private String pdpGroup; - private String pdpSubgroup; - private long pdpHeartbeatIntervalMs; + + private Long pdpHeartbeatIntervalMs; private List<ToscaPolicy> policies; /** @@ -60,12 +61,9 @@ public class PdpUpdate extends PdpMessage { * @param source source from which to copy */ public PdpUpdate(PdpUpdate source) { - super(PdpMessageType.PDP_UPDATE); + super(source); - this.name = source.name; this.description = source.description; - this.pdpGroup = source.pdpGroup; - this.pdpSubgroup = source.pdpSubgroup; this.pdpHeartbeatIntervalMs = source.pdpHeartbeatIntervalMs; this.policies = (source.policies == null ? null : source.policies.stream().map(ToscaPolicy::new).collect(Collectors.toList())); diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/ToscaPolicyIdentifierOptVersion.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/ToscaPolicyIdentifierOptVersion.java deleted file mode 100644 index bd6b26ede..000000000 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/ToscaPolicyIdentifierOptVersion.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP Policy Models - * ================================================================================ - * Copyright (C) 2019 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.models.pdp.concepts; - -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; - -/** - * Policy identifier with an optional version; only the "name" is required. - */ -@Data -@NoArgsConstructor -public class ToscaPolicyIdentifierOptVersion { - - @NonNull - private String name; - - private String version; - - - public ToscaPolicyIdentifierOptVersion(@NonNull String name, String version) { - this.name = name; - this.version = version; - } - - public ToscaPolicyIdentifierOptVersion(ToscaPolicyIdentifierOptVersion source) { - this.name = source.name; - this.version = source.version; - } - - /** - * Determines if the version is null/missing. - * - * @return {@code true} if the version is null/missing, {@code false} - */ - public boolean isNullVersion() { - return (version == null); - } -} diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/ToscaPolicyTypeIdentifier.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/ToscaPolicyTypeIdentifier.java deleted file mode 100644 index cf989f3ae..000000000 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/ToscaPolicyTypeIdentifier.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP Policy Models - * ================================================================================ - * Copyright (C) 2019 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.models.pdp.concepts; - -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; - -/** - * Identifies a policy type. Both the name and version must be non-null. - */ -@Data -@NoArgsConstructor -public class ToscaPolicyTypeIdentifier { - - @NonNull - private String name; - - @NonNull - private String version; - - - public ToscaPolicyTypeIdentifier(@NonNull String name, @NonNull String version) { - this.name = name; - this.version = version; - } - - public ToscaPolicyTypeIdentifier(ToscaPolicyTypeIdentifier source) { - this.name = source.name; - this.version = source.version; - } -} 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 7020b4596..1937cbfbb 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.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; @@ -39,11 +38,9 @@ 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.onap.policy.common.utils.validation.Assertions; import org.onap.policy.common.utils.validation.ParameterValidationUtils; import org.onap.policy.models.base.PfAuthorative; @@ -58,9 +55,8 @@ import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.base.PfValidationResult.ValidationResult; import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.concepts.PdpSubGroup; -import org.onap.policy.models.pdp.concepts.ToscaPolicyIdentifier; -import org.onap.policy.models.pdp.concepts.ToscaPolicyTypeIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; /** * Class to represent a PDP subgroup in the database. diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java index 20553d788..a1eb97dd0 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java @@ -21,15 +21,12 @@ package org.onap.policy.models.pdp.persistence.provider; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import javax.ws.rs.core.Response; import lombok.NonNull; -import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; @@ -38,12 +35,12 @@ import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.dao.PfDao; import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.concepts.PdpGroup; +import org.onap.policy.models.pdp.concepts.PdpGroupFilter; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.pdp.persistence.concepts.JpaPdp; import org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup; import org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,7 +67,7 @@ public class PdpProvider { public List<PdpGroup> getPdpGroups(@NonNull final PfDao dao, final String name, final String version) throws PfModelException { - List<JpaPdpGroup> foundPdpGroups = dao.getFiltered(JpaPdpGroup.class, new PfConceptKey(name, version)); + List<JpaPdpGroup> foundPdpGroups = dao.getFiltered(JpaPdpGroup.class, name, version); if (foundPdpGroups != null) { return asPdpGroupList(foundPdpGroups); @@ -90,29 +87,31 @@ public class PdpProvider { * @throws PfModelException on errors getting policies */ public List<PdpGroup> getLatestPdpGroups(@NonNull final PfDao dao, final String name) throws PfModelException { - List<JpaPdpGroup> returnList = new ArrayList<>(); + List<JpaPdpGroup> jpaPdpGroupList = new ArrayList<>(); if (name == null) { - returnList.add(dao.getLatestVersion(JpaPdpGroup.class, name)); - } - else { - returnList.addAll(dao.getLatestVersions(JpaPdpGroup.class)); + jpaPdpGroupList.addAll(dao.getAll(JpaPdpGroup.class)); + } else { + jpaPdpGroupList.addAll(dao.getAllVersions(JpaPdpGroup.class, name)); } - return asPdpGroupList(returnList); + return asPdpGroupList(jpaPdpGroupList); } /** - * Get a filtered list of PDP groups, returns only active PDP groups. + * Get filtered PDP groups. * * @param dao the DAO to use to access the database - * @param pdpType The PDP type filter for the returned PDP groups, null to get policy types across PDP subgroups - * @param supportedPolicyTypes a list of policy type name/version pairs that the PDP groups must support. + * @param filter the filter for the PDP groups to get * @return the PDP groups found + * @throws PfModelException on errors getting policies */ - public List<PdpGroup> getFilteredPdpGroups(@NonNull final PfDao dao, final String pdpType, - @NonNull final List<Pair<String, String>> supportedPolicyTypes) { - return new ArrayList<>(); + public List<PdpGroup> getFilteredPdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroupFilter filter) + throws PfModelException { + + List<JpaPdpGroup> jpaPdpGroupList = dao.getAll(JpaPdpGroup.class); + + return asPdpGroupList(jpaPdpGroupList); } /** @@ -308,19 +307,6 @@ public class PdpProvider { } /** - * Get deployed policies. - * - * @param dao the DAO to use to access the database - * @param name the name of the policy to get deployed policies for, null to get all deployed policies - * @return the policies deployed as a map of policy lists keyed by PDP group name and version - * @throws PfModelException on errors getting policies - */ - public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(@NonNull final PfDao dao, - final String name) throws PfModelException { - return new LinkedHashMap<>(); - } - - /** * Convert JPA PDP group list to an authorative PDP group list. * * @param foundPdpGroups the list to convert diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/ToscaPolicyIdentifier.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java index 245806c71..ee7e15b6a 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/ToscaPolicyIdentifier.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java @@ -20,31 +20,12 @@ package org.onap.policy.models.pdp.concepts; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; - /** - * Identifies a policy. Both the name and version must be non-null. + * Utility class for tests of PdpMessage subclasses. */ -@Data -@NoArgsConstructor -public class ToscaPolicyIdentifier { - - @NonNull - private String name; - - @NonNull - private String version; - - - public ToscaPolicyIdentifier(@NonNull String name, @NonNull String version) { - this.name = name; - this.version = version; - } +public class PdpMessageUtils { - public ToscaPolicyIdentifier(ToscaPolicyIdentifier source) { - this.name = source.name; - this.version = source.version; + public static String removeVariableFields(String text) { + return text.replaceAll("requestId=[^,]*", "requestId=xxx").replaceAll("timestampMs=[^,]*", "timestampMs=nnn"); } } diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java index 39aee6f48..1813dde7d 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java @@ -38,7 +38,7 @@ import org.onap.policy.common.utils.validation.ToStringTester; public class TestModels { @Test - public void testPapModels() { + public void testPdpModels() { final Validator validator = ValidatorBuilder.create().with(new ToStringTester()).with(new SetterTester()) .with(new GetterTester()).build(); validator.validate(TestModels.class.getPackage().getName(), new FilterPackageInfo()); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifier.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java index 7a09e9d44..515c48385 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifier.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java @@ -1,8 +1,9 @@ -/* +/*- * ============LICENSE_START======================================================= * ONAP Policy Models * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications 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. @@ -24,39 +25,33 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import org.junit.Test; +import org.onap.policy.models.pdp.enums.PdpMessageType; /** - * Test the other constructors, as {@link TestModels} tests the other methods. + * Test the copy constructor, as {@link TestModels} tests the other methods. */ -public class TestToscaPolicyIdentifier extends ToscaIdentifierTestBase<ToscaPolicyIdentifier> { - private static final String NAME = "my-name"; - private static final String VERSION = "1.2.3"; - - public TestToscaPolicyIdentifier() { - super(ToscaPolicyIdentifier.class); - } - - @Test - public void testAllArgsConstructor() { - assertThatThrownBy(() -> new ToscaPolicyIdentifier(null, VERSION)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> new ToscaPolicyIdentifier(NAME, null)).isInstanceOf(NullPointerException.class); - - ToscaPolicyIdentifier orig = new ToscaPolicyIdentifier(NAME, VERSION); - assertEquals(NAME, orig.getName()); - assertEquals(VERSION, orig.getVersion()); - } +public class TestPdpMessage { @Test public void testCopyConstructor() { - assertThatThrownBy(() -> new ToscaPolicyIdentifier(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> new PdpMessage((PdpMessage) null)).isInstanceOf(NullPointerException.class); - ToscaPolicyIdentifier orig = new ToscaPolicyIdentifier(); + PdpMessage orig = new PdpMessage(PdpMessageType.PDP_STATE_CHANGE); // verify with null values - assertEquals(orig.toString(), new ToscaPolicyIdentifier(orig).toString()); + PdpMessage newmsg = new PdpMessage(orig); + newmsg.setRequestId(orig.getRequestId()); + newmsg.setTimestampMs(orig.getTimestampMs()); + assertEquals(orig.toString(), newmsg.toString()); // verify with all values - orig = new ToscaPolicyIdentifier(NAME, VERSION); - assertEquals(orig.toString(), new ToscaPolicyIdentifier(orig).toString()); + orig.setName("my-name"); + orig.setPdpGroup("my-group"); + orig.setPdpSubgroup("my-subgroup"); + + newmsg = new PdpMessage(orig); + newmsg.setRequestId(orig.getRequestId()); + newmsg.setTimestampMs(orig.getTimestampMs()); + assertEquals(orig.toString(), newmsg.toString()); } } diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java index 8c843a1ac..55eaedc26 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java @@ -23,6 +23,7 @@ package org.onap.policy.models.pdp.concepts; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; +import static org.onap.policy.models.pdp.concepts.PdpMessageUtils.removeVariableFields; import org.junit.Test; import org.onap.policy.models.pdp.enums.PdpState; @@ -39,8 +40,7 @@ public class TestPdpStateChange { PdpStateChange orig = new PdpStateChange(); // verify with null values - assertEquals("PdpStateChange(name=null, state=null, pdpGroup=null, pdpSubgroup=null)", - new PdpStateChange(orig).toString()); + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpStateChange(orig).toString())); // verify with all values orig.setName("my-name"); @@ -48,7 +48,6 @@ public class TestPdpStateChange { orig.setPdpSubgroup("my-subgroup"); orig.setState(PdpState.SAFE); - assertEquals("PdpStateChange(name=my-name, state=SAFE, pdpGroup=my-group, pdpSubgroup=my-subgroup)", - new PdpStateChange(orig).toString()); + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpStateChange(orig).toString())); } } diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java index 2580ca829..c80745d76 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java @@ -29,6 +29,8 @@ import java.util.Map; import java.util.TreeMap; import org.junit.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; /** * Test the copy constructor, as {@link TestModels} tests the other methods. diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java index d2b571f34..b366088d1 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java @@ -24,6 +24,7 @@ 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 static org.onap.policy.models.pdp.concepts.PdpMessageUtils.removeVariableFields; import java.util.Arrays; import java.util.List; @@ -42,15 +43,14 @@ public class TestPdpUpdate { PdpUpdate orig = new PdpUpdate(); // verify with null values - assertEquals("PdpUpdate(name=null, description=null, pdpGroup=null, pdpSubgroup=null, " - + "pdpHeartbeatIntervalMs=0, policies=null)", new PdpUpdate(orig).toString()); + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpUpdate(orig).toString())); // verify with all values orig.setDescription("my-description"); orig.setName("my-name"); orig.setPdpGroup("my-group"); orig.setPdpSubgroup("my-subgroup"); - orig.setPdpHeartbeatIntervalMs(30000); + orig.setPdpHeartbeatIntervalMs(30000L); ToscaPolicy policy1 = new ToscaPolicy(); policy1.setName("policy-a"); @@ -65,13 +65,7 @@ public class TestPdpUpdate { PdpUpdate other = new PdpUpdate(orig); - assertEquals("PdpUpdate(name=my-name, description=my-description, " - + "pdpGroup=my-group, pdpSubgroup=my-subgroup, pdpHeartbeatIntervalMs=30000, policies=[" - + "ToscaPolicy(super=ToscaEntity(name=policy-a, version=1.2.3, derivedFrom=null, " - + "metadata=null, description=null), type=null, typeVersion=null, properties=null), " - + "ToscaPolicy(super=ToscaEntity(name=policy-b, version=4.5.6, derivedFrom=null, " - + "metadata=null, description=null), type=null, typeVersion=null, properties=null)])", - other.toString()); + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); // ensure list and items are not the same object assertTrue(other.getPolicies() != policies); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifierOptVersion.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifierOptVersion.java deleted file mode 100644 index c4e9278eb..000000000 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifierOptVersion.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP Policy Models - * ================================================================================ - * Copyright (C) 2019 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.models.pdp.concepts; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -/** - * Test the other constructors, as {@link TestModels} tests the other methods. - */ -public class TestToscaPolicyIdentifierOptVersion extends ToscaIdentifierTestBase<ToscaPolicyIdentifierOptVersion> { - private static final String NAME = "my-name"; - private static final String VERSION = "1.2.3"; - - public TestToscaPolicyIdentifierOptVersion() { - super(ToscaPolicyIdentifierOptVersion.class); - } - - @Test - public void testAllArgsConstructor_testIsNullVersion() { - assertThatThrownBy(() -> new ToscaPolicyIdentifierOptVersion(null, VERSION)) - .isInstanceOf(NullPointerException.class); - - // with null version - ToscaPolicyIdentifierOptVersion orig = new ToscaPolicyIdentifierOptVersion(NAME, null); - assertEquals(NAME, orig.getName()); - assertEquals(null, orig.getVersion()); - assertTrue(orig.isNullVersion()); - - orig = new ToscaPolicyIdentifierOptVersion(NAME, VERSION); - assertEquals(NAME, orig.getName()); - assertEquals(VERSION, orig.getVersion()); - assertFalse(orig.isNullVersion()); - } - - @Test - public void testCopyConstructor() throws Exception { - assertThatThrownBy(() -> new ToscaPolicyIdentifierOptVersion(null)).isInstanceOf(NullPointerException.class); - - ToscaPolicyIdentifierOptVersion orig = new ToscaPolicyIdentifierOptVersion(); - - // verify with null values - assertEquals(orig.toString(), new ToscaPolicyIdentifierOptVersion(orig).toString()); - - // verify with all values - orig = makeIdent(NAME, VERSION); - assertEquals(orig.toString(), new ToscaPolicyIdentifierOptVersion(orig).toString()); - } -} diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyTypeIdentifier.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyTypeIdentifier.java deleted file mode 100644 index ab314ef12..000000000 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyTypeIdentifier.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP Policy Models - * ================================================================================ - * Copyright (C) 2019 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.models.pdp.concepts; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Test the other constructors, as {@link TestModels} tests the other methods. - */ -public class TestToscaPolicyTypeIdentifier extends ToscaIdentifierTestBase<ToscaPolicyTypeIdentifier> { - private static final String NAME = "my-name"; - private static final String VERSION = "1.2.3"; - - public TestToscaPolicyTypeIdentifier() { - super(ToscaPolicyTypeIdentifier.class); - } - - @Test - public void testAllArgsConstructor() { - assertThatThrownBy(() -> new ToscaPolicyTypeIdentifier(null, VERSION)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> new ToscaPolicyTypeIdentifier(NAME, null)).isInstanceOf(NullPointerException.class); - - ToscaPolicyTypeIdentifier orig = new ToscaPolicyTypeIdentifier(NAME, VERSION); - assertEquals(NAME, orig.getName()); - assertEquals(VERSION, orig.getVersion()); - } - - @Test - public void testCopyConstructor() { - assertThatThrownBy(() -> new ToscaPolicyTypeIdentifier(null)).isInstanceOf(NullPointerException.class); - - ToscaPolicyTypeIdentifier orig = new ToscaPolicyTypeIdentifier(); - - // verify with null values - assertEquals(orig.toString(), new ToscaPolicyTypeIdentifier(orig).toString()); - - // verify with all values - orig = new ToscaPolicyTypeIdentifier(NAME, VERSION); - assertEquals(orig.toString(), new ToscaPolicyTypeIdentifier(orig).toString()); - } - -} diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ToscaIdentifierTestBase.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ToscaIdentifierTestBase.java deleted file mode 100644 index 8b6a4f7bb..000000000 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ToscaIdentifierTestBase.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP Policy Models - * ================================================================================ - * Copyright (C) 2019 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.models.pdp.concepts; - -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; - -/** - * Super class to test identity keys. - * - * @param <T> type of key being tested - */ -public class ToscaIdentifierTestBase<T> { - - private static final Coder coder = new StandardCoder(); - - private final Class<T> clazz; - - - /** - * Constructs the object. - * @param clazz the type of class being tested - */ - public ToscaIdentifierTestBase(Class<T> clazz) { - this.clazz = clazz; - } - - /** - * Makes an identifier. Uses JSON which does no error checking. - * - * @param name name to put into the identifier - * @param version version to put into the identifier - * @return a new identifier - * @throws CoderException if the JSON cannot be decoded - */ - public T makeIdent(String name, String version) throws CoderException { - StringBuilder bldr = new StringBuilder(); - bldr.append("{"); - - if (name != null) { - bldr.append("'name':'"); - bldr.append(name); - bldr.append("'"); - } - - if (version != null) { - if (name != null) { - bldr.append(','); - } - - bldr.append("'version':'"); - bldr.append(version); - bldr.append("'"); - } - - bldr.append("}"); - - String json = bldr.toString().replace('\'', '"'); - - return coder.decode(json, clazz); - } -} diff --git a/models-pdp/src/test/java/org/onap/policy/models/persistence/provider/PdpProviderTest.java b/models-pdp/src/test/java/org/onap/policy/models/persistence/provider/PdpProviderTest.java index fcb9062c6..6f20882f4 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/persistence/provider/PdpProviderTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/persistence/provider/PdpProviderTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 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. @@ -24,10 +25,6 @@ import static org.junit.Assert.assertEquals; import java.sql.Connection; import java.sql.DriverManager; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -37,15 +34,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.concepts.PdpSubGroup; -import org.onap.policy.models.pdp.concepts.ToscaPolicyTypeIdentifier; -import org.onap.policy.models.pdp.enums.PdpHealthStatus; -import org.onap.policy.models.pdp.enums.PdpState; import org.onap.policy.models.pdp.persistence.provider.PdpProvider; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider; /** * Test the {@link SimpleToscaProvider} class. @@ -110,7 +101,6 @@ public class PdpProviderTest { String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json"); - @SuppressWarnings("unchecked") PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class); PdpGroups createdPdpGroups0 = new PdpGroups(); |