diff options
author | Liam Fallon <liam.fallon@est.tech> | 2021-06-03 21:09:07 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-06-03 21:09:07 +0000 |
commit | 1b460194bc034443ba57fa690d294131836a3e9e (patch) | |
tree | 71f3ef59d079432988b42f83ca6fe045aabfb16b /models-pap/src | |
parent | 2baa6495f0b562afc15bc30823ba97c2306f45cd (diff) | |
parent | d72a2ab96255ccc7a9c3a3506eab5509cbcf9ac9 (diff) |
Merge "Exposing the Audit provider through Models provider."
Diffstat (limited to 'models-pap/src')
2 files changed, 32 insertions, 2 deletions
diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProvider.java b/models-pap/src/main/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProvider.java index c117beefa..8923fb23f 100644 --- a/models-pap/src/main/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProvider.java +++ b/models-pap/src/main/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProvider.java @@ -59,7 +59,7 @@ public class PolicyAuditProvider { BeanValidationResult result = new BeanValidationResult("createAuditRecords", jpaAudits); int count = 0; - for (JpaPolicyAudit jpaAudit: jpaAudits) { + for (JpaPolicyAudit jpaAudit : jpaAudits) { result.addResult(jpaAudit.validate(String.valueOf(count++))); } @@ -126,12 +126,22 @@ public class PolicyAuditProvider { */ @Data @Builder - protected static class AuditFilter { + public static class AuditFilter { private String name; private String version; private AuditAction action; private String pdpGroup; private Instant fromDate; private Instant toDate; + + /** + * Check if even still using build(), none of the params were provided. + * + * @return {@code true} if all empty/null; {@code false} otherwise. + */ + public boolean isEmpty() { + return StringUtils.isAllEmpty(name, version, pdpGroup) && action == null && fromDate == null + && toDate == null; + } } } diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProviderTest.java b/models-pap/src/test/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProviderTest.java index da231dc7b..228a3fc01 100644 --- a/models-pap/src/test/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProviderTest.java +++ b/models-pap/src/test/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProviderTest.java @@ -23,6 +23,7 @@ package org.onap.policy.models.pap.persistence.provider; import static org.assertj.core.api.Assertions.assertThat; 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.assertThrows; import static org.junit.Assert.assertTrue; @@ -217,6 +218,25 @@ public class PolicyAuditProviderTest { }).hasMessageMatching(String.format(FIELD_IS_NULL, "auditFilter")); } + @Test + public void testAuditFiltersIsEmpty() { + AuditFilter emptyFilter = AuditFilter.builder().build(); + assertTrue(emptyFilter.isEmpty()); + + AuditFilter stringsEmpty = + AuditFilter.builder().action(AuditAction.DEPLOYMENT).fromDate(Instant.MIN).toDate(Instant.MAX).build(); + assertFalse(stringsEmpty.isEmpty()); + + AuditFilter filter = AuditFilter.builder().fromDate(Instant.MIN).toDate(Instant.MAX).build(); + assertFalse(filter.isEmpty()); + filter = AuditFilter.builder().fromDate(Instant.MIN).build(); + assertFalse(filter.isEmpty()); + filter = AuditFilter.builder().toDate(Instant.MAX).build(); + assertFalse(filter.isEmpty()); + filter = AuditFilter.builder().name("myPolicy").toDate(Instant.MAX).build(); + assertFalse(filter.isEmpty()); + } + private List<PolicyAudit> generatePolicyAudits(Instant date, String group, ToscaConceptIdentifier policy) { // @formatter:off PolicyAudit deploy = PolicyAudit.builder() |