diff options
Diffstat (limited to 'models-provider/src')
6 files changed, 54 insertions, 46 deletions
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java index 3bf81adf7..3af069e24 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java @@ -22,8 +22,8 @@ package org.onap.policy.models.provider; +import java.time.Instant; import java.util.Collection; -import java.util.Date; import java.util.List; import lombok.NonNull; import org.onap.policy.models.base.PfModelException; @@ -324,7 +324,7 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the statistics found * @throws PfModelException on errors getting statistics */ - public List<PdpStatistics> getPdpStatistics(final String name, final Date timestamp) throws PfModelException; + public List<PdpStatistics> getPdpStatistics(final String name, final Instant timestamp) throws PfModelException; /** @@ -341,7 +341,7 @@ public interface PolicyModelsProvider extends AutoCloseable { * @throws PfModelException on errors getting policies */ public List<PdpStatistics> getFilteredPdpStatistics(String name, @NonNull String pdpGroupName, String pdpSubGroup, - Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) throws PfModelException; + Instant startTimeStamp, Instant endTimeStamp, String sortOrder, int getRecordNum) throws PfModelException; /** * Creates PDP statistics. @@ -371,7 +371,7 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the PDP statistics deleted * @throws PfModelException on errors deleting PDP statistics */ - public List<PdpStatistics> deletePdpStatistics(@NonNull String name, Date timestamp) throws PfModelException; + public List<PdpStatistics> deletePdpStatistics(@NonNull String name, Instant timestamp) throws PfModelException; /** * Gets all policy deployments. diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java index 8c7c5122b..1839604aa 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java @@ -22,8 +22,8 @@ package org.onap.policy.models.provider.impl; +import java.time.Instant; import java.util.Collection; -import java.util.Date; import java.util.List; import javax.ws.rs.core.Response; import lombok.NonNull; @@ -247,15 +247,16 @@ public class DatabasePolicyModelsProviderImpl extends AbstractModelsProvider imp } @Override - public List<PdpStatistics> getPdpStatistics(final String name, final Date timestamp) throws PfModelException { + public List<PdpStatistics> getPdpStatistics(final String name, final Instant timestamp) throws PfModelException { assertInitialized(); return new PdpStatisticsProvider().getPdpStatistics(getPfDao(), name, timestamp); } @Override public List<PdpStatistics> getFilteredPdpStatistics(final String name, @NonNull final String pdpGroupName, - final String pdpSubGroup, final Date startTimeStamp, final Date endTimeStamp, final String sortOrder, - final int getRecordNum) throws PfModelException { + final String pdpSubGroup, final Instant startTimeStamp, + final Instant endTimeStamp, final String sortOrder, + final int getRecordNum) throws PfModelException { assertInitialized(); return new PdpStatisticsProvider().getFilteredPdpStatistics(getPfDao(), name, pdpGroupName, pdpSubGroup, startTimeStamp, endTimeStamp, sortOrder, getRecordNum); @@ -276,7 +277,7 @@ public class DatabasePolicyModelsProviderImpl extends AbstractModelsProvider imp } @Override - public List<PdpStatistics> deletePdpStatistics(@NonNull final String name, final Date timestamp) + public List<PdpStatistics> deletePdpStatistics(@NonNull final String name, final Instant timestamp) throws PfModelException { assertInitialized(); return new PdpStatisticsProvider().deletePdpStatistics(getPfDao(), name, timestamp); diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java index 1b91f07c6..07617aad9 100644 --- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java +++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java @@ -22,9 +22,9 @@ package org.onap.policy.models.provider.impl; +import java.time.Instant; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.List; import javax.ws.rs.core.Response; import lombok.NonNull; @@ -211,13 +211,13 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public List<PdpStatistics> getPdpStatistics(final String name, final Date timestamp) throws PfModelException { + public List<PdpStatistics> getPdpStatistics(final String name, final Instant timestamp) throws PfModelException { return new ArrayList<>(); } @Override public List<PdpStatistics> getFilteredPdpStatistics(String name, String pdpGroupName, String pdpSubGroup, - Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) { + Instant startTimeStamp, Instant endTimeStamp, String sortOrder, int getRecordNum) { // Not implemented return new ArrayList<>(); } @@ -237,7 +237,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public List<PdpStatistics> deletePdpStatistics(final String name, final Date timestamp) { + public List<PdpStatistics> deletePdpStatistics(final String name, final Instant timestamp) { // Not implemented return new ArrayList<>(); } 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 4f574906a..0cdd1bc40 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 @@ -29,8 +29,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.time.Instant; import java.util.ArrayList; -import java.util.Date; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -75,7 +75,7 @@ public class DatabasePolicyModelsProviderTest { private static final String VERSION_100 = "1.0.0"; - private static final Date TIMESTAMP = new Date(); + private static final Instant TIMESTAMP = Instant.EPOCH; private static final String ORDER = "DESC"; @@ -370,7 +370,7 @@ public class DatabasePolicyModelsProviderTest { PdpStatistics pdpStatistics = new PdpStatistics(); pdpStatistics.setPdpInstanceId(NAME); - pdpStatistics.setTimeStamp(new Date()); + pdpStatistics.setTimeStamp(TIMESTAMP); pdpStatistics.setPdpGroupName(GROUP); pdpStatistics.setPdpSubGroupName("type"); ArrayList<PdpStatistics> statisticsArrayList = new ArrayList<>(); @@ -403,31 +403,34 @@ public class DatabasePolicyModelsProviderTest { 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(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, 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()); + 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(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()); + 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(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(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", new Date(), new Date(), ORDER, 5) - .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.deletePdpStatistics(NAME, null).get(0).getPdpInstanceId()); assertEquals(0, databaseProvider.getPdpStatistics(null, null).size()); @@ -436,7 +439,8 @@ public class DatabasePolicyModelsProviderTest { assertThat(databaseProvider.getAllPolicyStatus(new ToscaConceptIdentifierOptVersion("MyPolicy", null))) .isEmpty(); assertThat(databaseProvider.getGroupPolicyStatus(GROUP)).isEmpty(); - assertThatCode(() -> databaseProvider.cudPolicyStatus(null, null, null)).doesNotThrowAnyException(); + assertThatCode(() -> databaseProvider.cudPolicyStatus(null, null, null)) + .doesNotThrowAnyException(); 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 f2e8e8489..4daeaba4c 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 @@ -22,10 +22,10 @@ package org.onap.policy.models.provider.impl; +import java.time.Instant; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.List; import javax.ws.rs.core.Response; import lombok.NonNull; @@ -203,13 +203,13 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public List<PdpStatistics> getPdpStatistics(final String name, final Date timestamp) throws PfModelException { + public List<PdpStatistics> getPdpStatistics(final String name, final Instant timestamp) throws PfModelException { return new ArrayList<>(); } @Override public List<PdpStatistics> getFilteredPdpStatistics(String name, String pdpGroupName, String pdpSubGroup, - Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) { + Instant startTimeStamp, Instant endTimeStamp, String sortOrder, int getRecordNum) { // Not implemented return new ArrayList<>(); } @@ -229,7 +229,7 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public List<PdpStatistics> deletePdpStatistics(final String name, final Date timestamp) { + public List<PdpStatistics> deletePdpStatistics(final String name, final Instant timestamp) { // 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 a57cc956d..428aecc36 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 @@ -30,8 +30,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.time.Instant; import java.util.ArrayList; -import java.util.Date; import org.junit.Test; import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.concepts.PdpGroupFilter; @@ -112,15 +112,18 @@ public class DummyPolicyModelsProviderTest { assertTrue(dummyProvider.getPdpStatistics("name", null).isEmpty()); assertTrue( - dummyProvider.getFilteredPdpStatistics("name", null, null, new Date(), new Date(), null, 0).isEmpty()); + dummyProvider.getFilteredPdpStatistics("name", null, null, + Instant.now(), Instant.now(), null, 0).isEmpty()); assertTrue(dummyProvider.createPdpStatistics(null).isEmpty()); assertTrue(dummyProvider.updatePdpStatistics(null).isEmpty()); - assertTrue(dummyProvider.deletePdpStatistics(null, new Date()).isEmpty()); + assertTrue(dummyProvider.deletePdpStatistics(null, Instant.now()).isEmpty()); assertThat(dummyProvider.getAllPolicyStatus()).isEmpty(); - assertThat(dummyProvider.getAllPolicyStatus(new ToscaConceptIdentifierOptVersion("MyPolicy", null))).isEmpty(); + assertThat(dummyProvider.getAllPolicyStatus(new ToscaConceptIdentifierOptVersion("MyPolicy", + null))).isEmpty(); assertThat(dummyProvider.getGroupPolicyStatus("name")).isEmpty(); - assertThatCode(() -> dummyProvider.cudPolicyStatus(null, null, null)).doesNotThrowAnyException(); + assertThatCode(() -> dummyProvider.cudPolicyStatus(null, null, + null)).doesNotThrowAnyException(); } @Test |