summaryrefslogtreecommitdiffstats
path: root/models-pdp/src/main/java/org/onap
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-04-09 11:55:57 +0000
committerliamfallon <liam.fallon@est.tech>2019-04-09 11:55:57 +0000
commit9ede89131044d171187c5be906aefee615a0e568 (patch)
treed77966aa7aa12ea520bacdbe835355ba20cccb65 /models-pdp/src/main/java/org/onap
parentc54b9408a10c0060e35be2ee0b5bac6a24e9153a (diff)
Complete unit test for models-pdp
This review completes the unit test for the models-pdp module, for persistence of PDP groups and for PDP group filtering. Added unit test of filters for TOSCA policy types and policies. Added fix to allow filters to pass when the value being checked is null. Issue-ID: POLICY-1095 Change-Id: I982400ef39f0282d813d49e484a58207e03b8a63 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-pdp/src/main/java/org/onap')
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java5
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java53
2 files changed, 11 insertions, 47 deletions
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 20e43f0b5..f0ff4a6c2 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
@@ -290,12 +290,12 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro
if (currentInstanceCount < 0) {
result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "the current instance count of a PDP group may not be negative"));
+ "the current instance count of a PDP sub group may not be negative"));
}
if (desiredInstanceCount < 0) {
result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "the desired instance count of a PDP group may not be negative"));
+ "the desired instance count of a PDP sub group may not be negative"));
}
if (properties != null) {
@@ -311,7 +311,6 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro
}
}
-
return validateSubConcepts(result);
}
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 bef3f1547..bfdeda984 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
@@ -67,35 +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, name, version);
-
- if (foundPdpGroups != null) {
- return asPdpGroupList(foundPdpGroups);
- } else {
- String errorMessage = "no PDP groups found for filter " + name + ":" + version;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
- }
- }
-
- /**
- * Get latest PDP Groups, returns PDP groups in all states.
- *
- * @param dao the DAO to use to access the database
- * @param name the name of the PDP group to get, null to get all PDP groups
- * @return the PDP groups found
- * @throws PfModelException on errors getting policies
- */
- public List<PdpGroup> getLatestPdpGroups(@NonNull final PfDao dao, final String name) throws PfModelException {
- List<JpaPdpGroup> jpaPdpGroupList = new ArrayList<>();
-
- if (name == null) {
- jpaPdpGroupList.addAll(dao.getAll(JpaPdpGroup.class));
- } else {
- jpaPdpGroupList.addAll(dao.getAllVersions(JpaPdpGroup.class, name));
- }
-
- return asPdpGroupList(jpaPdpGroupList);
+ return asPdpGroupList(dao.getFiltered(JpaPdpGroup.class, name, version));
}
/**
@@ -106,8 +78,7 @@ public class PdpProvider {
* @return the PDP groups found
* @throws PfModelException on errors getting policies
*/
- public List<PdpGroup> getFilteredPdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroupFilter filter)
- throws PfModelException {
+ public List<PdpGroup> getFilteredPdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroupFilter filter) {
List<JpaPdpGroup> jpaPdpGroupList = dao.getAll(JpaPdpGroup.class);
@@ -211,10 +182,7 @@ public class PdpProvider {
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
}
- if (dao.update(jpaPdpSubgroup) == null) {
- String errorMessage = "update of PDP subgroup \"" + jpaPdpSubgroup.getId() + "\" failed";
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
- }
+ dao.update(jpaPdpSubgroup);
}
/**
@@ -228,8 +196,7 @@ public class PdpProvider {
* @throws PfModelException on errors updating PDP subgroups
*/
public void updatePdp(@NonNull final PfDao dao, @NonNull final String pdpGroupName,
- @NonNull final String pdpGroupVersion, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp)
- throws PfModelException {
+ @NonNull final String pdpGroupVersion, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp) {
final PfReferenceKey pdpKey =
new PfReferenceKey(pdpGroupName, pdpGroupVersion, pdpSubGroup, pdp.getInstanceId());
@@ -243,10 +210,7 @@ public class PdpProvider {
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
}
- if (dao.update(jpaPdp) == null) {
- String errorMessage = "update of PDP \"" + jpaPdp.getId() + "\" failed";
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
- }
+ dao.update(jpaPdp);
}
/**
@@ -258,8 +222,8 @@ public class PdpProvider {
* @return the PDP group deleted
* @throws PfModelException on errors deleting PDP groups
*/
- public PdpGroup deletePdpGroup(@NonNull final PfDao dao, @NonNull final String name, @NonNull final String version)
- throws PfModelException {
+ public PdpGroup deletePdpGroup(@NonNull final PfDao dao, @NonNull final String name,
+ @NonNull final String version) {
PfConceptKey pdpGroupKey = new PfConceptKey(name, version);
@@ -298,11 +262,12 @@ public class PdpProvider {
* @param pdpGroupVersion the version of the PDP group containing the PDP that the statistics are for
* @param pdpType the PDP type of the subgroup containing the PDP that the statistics are for
* @param pdpInstanceId the instance ID of the PDP to update statistics for
+ * @param pdpStatistics the statistics to update
* @throws PfModelException on errors updating statistics
*/
public void updatePdpStatistics(@NonNull final PfDao dao, @NonNull final String pdpGroupName,
@NonNull final String pdpGroupVersion, @NonNull final String pdpType, @NonNull final String pdpInstanceId,
- @NonNull final PdpStatistics pdppStatistics) throws PfModelException {
+ @NonNull final PdpStatistics pdpStatistics) throws PfModelException {
// Not implemented yet
}