diff options
Diffstat (limited to 'models-provider/src/test/java')
2 files changed, 40 insertions, 22 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 02481ca12..fd566a52f 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 @@ -31,7 +31,6 @@ import java.util.ArrayList; import java.util.Base64; import java.util.Date; import java.util.List; - import org.junit.Before; import org.junit.Test; import org.onap.policy.models.pdp.concepts.Pdp; @@ -81,6 +80,8 @@ public class DatabasePolicyModelsProviderTest { private static final Date TIMESTAMP = new Date(); + private static final String ORDER = "DESC"; + private static final Logger LOGGER = LoggerFactory.getLogger(DatabasePolicyModelsProviderTest.class); PolicyModelsProviderParameters parameters; @@ -326,7 +327,7 @@ public class DatabasePolicyModelsProviderTest { }).hasMessageMatching(NAME_IS_NULL); assertThatThrownBy(() -> { - databaseProvider.getFilteredPdpStatistics(NAME, null, "sub", TIMESTAMP, TIMESTAMP); + databaseProvider.getFilteredPdpStatistics(NAME, null, "sub", TIMESTAMP, TIMESTAMP, ORDER, 0); }).hasMessageMatching(GROUP_IS_NULL); assertThatThrownBy(() -> { @@ -467,9 +468,10 @@ public class DatabasePolicyModelsProviderTest { pdpSubGroup.getPdpInstances().add(pdp); PdpStatistics pdpStatistics = new PdpStatistics(); - pdpStatistics.setPdpInstanceId("Pdp1"); + pdpStatistics.setPdpInstanceId(NAME); pdpStatistics.setTimeStamp(new Date()); - pdpStatistics.setPdpGroupName("DefaultGroup"); + pdpStatistics.setPdpGroupName(GROUP); + pdpStatistics.setPdpSubGroupName("type"); ArrayList<PdpStatistics> statisticsArrayList = new ArrayList<>(); statisticsArrayList.add(pdpStatistics); @@ -496,22 +498,38 @@ public class DatabasePolicyModelsProviderTest { assertEquals(pdpGroup.getName(), databaseProvider.deletePdpGroup(GROUP).getName()); assertEquals(0, databaseProvider.getPdpStatistics(null, null).size()); - - databaseProvider.getFilteredPdpStatistics(null, GROUP, null, null, null); - databaseProvider.getFilteredPdpStatistics(null, GROUP, null, new Date(), null); - databaseProvider.getFilteredPdpStatistics(null, GROUP, null, null, new Date()); - databaseProvider.getFilteredPdpStatistics(null, GROUP, null, new Date(), new Date()); - - databaseProvider.getFilteredPdpStatistics(NAME, GROUP, null, null, null); - databaseProvider.getFilteredPdpStatistics(NAME, GROUP, null, new Date(), new Date()); - - databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", null, null); - databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", new Date(), new Date()); - - databaseProvider.createPdpStatistics(statisticsArrayList); - databaseProvider.updatePdpStatistics(statisticsArrayList); - - databaseProvider.deletePdpStatistics("pdp1", null); + assertEquals(1, databaseProvider.createPdpStatistics(statisticsArrayList).size()); + assertEquals(1, databaseProvider.updatePdpStatistics(statisticsArrayList).size()); + + 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, new Date(), null, ORDER, 0).size()); + assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(null, GROUP, null, null, new Date(), ORDER, 0) + .get(0).getPdpInstanceId()); + assertEquals(0, databaseProvider + .getFilteredPdpStatistics(null, GROUP, null, new Date(), new Date(), ORDER, 0).size()); + + assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, null, null, null, ORDER, 0).get(0) + .getPdpInstanceId()); + assertEquals(0, databaseProvider + .getFilteredPdpStatistics(NAME, GROUP, null, new Date(), new Date(), ORDER, 0).size()); + + assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", null, null, ORDER, 0) + .get(0).getPdpInstanceId()); + assertEquals(0, databaseProvider + .getFilteredPdpStatistics(NAME, GROUP, "type", new Date(), new Date(), 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", new Date(), new Date(), ORDER, 5).size()); + + assertEquals(NAME, databaseProvider.deletePdpStatistics(NAME, null).get(0).getPdpInstanceId()); + assertEquals(0, databaseProvider.getPdpStatistics(null, null).size()); } catch (Exception exc) { LOGGER.warn("test should not throw an exception", exc); fail("test should not throw an exception"); 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 d809f66ba..73940a6b3 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -230,7 +230,7 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { @Override public List<PdpStatistics> getFilteredPdpStatistics(String name, String pdpGroupName, String pdpSubGroup, - Date startTimeStamp, Date endTimeStamp) { + Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) { // Not implemented return new ArrayList<>(); } |