From 8cbad257df2d5f5c585ce37e61cfd16e402be738 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Thu, 10 Jun 2021 17:38:58 -0400 Subject: Fix sonars in policy-models Fixed: - too many parameters in method call Fixed it by introducing PfFilterParameters. However, classes having the Builder annotation are not easily subclassed, so introduced an interface, too. Issue-ID: POLICY-3094 Change-Id: Ida99522a542b1296b367c55b7e8f8e83783c2e4f Signed-off-by: Jim Hahn --- .../provider/PolicyAuditProviderTest.java | 34 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'models-pap/src/test/java') 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 228a3fc01..0540d4844 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 @@ -134,7 +134,37 @@ public class PolicyAuditProviderTest { PolicyAuditProvider provider = new PolicyAuditProvider(); Instant date = Instant.now().truncatedTo(ChronoUnit.SECONDS); - System.out.println(date); + provider.createAuditRecords(pfDao, generatePolicyAudits(date, GROUP_A, MY_POLICY)); + provider.createAuditRecords(pfDao, generatePolicyAudits(date, GROUP_B, MY_POLICY)); + provider.createAuditRecords(pfDao, generatePolicyAudits(date, GROUP_B, MY_POLICY2)); + Awaitility.await().pollDelay(3, TimeUnit.SECONDS).until(() -> { + return true; + }); + + List records = provider.getAuditRecords(pfDao, + AuditFilter.builder().fromDate(date).toDate(Instant.now()).recordNum(NUMBER_RECORDS).build()); + assertThat(records).hasSize(6); + + List recordsWithGroupB = + provider.getAuditRecords(pfDao, + AuditFilter.builder().pdpGroup(GROUP_B).recordNum(NUMBER_RECORDS).build()); + assertThat(recordsWithGroupB).hasSize(4); + + List recordsWithActionDeploy = provider.getAuditRecords(pfDao, + AuditFilter.builder().action(AuditAction.DEPLOYMENT).recordNum(NUMBER_RECORDS).build()); + assertThat(recordsWithActionDeploy).hasSize(3); + + List recordsWithMyPolicy = provider.getAuditRecords(pfDao, + AuditFilter.builder().name(MY_POLICY.getName()).version(MY_POLICY.getVersion()) + .recordNum(NUMBER_RECORDS).build()); + assertThat(recordsWithMyPolicy).hasSize(4); + } + + @Test + public void testFiltersOld() { + PolicyAuditProvider provider = new PolicyAuditProvider(); + + Instant date = Instant.now().truncatedTo(ChronoUnit.SECONDS); provider.createAuditRecords(pfDao, generatePolicyAudits(date, GROUP_A, MY_POLICY)); provider.createAuditRecords(pfDao, generatePolicyAudits(date, GROUP_B, MY_POLICY)); provider.createAuditRecords(pfDao, generatePolicyAudits(date, GROUP_B, MY_POLICY2)); @@ -202,7 +232,7 @@ public class PolicyAuditProviderTest { }).hasMessageMatching(String.format(FIELD_IS_NULL, "dao")); assertThatThrownBy(() -> { - provider.getAuditRecords(pfDao, null); + provider.getAuditRecords(pfDao, (Integer) null); }).hasMessageMatching(String.format(FIELD_IS_NULL, "numRecords")); assertThatThrownBy(() -> { -- cgit 1.2.3-korg