diff options
Diffstat (limited to 'models-provider/src/test')
3 files changed, 49 insertions, 48 deletions
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java index 4356e4b1d..de7b28a60 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java @@ -46,6 +46,7 @@ import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.pdp.enums.PdpHealthStatus; import org.onap.policy.models.pdp.enums.PdpState; +import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; @@ -278,10 +279,6 @@ public class DatabasePolicyModelsProviderTest { }).hasMessageMatching(NAME_IS_NULL); assertThatThrownBy(() -> { - databaseProvider.getFilteredPdpStatistics(NAME, null, "sub", TIMESTAMP, TIMESTAMP, ORDER, 0); - }).hasMessageMatching(GROUP_IS_NULL); - - assertThatThrownBy(() -> { databaseProvider.createPdpStatistics(null); }).hasMessageMatching("^pdpStatisticsList is marked .*on.*ull but is null$"); @@ -426,34 +423,41 @@ public class DatabasePolicyModelsProviderTest { databaseProvider.createPdpStatistics(makePdpStatisticsList()); assertEquals(NAME, databaseProvider.getPdpStatistics(null, null).get(0).getPdpInstanceId()); - assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(null, GROUP, null, - null, null, ORDER, 0).get(0).getPdpInstanceId()); - assertEquals(0, databaseProvider.getFilteredPdpStatistics(null, GROUP, null, - Instant.now(), null, ORDER, 0).size()); - assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(null, GROUP, null, - null, TIMESTAMP, ORDER, 0).get(0).getPdpInstanceId()); - assertEquals(0, - databaseProvider.getFilteredPdpStatistics(null, GROUP, null, Instant.now(), - Instant.now(), ORDER, 0).size()); - - assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, null, null, - null, ORDER, 0).get(0).getPdpInstanceId()); - assertEquals(0, - databaseProvider.getFilteredPdpStatistics(NAME, GROUP, null, Instant.now(), Instant.now(), - ORDER, 0).size()); - - assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", - null, null, ORDER, 0).get(0).getPdpInstanceId()); - - assertEquals(0, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", - Instant.now(), Instant.now(), ORDER, 0).size()); - - assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", - null, null, ORDER, 1).get(0).getPdpInstanceId()); - assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", - null, null, ORDER, 5).get(0).getPdpInstanceId()); - assertEquals(0, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", - Instant.now(), Instant.now(), ORDER, 5).size()); + assertEquals(NAME, databaseProvider.getFilteredPdpStatistics( + PdpFilterParameters.builder().group(GROUP).build()).get(0).getPdpInstanceId()); + assertEquals(0, databaseProvider.getFilteredPdpStatistics( + PdpFilterParameters.builder().group(GROUP).startTime(Instant.now()).build()).size()); + assertEquals(NAME, databaseProvider + .getFilteredPdpStatistics(PdpFilterParameters.builder().group(GROUP).endTime(TIMESTAMP).build()) + .get(0).getPdpInstanceId()); + assertEquals(0, databaseProvider.getFilteredPdpStatistics(PdpFilterParameters.builder().group(GROUP) + .startTime(Instant.now()).endTime(Instant.now()).build()).size()); + + assertEquals(NAME, databaseProvider + .getFilteredPdpStatistics(PdpFilterParameters.builder().name(NAME).group(GROUP).build()).get(0) + .getPdpInstanceId()); + assertEquals(0, databaseProvider.getFilteredPdpStatistics(PdpFilterParameters.builder().name(NAME).group(GROUP) + .startTime(Instant.now()).endTime(Instant.now()).build()).size()); + + assertEquals(NAME, + databaseProvider.getFilteredPdpStatistics( + PdpFilterParameters.builder().name(NAME).group(GROUP).subGroup("type").build()) + .get(0).getPdpInstanceId()); + + assertEquals(0, databaseProvider.getFilteredPdpStatistics( + PdpFilterParameters.builder().name(NAME).group(GROUP).subGroup("type") + .startTime(Instant.now()).endTime(Instant.now()).build()).size()); + + assertEquals(NAME, databaseProvider.getFilteredPdpStatistics( + PdpFilterParameters.builder().name(NAME).group(GROUP).subGroup("type") + .sortOrder(ORDER).recordNum(1).build()).get(0).getPdpInstanceId()); + assertEquals(NAME, databaseProvider.getFilteredPdpStatistics( + PdpFilterParameters.builder().name(NAME).group(GROUP).subGroup("type") + .sortOrder(ORDER).recordNum(5).build()).get(0).getPdpInstanceId()); + assertEquals(0, databaseProvider.getFilteredPdpStatistics( + PdpFilterParameters.builder().name(NAME).group(GROUP).subGroup("type") + .startTime(Instant.now()).endTime(Instant.now()) + .sortOrder(ORDER).recordNum(5).build()).size()); assertEquals(NAME, databaseProvider.deletePdpStatistics(NAME, null).get(0).getPdpInstanceId()); assertEquals(0, databaseProvider.getPdpStatistics(null, null).size()); @@ -549,22 +553,16 @@ public class DatabasePolicyModelsProviderTest { databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); databaseProvider.createAuditRecords(List.of(audit)); - List<PolicyAudit> createdAudits = databaseProvider.getAuditRecords(null, 10); + List<PolicyAudit> createdAudits = databaseProvider.getAuditRecords(AuditFilter.builder().recordNum(10).build()); assertThat(createdAudits).hasSize(1); - createdAudits = databaseProvider.getAuditRecords(AuditFilter.builder().build(), 10); - assertThat(createdAudits).hasSize(1); - - List<PolicyAudit> emptyList = - databaseProvider.getAuditRecords(AuditFilter.builder().action(AuditAction.UNDEPLOYMENT).build(), 10); + List<PolicyAudit> emptyList = databaseProvider + .getAuditRecords(AuditFilter.builder().action(AuditAction.UNDEPLOYMENT).recordNum(10).build()); assertThat(emptyList).isEmpty(); assertThatThrownBy(() -> databaseProvider.createAuditRecords(null)) .hasMessageContaining("audits is marked non-null but is null"); - assertThatThrownBy(() -> databaseProvider.getAuditRecords(null, null)) - .hasMessageContaining("numRecords is marked non-null but is null"); - databaseProvider.close(); } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java index 34cdbff0f..224ef0e85 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java @@ -39,6 +39,7 @@ import org.onap.policy.models.pdp.concepts.PdpGroupFilter; import org.onap.policy.models.pdp.concepts.PdpPolicyStatus; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpSubGroup; +import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; @@ -210,10 +211,9 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public List<PdpStatistics> getFilteredPdpStatistics(String name, String pdpGroupName, String pdpSubGroup, - Instant startTimeStamp, Instant endTimeStamp, String sortOrder, int getRecordNum) { + public List<PdpStatistics> getFilteredPdpStatistics(PdpFilterParameters filterParams) throws PfModelException { // Not implemented - return new ArrayList<>(); + return null; } @Override @@ -273,7 +273,7 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter, @NonNull Integer numRecords) { + public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter) { // Not implemented return null; } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java index de320724a..d7c69bbb2 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java @@ -34,9 +34,11 @@ import java.time.Instant; import java.util.ArrayList; import org.junit.Test; import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter; import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.concepts.PdpGroupFilter; import org.onap.policy.models.pdp.concepts.PdpSubGroup; +import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; @@ -114,8 +116,9 @@ public class DummyPolicyModelsProviderTest { assertTrue(dummyProvider.getPdpStatistics("name", null).isEmpty()); assertTrue( - dummyProvider.getFilteredPdpStatistics("name", null, null, - Instant.now(), Instant.now(), null, 0).isEmpty()); + dummyProvider.getFilteredPdpStatistics( + PdpFilterParameters.builder().name("name") + .startTime(Instant.now()).endTime(Instant.now()).build()).isEmpty()); assertTrue(dummyProvider.createPdpStatistics(null).isEmpty()); assertTrue(dummyProvider.updatePdpStatistics(null).isEmpty()); assertTrue(dummyProvider.deletePdpStatistics(null, Instant.now()).isEmpty()); @@ -127,7 +130,7 @@ public class DummyPolicyModelsProviderTest { assertThatCode(() -> dummyProvider.cudPolicyStatus(null, null, null)).doesNotThrowAnyException(); assertThatCode(() -> dummyProvider.createAuditRecords(null)).doesNotThrowAnyException(); - assertThat(dummyProvider.getAuditRecords(null, 10)).isEmpty(); + assertThat(dummyProvider.getAuditRecords(AuditFilter.builder().recordNum(10).build())).isEmpty(); } @Test |