Refactor timestamp property in policy models to use Instant 17/118017/6
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>
Tue, 16 Feb 2021 16:25:18 +0000 (16:25 +0000)
committerrameshiyer27 <ramesh.murugan.iyer@est.tech>
Fri, 19 Feb 2021 15:26:11 +0000 (15:26 +0000)
Updated JPA classes to use java.sql.TImestamp rather than Instant.

Issue-ID: POLICY-3069
Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech>
Change-Id: If5b874ec96931d4b8dd142d46a9980e83a4708fc

23 files changed:
models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java
models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java
models-base/src/test/java/org/onap/policy/models/base/PfReferenceTimestampKeyTest.java
models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java
models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java
models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatisticsTest.java
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatisticsTest.java
models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java
models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java
models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java

index 5cb639e..47a72e8 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.policy.models.base;
 
+import java.sql.Timestamp;
 import java.time.Instant;
 import javax.persistence.Column;
 import javax.persistence.Embeddable;
@@ -37,15 +38,16 @@ import org.onap.policy.common.utils.validation.Assertions;
  */
 @Embeddable
 @Data
-@EqualsAndHashCode
+@EqualsAndHashCode(callSuper = true)
 @ToString(callSuper = true)
 public class PfReferenceTimestampKey extends PfReferenceKey {
+    private static final long serialVersionUID = 1130918285832617215L;
+
     private static final String TIMESTAMP_TOKEN = "timeStamp";
-    private static final Instant DEFAULT_TIMESTAMP = Instant.EPOCH;
 
     @Column(name = TIMESTAMP_TOKEN)
     @NotNull
-    private Instant timeStamp;
+    private Timestamp timeStamp;
 
 
     /**
@@ -53,7 +55,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
      */
     public PfReferenceTimestampKey() {
         super();
-        this.timeStamp = DEFAULT_TIMESTAMP;
+        this.timeStamp = new Timestamp(0);
     }
 
     /**
@@ -75,7 +77,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
      */
     public PfReferenceTimestampKey(final PfConceptKey pfConceptKey) {
         super(pfConceptKey);
-        this.timeStamp = DEFAULT_TIMESTAMP;
+        this.timeStamp = new Timestamp(0);
     }
 
     /**
@@ -85,12 +87,12 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
      *        the parent concept key of this reference key
      * @param localName
      *        the local name of this reference key
-     * @param timeStamp
-     *        the timestamp for this reference key
+     * @param instant
+     *        the time stamp for this reference key
      */
-    public PfReferenceTimestampKey(final PfConceptKey pfConceptKey, final String localName, final Instant timeStamp) {
+    public PfReferenceTimestampKey(final PfConceptKey pfConceptKey, final String localName, final Instant instant) {
         super(pfConceptKey, localName);
-        this.timeStamp = timeStamp;
+        this.timeStamp = Timestamp.from(instant);
     }
 
     /**
@@ -100,13 +102,13 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
      *        the parent reference key of this reference key
      * @param localName
      *        the local name of this reference key
-     * @param timeStamp
-     *        the timestamp for this reference key
+     * @param instant
+     *        the time stamp for this reference key
      */
     public PfReferenceTimestampKey(final PfReferenceKey parentReferenceKey, final String localName,
-                                   final Instant timeStamp) {
+                                   final Instant instant) {
         super(parentReferenceKey, localName);
-        this.timeStamp = timeStamp;
+        this.timeStamp = Timestamp.from(instant);
     }
 
     /**
@@ -119,13 +121,13 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
      *        the local name of the parent reference key of this reference key
      * @param localName
      *        the local name of this reference key
-     * @param timeStamp
-     *        the timestamp for this reference key
+     * @param instant
+     *        the time stamp for this reference key
      */
     public PfReferenceTimestampKey(final PfConceptKey pfConceptKey, final String parentLocalName,
-                                   final String localName, final Instant timeStamp) {
+                                   final String localName, final Instant instant) {
         super(pfConceptKey, parentLocalName, localName);
-        this.timeStamp = timeStamp;
+        this.timeStamp = Timestamp.from(instant);
     }
 
     /**
@@ -138,13 +140,13 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
      *        the version of the parent concept key of this reference key
      * @param localName
      *        the local name of this reference key
-     * @param timeStamp
-     *        the timestamp for this reference key
+     * @param instant
+     *        the time stamp for this reference key
      */
     public PfReferenceTimestampKey(final String parentKeyName, final String parentKeyVersion, final String localName,
-                                   final Instant timeStamp) {
+                                   final Instant instant) {
         super(parentKeyName, parentKeyVersion, NULL_KEY_NAME, localName);
-        this.timeStamp = timeStamp;
+        this.timeStamp = Timestamp.from(instant);
     }
 
     /**
@@ -159,13 +161,13 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
      *        the parent local name of this reference key
      * @param localName
      *        the local name of this reference key
-     * @param timeStamp
-     *        the timestamp for this reference key
+     * @param instant
+     *        the instant for this reference key
      */
     public PfReferenceTimestampKey(final String parentKeyName, final String parentKeyVersion,
-                                   final String parentLocalName, final String localName, final Instant timeStamp) {
+                                   final String parentLocalName, final String localName, final Instant instant) {
         super(parentKeyName, parentKeyVersion, parentLocalName, localName);
-        this.timeStamp = timeStamp;
+        this.timeStamp = Timestamp.from(instant);
     }
 
 
@@ -176,7 +178,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
      */
     public PfReferenceTimestampKey(final String id) {
         super(id.substring(0, id.lastIndexOf(':')));
-        this.timeStamp = Instant.ofEpochSecond(Long.parseLong(id.substring(id.lastIndexOf(':') + 1)));
+        this.timeStamp = new Timestamp(Long.parseLong(id.substring(id.lastIndexOf(':') + 1)));
     }
 
 
@@ -187,9 +189,16 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
      */
     public static PfReferenceTimestampKey getNullKey() {
         return new PfReferenceTimestampKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, PfKey.NULL_KEY_NAME,
-            PfKey.NULL_KEY_NAME, DEFAULT_TIMESTAMP);
+            PfKey.NULL_KEY_NAME, Instant.EPOCH);
+    }
+
+    public Instant getInstant() {
+        return timeStamp.toInstant();
     }
 
+    public void setInstant(final Instant instant) {
+        setTimeStamp(Timestamp.from(instant));
+    }
 
     @Override
     public PfReferenceTimestampKey getKey() {
@@ -198,12 +207,12 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
 
     @Override
     public String getId() {
-        return super.getId() + ':' + getTimeStamp().getEpochSecond();
+        return super.getId() + ':' + getTimeStamp().getTime();
     }
 
     @Override
     public boolean isNullKey() {
-        return super.isNullKey() && getTimeStamp().getEpochSecond() == 0;
+        return super.isNullKey() && getTimeStamp().getTime() == 0;
     }
 
     @Override
@@ -215,7 +224,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
             return false;
         }
         if (!getTimeStamp().equals(otherConceptKey.timeStamp)) {
-            return timeStamp.isAfter(otherConceptKey.timeStamp);
+            return timeStamp.after(otherConceptKey.timeStamp);
         }
         return super.isNewerThan(otherKey);
     }
index d12466c..a996519 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
  * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
 
 package org.onap.policy.models.base;
 
-import java.util.Date;
+import java.sql.Timestamp;
+import java.time.Instant;
 import javax.persistence.Column;
 import javax.persistence.Embeddable;
+import lombok.Data;
 import lombok.EqualsAndHashCode;
-import lombok.Getter;
 import lombok.NonNull;
 import org.onap.policy.common.parameters.annotations.Pattern;
 import org.onap.policy.common.utils.validation.Assertions;
 
 @Embeddable
-@Getter
+@Data
 @EqualsAndHashCode(callSuper = false)
 public class PfTimestampKey extends PfKeyImpl {
     private static final long serialVersionUID = -8410208962541783805L;
@@ -49,14 +50,15 @@ public class PfTimestampKey extends PfKeyImpl {
     private String version;
 
     @Column(name = TIMESTAMP_TOKEN)
-    private Date timeStamp;
+    @NonNull
+    private Timestamp timeStamp;
 
 
     /**
      * The default constructor creates a null concept key.
      */
     public PfTimestampKey() {
-        this(NULL_KEY_NAME, NULL_KEY_VERSION, new Date(0));
+        this(NULL_KEY_NAME, NULL_KEY_VERSION, Instant.EPOCH);
     }
 
     /**
@@ -66,8 +68,7 @@ public class PfTimestampKey extends PfKeyImpl {
      */
     public PfTimestampKey(@NonNull final PfTimestampKey copyConcept) {
         super(copyConcept);
-        long millis = copyConcept.getTimeStamp().getTime();
-        this.timeStamp = new Date(millis);
+        this.timeStamp = copyConcept.getTimeStamp();
     }
 
     /**
@@ -75,12 +76,12 @@ public class PfTimestampKey extends PfKeyImpl {
      *
      * @param name the key name
      * @param version the key version
-     * @param timeStamp the timestamp of key
+     * @param instant the time stamp of key
      */
     public PfTimestampKey(@NonNull final String name, @NonNull final String version,
-            @NonNull final Date timeStamp) {
+            @NonNull final Instant instant) {
         super(name, version);
-        this.timeStamp = new Date(timeStamp.getTime());
+        this.timeStamp = Timestamp.from(instant);
     }
 
     /**
@@ -90,7 +91,7 @@ public class PfTimestampKey extends PfKeyImpl {
      */
     public PfTimestampKey(final String id) {
         super(id.substring(0, id.lastIndexOf(':')));
-        this.timeStamp = new Date(Long.parseLong(id.substring(id.lastIndexOf(':') + 1)));
+        this.timeStamp = new Timestamp(Long.parseLong(id.substring(id.lastIndexOf(':') + 1)));
     }
 
     @Override
@@ -104,13 +105,15 @@ public class PfTimestampKey extends PfKeyImpl {
      * @return a null key
      */
     public static final PfTimestampKey getNullKey() {
-        return new PfTimestampKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, new Date(0));
+        return new PfTimestampKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, Instant.EPOCH);
     }
 
-    @Override
-    public String toString() {
-        return "PfTimestampKey(name=" + getName() + ", version=" + getVersion() + ", timestamp="
-                + getTimeStamp().getTime() + ")";
+    public Instant getInstant() {
+        return timeStamp.toInstant();
+    }
+
+    public void setInstant(final Instant instant) {
+        setTimeStamp(Timestamp.from(instant));;
     }
 
     @Override
@@ -130,10 +133,6 @@ public class PfTimestampKey extends PfKeyImpl {
         return super.isNewerThan(otherKey);
     }
 
-    public void setTimeStamp(@NonNull final Date timeStamp) {
-        this.timeStamp = new Date(timeStamp.getTime());
-    }
-
     @Override
     public boolean isNullKey() {
         return super.isNullKey() && getTimeStamp().getTime() == 0;
@@ -158,4 +157,5 @@ public class PfTimestampKey extends PfKeyImpl {
     public void setVersion(@NonNull String version) {
         this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, getVersionRegEx());
     }
+
 }
index b6eae67..c4762a2 100644 (file)
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.sql.Timestamp;
 import java.time.Instant;
 import org.junit.Test;
 
@@ -46,26 +47,28 @@ public class PfReferenceTimestampKeyTest {
         assertEquals(PfKey.NULL_KEY_NAME, new PfReferenceTimestampKey(new PfConceptKey()).getParentKeyName());
         assertNotNull(new PfReferenceTimestampKey(new PfReferenceTimestampKey()).getTimeStamp());
 
-        assertEquals(LOCAL_NAME, new PfReferenceTimestampKey(new PfReferenceKey(), LOCAL_NAME,
-            Instant.ofEpochSecond(timeStamp)).getLocalName());
-        assertEquals(Instant.ofEpochSecond(timeStamp), new PfReferenceTimestampKey(new PfConceptKey(),
-            PARENT_LOCAL_NAME, LOCAL_NAME, Instant.ofEpochSecond(timeStamp)).getTimeStamp());
+        assertEquals(LOCAL_NAME,
+                new PfReferenceTimestampKey(new PfReferenceKey(), LOCAL_NAME, Instant.ofEpochSecond(timeStamp))
+                        .getLocalName());
+        assertEquals(Timestamp.from(Instant.ofEpochSecond(timeStamp)), new PfReferenceTimestampKey(new PfConceptKey(),
+                PARENT_LOCAL_NAME, LOCAL_NAME, Instant.ofEpochSecond(timeStamp)).getTimeStamp());
 
-        assertThat(new PfReferenceTimestampKey("ParentKeyName", VERSION001, PARENT_LOCAL_NAME,
-            LOCAL_NAME, Instant.ofEpochSecond(timeStamp))).isInstanceOf(PfReferenceTimestampKey.class);
+        assertThat(new PfReferenceTimestampKey("ParentKeyName", VERSION001, PARENT_LOCAL_NAME, LOCAL_NAME,
+                Instant.ofEpochSecond(timeStamp))).isInstanceOf(PfReferenceTimestampKey.class);
 
-        assertThat(new PfReferenceTimestampKey("ParentKeyName", VERSION001, LOCAL_NAME,
-            Instant.ofEpochSecond(timeStamp)).getParentLocalName()).isEqualTo(PfKey.NULL_KEY_NAME);
+        assertThat(
+                new PfReferenceTimestampKey("ParentKeyName", VERSION001, LOCAL_NAME, Instant.ofEpochSecond(timeStamp))
+                        .getParentLocalName()).isEqualTo(PfKey.NULL_KEY_NAME);
 
         assertEquals(PfReferenceTimestampKey.getNullKey().getKey(), PfReferenceTimestampKey.getNullKey());
         assertEquals("NULL:0.0.0:NULL:NULL:" + Instant.EPOCH.getEpochSecond(),
-            PfReferenceTimestampKey.getNullKey().getId());
+                PfReferenceTimestampKey.getNullKey().getId());
 
         assertThatThrownBy(() -> new PfReferenceTimestampKey(new PfConceptKey(), null, null))
-            .hasMessage("parameter \"localName\" is null");
+                .hasMessage("parameter \"localName\" is null");
 
         String id = "NULL:0.0.0:NULL:NULL:" + timeStamp;
-        assertThat(new PfReferenceTimestampKey(id).getTimeStamp().getEpochSecond()).isEqualTo(timeStamp);
+        assertThat(new PfReferenceTimestampKey(id).getTimeStamp().getTime()).isEqualTo(timeStamp);
 
     }
 
@@ -78,8 +81,7 @@ public class PfReferenceTimestampKeyTest {
         assertEquals(1, testReferenceKey.getKeys().size());
         assertFalse(testReferenceKey.isNullKey());
 
-        testReferenceKey.setParentReferenceKey(new PfReferenceKey("PN", VERSION001,
-            "LN"));
+        testReferenceKey.setParentReferenceKey(new PfReferenceKey("PN", VERSION001, "LN"));
         assertEquals("PN:0.0.1:NULL:LN", testReferenceKey.getParentReferenceKey().getId());
 
         testReferenceKey.setParentKeyName("PKN");
@@ -94,12 +96,12 @@ public class PfReferenceTimestampKeyTest {
         testReferenceKey.setLocalName("LN");
         assertEquals("LN", testReferenceKey.getLocalName());
 
-        testReferenceKey.setTimeStamp(DEFAULT_TIMESTAMP);
-        assertEquals(DEFAULT_TIMESTAMP, testReferenceKey.getTimeStamp());
+        testReferenceKey.setTimeStamp(Timestamp.from(DEFAULT_TIMESTAMP));
+        assertEquals(Timestamp.from(DEFAULT_TIMESTAMP), testReferenceKey.getTimeStamp());
 
 
         assertThatThrownBy(() -> testReferenceKey.isCompatible(null))
-            .hasMessageMatching("^otherKey is marked .*on.*ull but is null$");
+                .hasMessageMatching("^otherKey is marked .*on.*ull but is null$");
 
         assertFalse(testReferenceKey.isCompatible(PfConceptKey.getNullKey()));
         assertFalse(testReferenceKey.isCompatible(PfReferenceKey.getNullKey()));
@@ -112,26 +114,26 @@ public class PfReferenceTimestampKeyTest {
         PfReferenceTimestampKey clonedReferenceKey = new PfReferenceTimestampKey(testReferenceKey);
 
         assertEquals("PfReferenceTimestampKey(super=PfReferenceKey(parentKeyName=PKN, parentKeyVersion=0.0.1, "
-                + "parentLocalName=ParentLocalName, localName=LN), timeStamp=" + Instant.EPOCH + ")",
-            clonedReferenceKey.toString());
+                + "parentLocalName=ParentLocalName, localName=LN), timeStamp=" + Timestamp.from(Instant.EPOCH) + ")",
+                clonedReferenceKey.toString());
 
         assertNotEquals(0, testReferenceKey.hashCode());
 
         assertEquals(testReferenceKey, clonedReferenceKey);
-        assertNotEquals(testReferenceKey, new PfReferenceTimestampKey("PKN", VERSION001,
-            "PLN", "LN", Instant.ofEpochSecond(timeStamp)));
-        testReferenceKey.setTimeStamp(Instant.ofEpochSecond(timeStamp));
-        assertEquals(testReferenceKey, new PfReferenceTimestampKey("PKN", VERSION001,
-            PARENT_LOCAL_NAME, "LN", Instant.ofEpochSecond(timeStamp)));
+        assertNotEquals(testReferenceKey,
+                new PfReferenceTimestampKey("PKN", VERSION001, "PLN", "LN", Instant.ofEpochSecond(timeStamp)));
+        testReferenceKey.setTimeStamp(Timestamp.from(Instant.ofEpochSecond(timeStamp)));
+        assertEquals(testReferenceKey, new PfReferenceTimestampKey("PKN", VERSION001, PARENT_LOCAL_NAME, "LN",
+                Instant.ofEpochSecond(timeStamp)));
 
         assertNotEquals(0, testReferenceKey.compareTo(new PfConceptKey()));
-        assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceTimestampKey("PKN",
-            VERSION002, "PLN", "LN", Instant.ofEpochSecond(timeStamp))));
-        assertEquals(0, testReferenceKey.compareTo(new PfReferenceTimestampKey("PKN",
-            VERSION001, PARENT_LOCAL_NAME, "LN", Instant.ofEpochSecond(timeStamp))));
+        assertNotEquals(0, testReferenceKey.compareTo(
+                new PfReferenceTimestampKey("PKN", VERSION002, "PLN", "LN", Instant.ofEpochSecond(timeStamp))));
+        assertEquals(0, testReferenceKey.compareTo(new PfReferenceTimestampKey("PKN", VERSION001, PARENT_LOCAL_NAME,
+                "LN", Instant.ofEpochSecond(timeStamp))));
 
         assertThatThrownBy(() -> new PfReferenceTimestampKey((PfReferenceTimestampKey) null))
-            .isInstanceOf(NullPointerException.class);
+                .isInstanceOf(NullPointerException.class);
 
         assertEquals(testReferenceKey, new PfReferenceTimestampKey(testReferenceKey));
 
@@ -139,14 +141,14 @@ public class PfReferenceTimestampKeyTest {
 
     @Test
     public void testNewerKey() {
-        PfReferenceTimestampKey key1 = new PfReferenceTimestampKey("ParentKeyName", VERSION001,
-            PARENT_LOCAL_NAME, LOCAL_NAME, Instant.ofEpochSecond(timeStamp));
+        PfReferenceTimestampKey key1 = new PfReferenceTimestampKey("ParentKeyName", VERSION001, PARENT_LOCAL_NAME,
+                LOCAL_NAME, Instant.ofEpochSecond(timeStamp));
         PfReferenceTimestampKey key2 = new PfReferenceTimestampKey(key1);
         assertFalse(key2.isNewerThan(key1));
         assertThatThrownBy(() -> key1.isNewerThan((PfKey) null)).isInstanceOf(NullPointerException.class)
-            .hasMessageMatching("^otherKey is marked .*on.*ull but is null$");
+                .hasMessageMatching("^otherKey is marked .*on.*ull but is null$");
 
-        key2.setTimeStamp(Instant.ofEpochSecond(timeStamp).plusSeconds(80));
+        key2.setTimeStamp(Timestamp.from(Instant.ofEpochSecond(timeStamp).plusSeconds(80)));
         assertTrue(key2.isNewerThan(key1));
     }
 
index 180e8b7..e6a9988 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,7 +25,8 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Date;
+import java.sql.Timestamp;
+import java.time.Instant;
 import org.junit.Test;
 
 public class PfTimestampKeyTest {
@@ -33,7 +34,6 @@ public class PfTimestampKeyTest {
     private static final String CONCEPT_IS_NULL = "^copyConcept is marked .*on.*ull but is null$";
     private static final String NAME_IS_NULL = "^name is marked .*on.*ull but is null$";
     private static final String VERSION_IS_NULL = "^version is marked .*on.*ull but is null$";
-    private static final String TIMESTAMP_IS_NULL = "^timeStamp is marked .*on.*ull but is null$";
     private static final long timeStamp = 1574832537641L;
 
     @Test
@@ -41,15 +41,17 @@ public class PfTimestampKeyTest {
         PfTimestampKey someKey0 = new PfTimestampKey();
         assertEquals(PfTimestampKey.getNullKey(), someKey0);
         assertTrue(someKey0.isNullKey());
-        assertEquals("PfTimestampKey(name=NULL, version=0.0.0, timestamp=0)", someKey0.toString());
+        assertEquals("PfTimestampKey(name=NULL, version=0.0.0, timeStamp=" + Timestamp.from(Instant.EPOCH) + ")",
+                someKey0.toString());
 
-        PfTimestampKey someKey1 = new PfTimestampKey("my-name", VERSION001, new Date(timeStamp));
+        PfTimestampKey someKey1 = new PfTimestampKey("my-name", VERSION001, Instant.ofEpochSecond(timeStamp));
         PfTimestampKey someKey2 = new PfTimestampKey(someKey1);
         PfTimestampKey someKey3 = new PfTimestampKey(someKey1.getId());
         assertEquals(someKey1, someKey2);
         assertEquals(someKey1, someKey3);
         assertFalse(someKey1.isNullVersion());
-        assertEquals("PfTimestampKey(name=my-name, version=0.0.1, timestamp=1574832537641)", someKey1.toString());
+        assertEquals("PfTimestampKey(name=my-name, version=0.0.1, timeStamp="
+                + Timestamp.from(Instant.ofEpochSecond(timeStamp)) + ")", someKey1.toString());
 
         assertEquals("my-name", someKey1.getName());
         assertEquals(VERSION001, someKey1.getVersion());
@@ -58,25 +60,26 @@ public class PfTimestampKeyTest {
         assertEquals(1, someKey1.getKeys().size());
 
         assertThatThrownBy(() -> new PfTimestampKey((PfTimestampKey) null)).isInstanceOf(NullPointerException.class)
-            .hasMessageMatching(CONCEPT_IS_NULL);
+                .hasMessageMatching(CONCEPT_IS_NULL);
         assertThatThrownBy(() -> new PfTimestampKey(null, null, null)).isInstanceOf(NullPointerException.class)
-            .hasMessageMatching(NAME_IS_NULL);
+                .hasMessageMatching(NAME_IS_NULL);
         assertThatThrownBy(() -> new PfTimestampKey("my-name", null, null)).isInstanceOf(NullPointerException.class)
-            .hasMessageMatching(VERSION_IS_NULL);
+                .hasMessageMatching(VERSION_IS_NULL);
         assertThatThrownBy(() -> new PfTimestampKey("my-name", VERSION001, null))
-            .isInstanceOf(NullPointerException.class).hasMessageMatching(TIMESTAMP_IS_NULL);
+                .isInstanceOf(NullPointerException.class)
+                .hasMessageMatching("^instant is marked .*on.*ull but is null$");
 
         assertThatThrownBy(() -> someKey0.setName(null)).isInstanceOf(NullPointerException.class)
-            .hasMessageMatching(NAME_IS_NULL);
+                .hasMessageMatching(NAME_IS_NULL);
         assertThatThrownBy(() -> someKey0.setVersion(null)).isInstanceOf(NullPointerException.class)
-            .hasMessageMatching(VERSION_IS_NULL);
+                .hasMessageMatching(VERSION_IS_NULL);
         assertThatThrownBy(() -> someKey0.setTimeStamp(null)).isInstanceOf(NullPointerException.class)
-            .hasMessageMatching(TIMESTAMP_IS_NULL);
+                .hasMessageMatching("^timeStamp is marked .*on.*ull but is null$");
 
         assertFalse(someKey1.isNewerThan(someKey2));
         assertThatThrownBy(() -> someKey1.isNewerThan((PfKey) null)).isInstanceOf(NullPointerException.class)
-            .hasMessageMatching("^otherKey is marked .*on.*ull but is null$");
-        someKey2.setTimeStamp(new Date(timeStamp + 1));
+                .hasMessageMatching("^otherKey is marked .*on.*ull but is null$");
+        someKey2.setTimeStamp(Timestamp.from(Instant.ofEpochSecond(timeStamp).plusMillis(90)));
         assertTrue(someKey2.isNewerThan(someKey1));
         someKey3.setName("my-name3");
         assertTrue(someKey3.isNewerThan(someKey1));
@@ -84,9 +87,9 @@ public class PfTimestampKeyTest {
         assertEquals(-1, someKey1.compareTo(someKey2));
         assertEquals(-1, someKey1.compareTo(someKey3));
         assertThatThrownBy(() -> someKey1.compareTo((PfConcept) null)).isInstanceOf(NullPointerException.class)
-            .hasMessageMatching("^otherObj is marked .*on.*ull but is null$");
+                .hasMessageMatching("^otherObj is marked .*on.*ull but is null$");
 
-        PfTimestampKey someKey4 = new PfTimestampKey("NULL", "0.0.0", new Date(timeStamp));
+        PfTimestampKey someKey4 = new PfTimestampKey("NULL", "0.0.0", Instant.ofEpochSecond(timeStamp));
         assertFalse(someKey4.isNullKey());
         assertFalse(someKey1.isNullKey());
     }
index 6c862bb..05f907f 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,8 +21,8 @@
 
 package org.onap.policy.models.dao;
 
+import java.time.Instant;
 import java.util.Collection;
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import org.onap.policy.models.base.PfConcept;
@@ -168,8 +168,8 @@ public interface PfDao {
      * @param getRecordNum Total query count from database
      * @return the objects that was retrieved from the database
      */
-    <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version, Date startTime,
-            Date endTime, Map<String, Object> filterMap, String sortOrder, int getRecordNum);
+    <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version, Instant startTime,
+            Instant endTime, Map<String, Object> filterMap, String sortOrder, int getRecordNum);
 
     /**
      * Get an object from the database, referred to by concept key.
index 5e89ee5..c29c4bf 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
 
 package org.onap.policy.models.dao.impl;
 
+import java.sql.Timestamp;
+import java.time.Instant;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import javax.persistence.EntityManager;
@@ -355,7 +356,7 @@ public class DefaultPfDao implements PfDao {
 
     @Override
     public <T extends PfConcept> List<T> getFiltered(final Class<T> someClass, final String name, final String version,
-            final Date startTime, final Date endTime, final Map<String, Object> filterMap, final String sortOrder,
+            final Instant startTime, final Instant endTime, final Map<String, Object> filterMap, final String sortOrder,
             final int getRecordNum) {
         final EntityManager mg = getEntityManager();
 
@@ -381,14 +382,14 @@ public class DefaultPfDao implements PfDao {
             }
             if (startTime != null) {
                 if (endTime != null) {
-                    query.setParameter("startTime", startTime);
-                    query.setParameter("endTime", endTime);
+                    query.setParameter("startTime", Timestamp.from(startTime));
+                    query.setParameter("endTime", Timestamp.from(endTime));
                 } else {
-                    query.setParameter("startTime", startTime);
+                    query.setParameter("startTime", Timestamp.from(startTime));
                 }
             } else {
                 if (endTime != null) {
-                    query.setParameter("endTime", endTime);
+                    query.setParameter("endTime", Timestamp.from(endTime));
                 }
             }
             if (getRecordNum > 0) {
@@ -620,8 +621,8 @@ public class DefaultPfDao implements PfDao {
      *        endTime. null for ignore end time
      * @return the filter string to query database
      */
-    private String addKeyFilterString(String inputFilterString, final String name, final Date startTime,
-            final Date endTime) {
+    private String addKeyFilterString(String inputFilterString, final String name, final Instant startTime,
+            final Instant endTime) {
         String filterQueryString;
         if (name != null) {
             inputFilterString += NAME_FILTER + AND;
index 040b76b..1ba2e41 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,8 +27,8 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 
+import java.time.Instant;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -58,9 +58,9 @@ public class EntityTest {
     private static final String VERSION003 = "0.0.3";
     private static final String VERSION002 = "0.0.2";
     private static final String VERSION001 = "0.0.1";
-    private static final Date TIMESTAMP0 = new Date();
-    private static final Date TIMESTAMP1 = new Date();
-    private static final Date TIMESTAMP2 = new Date();
+    private static final Instant TIMESTAMP0 = Instant.ofEpochSecond(1613494293);
+    private static final Instant TIMESTAMP1 = Instant.ofEpochSecond(1613494293).plusSeconds(55);
+    private static final Instant TIMESTAMP2 = Instant.ofEpochSecond(1613494293).plusSeconds(90);
     private PfDao pfDao;
 
     @Test
index 1ba983b..f7a0e7d 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
- *  Modifications Copyright (C) 2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2020-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
 
 package org.onap.policy.models.pdp.concepts;
 
-import java.util.Date;
+import java.time.Instant;
 import java.util.List;
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -39,7 +39,7 @@ import org.onap.policy.models.base.PfUtils;
 public class PdpStatistics {
 
     private String pdpInstanceId;
-    private Date timeStamp;
+    private Instant timeStamp;
     private String pdpGroupName;
     private String pdpSubGroupName;
     private long policyDeployCount;
@@ -57,7 +57,7 @@ public class PdpStatistics {
      */
     public PdpStatistics(@NonNull PdpStatistics source) {
         this.pdpInstanceId = source.pdpInstanceId;
-        this.timeStamp = source.timeStamp == null ? null : new Date(source.timeStamp.getTime());
+        this.timeStamp = source.timeStamp;
         this.pdpGroupName = source.pdpGroupName;
         this.pdpSubGroupName = source.pdpSubGroupName;
         this.policyDeployCount = source.policyDeployCount;
index 90cf4e4..c3329cf 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
  * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,7 @@
 package org.onap.policy.models.pdp.persistence.concepts;
 
 import java.io.Serializable;
-import java.util.Date;
+import java.time.Instant;
 import java.util.List;
 import javax.persistence.Column;
 import javax.persistence.ElementCollection;
@@ -167,7 +167,7 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
     public PdpStatistics toAuthorative() {
         PdpStatistics pdpStatistics = new PdpStatistics();
         pdpStatistics.setPdpInstanceId(key.getName());
-        pdpStatistics.setTimeStamp(new Date(key.getTimeStamp().getTime()));
+        pdpStatistics.setTimeStamp(key.getInstant());
         pdpStatistics.setPdpGroupName(pdpGroupName);
         pdpStatistics.setPdpSubGroupName(pdpSubGroupName);
         pdpStatistics.setPolicyDeployCount(policyDeployCount);
@@ -185,7 +185,7 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
     public void fromAuthorative(@NonNull final PdpStatistics pdpStatistics) {
         if (this.key == null || this.getKey().isNullKey()) {
             this.setKey(new PfTimestampKey(pdpStatistics.getPdpInstanceId(), PfKey.NULL_KEY_VERSION,
-                    new Date(pdpStatistics.getTimeStamp() == null ? 0 : pdpStatistics.getTimeStamp().getTime())));
+                    pdpStatistics.getTimeStamp() == null ? Instant.EPOCH : pdpStatistics.getTimeStamp()));
         }
         this.setPdpGroupName(pdpStatistics.getPdpGroupName());
         this.setPdpSubGroupName(pdpStatistics.getPdpSubGroupName());
index 7901246..e030d08 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
  * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,8 +23,8 @@
 
 package org.onap.policy.models.pdp.persistence.provider;
 
+import java.time.Instant;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -58,7 +58,7 @@ public class PdpStatisticsProvider {
      * @return the PDP statistics found
      * @throws PfModelException on errors getting PDP statistics
      */
-    public List<PdpStatistics> getPdpStatistics(@NonNull final PfDao dao, final String name, final Date timestamp)
+    public List<PdpStatistics> getPdpStatistics(@NonNull final PfDao dao, final String name, final Instant timestamp)
             throws PfModelException {
 
         List<PdpStatistics> pdpStatistics = new ArrayList<>();
@@ -87,8 +87,8 @@ public class PdpStatisticsProvider {
      * @throws PfModelException on errors getting policies
      */
     public List<PdpStatistics> getFilteredPdpStatistics(@NonNull final PfDao dao, final String name,
-            @NonNull final String pdpGroupName, final String pdpSubGroup, final Date startTimeStamp,
-            final Date endTimeStamp, final String sortOrder, final int getRecordNum) {
+            @NonNull final String pdpGroupName, final String pdpSubGroup, final Instant startTimeStamp,
+            final Instant endTimeStamp, final String sortOrder, final int getRecordNum) {
         Map<String, Object> filterMap = new HashMap<>();
         filterMap.put("pdpGroupName", pdpGroupName);
         if (pdpSubGroup != null) {
@@ -181,7 +181,7 @@ public class PdpStatisticsProvider {
      * @throws PfModelException on errors deleting PDP statistics
      */
     public List<PdpStatistics> deletePdpStatistics(@NonNull final PfDao dao, @NonNull final String name,
-            final Date timestamp) {
+            final Instant timestamp) {
         List<PdpStatistics> pdpStatisticsListToDel = asPdpStatisticsList(dao.getFiltered(JpaPdpStatistics.class, name,
                 PfKey.NULL_KEY_VERSION, timestamp, timestamp, null, DESC_ORDER, 0));
 
index c0d2ba6..b748b91 100644 (file)
@@ -23,7 +23,7 @@ package org.onap.policy.models.pdp.concepts;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 
-import java.util.Date;
+import java.time.Instant;
 import org.junit.Test;
 import org.onap.policy.models.pdp.enums.PdpEngineWorkerState;
 
@@ -50,7 +50,7 @@ public class PdpEngineWorkerStatisticsTest {
         PdpEngineWorkerStatistics stat = new PdpEngineWorkerStatistics();
         stat.setEngineId("Engine0");
         stat.setEngineWorkerState(PdpEngineWorkerState.READY);
-        stat.setEngineTimeStamp(new Date().getTime());
+        stat.setEngineTimeStamp(Instant.now().getEpochSecond());
         stat.setEventCount(1);
         stat.setLastExecutionTime(100);
         stat.setAverageExecutionTime(99);
index adf9b9f..4c099e6 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP Policy Models
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,8 +24,8 @@ package org.onap.policy.models.pdp.concepts;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 
+import java.time.Instant;
 import java.util.ArrayList;
-import java.util.Date;
 import org.junit.Test;
 
 public class PdpStatisticsTest {
@@ -44,7 +44,7 @@ public class PdpStatisticsTest {
         pdpStat.setPdpInstanceId("PDP0");
         pdpStat.setPdpGroupName("PDPGroup0");
         pdpStat.setPdpSubGroupName("PDPSubGroup0");
-        pdpStat.setTimeStamp(new Date());
+        pdpStat.setTimeStamp(Instant.EPOCH);
         pdpStat.setPolicyDeployCount(3);
         pdpStat.setPolicyDeploySuccessCount(1);
         pdpStat.setPolicyDeployFailCount(2);
index 83cf85b..405425e 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,8 +28,8 @@ import static org.junit.Assert.assertNotEquals;
 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 org.junit.Test;
 import org.onap.policy.models.base.PfTimestampKey;
 import org.onap.policy.models.pdp.concepts.PdpStatistics;
@@ -114,7 +114,7 @@ public class JpaPdpStatisticsTest {
         assertEquals(pdpStat.getPdpInstanceId(), jpaPdpStat.getKey().getName());
         assertEquals(pdpStat.getPdpGroupName(), jpaPdpStat.getPdpGroupName());
         assertEquals(pdpStat.getPdpSubGroupName(), jpaPdpStat.getPdpSubGroupName());
-        assertEquals(pdpStat.getTimeStamp(), jpaPdpStat.getKey().getTimeStamp());
+        assertEquals(pdpStat.getTimeStamp(), jpaPdpStat.getKey().getInstant());
         assertEquals(pdpStat.getPolicyDeployCount(), jpaPdpStat.getPolicyDeployCount());
         assertEquals(pdpStat.getPolicyDeploySuccessCount(), jpaPdpStat.getPolicyDeploySuccessCount());
         assertEquals(pdpStat.getPolicyDeployFailCount(), jpaPdpStat.getPolicyDeployFailCount());
@@ -128,7 +128,7 @@ public class JpaPdpStatisticsTest {
         pdpStat.setPdpInstanceId("PDP0");
         pdpStat.setPdpGroupName("PDPGroup0");
         pdpStat.setPdpSubGroupName("PDPSubGroup0");
-        pdpStat.setTimeStamp(new Date());
+        pdpStat.setTimeStamp(Instant.EPOCH);
         pdpStat.setPolicyDeployCount(3);
         pdpStat.setPolicyDeploySuccessCount(1);
         pdpStat.setPolicyDeployFailCount(2);
index d8eeab4..a418f81 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2020 Nordix Foundation.
+ *  Copyright (C) 2020-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,8 +25,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 
+import java.time.Instant;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.Properties;
 import org.eclipse.persistence.config.PersistenceUnitProperties;
@@ -48,8 +48,8 @@ public class PdpStatisticsProviderTest {
     private static final String NAME = "name";
     private static final String GROUP = "group";
     private static final String SUBGROUP = "subgroup";
-    private static final Date TIMESTAMP1 = new Date(1078884319);
-    private static final Date TIMESTAMP2 = new Date(1078884350);
+    private static final Instant TIMESTAMP1 = Instant.ofEpochSecond(1078884319);
+    private static final Instant TIMESTAMP2 = Instant.ofEpochSecond(1078884350);
     private static final String ORDER = "DESC";
 
     private PfDao pfDao;
index 3bf81ad..3af069e 100644 (file)
@@ -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.
index 8c7c512..1839604 100644 (file)
@@ -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);
index 1b91f07..07617aa 100644 (file)
@@ -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<>();
     }
index 4f57490..0cdd1bc 100644 (file)
@@ -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();
     }
index f2e8e84..4daeaba 100644 (file)
 
 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;
     }
index a57cc95..428aecc 100644 (file)
@@ -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
index 6392161..819b7d8 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,7 +24,8 @@
 package org.onap.policy.models.tosca.simple.concepts;
 
 import com.google.gson.annotations.SerializedName;
-import java.util.Date;
+import java.sql.Timestamp;
+import java.time.Instant;
 import java.util.List;
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
@@ -63,10 +64,10 @@ public class JpaToscaTimeInterval extends PfConcept {
     private PfReferenceKey key;
 
     @SerializedName("start_time")
-    private Date startTime;
+    private Timestamp startTime;
 
     @SerializedName("end_time")
-    private Date endTime;
+    private Timestamp endTime;
 
     /**
      * The Default Constructor creates a {@link JpaToscaTimeInterval} object with a null key.
@@ -81,7 +82,7 @@ public class JpaToscaTimeInterval extends PfConcept {
      * @param key the key
      */
     public JpaToscaTimeInterval(@NonNull final PfReferenceKey key) {
-        this(key, new Date(0), new Date(0));
+        this(key, Instant.EPOCH, Instant.EPOCH);
     }
 
     /**
@@ -89,11 +90,11 @@ public class JpaToscaTimeInterval extends PfConcept {
      *
      * @param key the key
      */
-    public JpaToscaTimeInterval(@NonNull final PfReferenceKey key, @NonNull final Date startTime,
-            @NonNull final Date endTime) {
+    public JpaToscaTimeInterval(@NonNull final PfReferenceKey key, @NonNull final Instant startTime,
+            @NonNull final Instant endTime) {
         this.key = key;
-        this.startTime = startTime;
-        this.endTime = endTime;
+        this.startTime = Timestamp.from(startTime);
+        this.endTime = Timestamp.from(endTime);
     }
 
     /**
index 2d52f50..b0a8ab7 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,7 +28,8 @@ import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Date;
+import java.sql.Timestamp;
+import java.time.Instant;
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfReferenceKey;
@@ -46,27 +47,27 @@ public class JpaToscaTimeIntervalTest {
     public void testTimeIntervalPojo() {
         assertNotNull(new JpaToscaTimeInterval());
         assertNotNull(new JpaToscaTimeInterval(new PfReferenceKey()));
-        assertNotNull(new JpaToscaTimeInterval(new PfReferenceKey(), new Date(), new Date()));
+        assertNotNull(new JpaToscaTimeInterval(new PfReferenceKey(), Instant.now(), Instant.now()));
         assertNotNull(new JpaToscaTimeInterval(new JpaToscaTimeInterval()));
 
         assertThatThrownBy(() -> new JpaToscaTimeInterval((PfReferenceKey) null)).hasMessageMatching(KEY_IS_NULL);
 
         assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, null)).hasMessageMatching(KEY_IS_NULL);
 
-        assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, new Date())).hasMessageMatching(KEY_IS_NULL);
+        assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, Instant.now())).hasMessageMatching(KEY_IS_NULL);
 
-        assertThatThrownBy(() -> new JpaToscaTimeInterval(null, new Date(), null)).hasMessageMatching(KEY_IS_NULL);
+        assertThatThrownBy(() -> new JpaToscaTimeInterval(null, Instant.now(), null)).hasMessageMatching(KEY_IS_NULL);
 
-        assertThatThrownBy(() -> new JpaToscaTimeInterval(null, new Date(), new Date()))
+        assertThatThrownBy(() -> new JpaToscaTimeInterval(null, Instant.now(), Instant.now()))
                 .hasMessageMatching(KEY_IS_NULL);
 
         assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), null, null))
                 .hasMessageMatching("startTime is marked .*on.*ull but is null");
 
-        assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), null, new Date()))
+        assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), null, Instant.now()))
                 .hasMessageMatching("startTime is marked .*on.*ull but is null");
 
-        assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), new Date(), null))
+        assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), Instant.now(), null))
                 .hasMessageMatching("endTime is marked .*on.*ull but is null");
 
         assertThatThrownBy(() -> new JpaToscaServiceTemplate((JpaToscaServiceTemplate) null))
@@ -74,8 +75,8 @@ public class JpaToscaTimeIntervalTest {
 
         PfConceptKey ttiParentKey = new PfConceptKey("tParentKey", "0.0.1");
         PfReferenceKey ttiKey = new PfReferenceKey(ttiParentKey, "trigger0");
-        Date startTime = new Date(1000);
-        Date endTime = new Date(2000);
+        Instant startTime = Instant.ofEpochSecond(1000);
+        Instant endTime = Instant.ofEpochSecond(2000);
         JpaToscaTimeInterval tti = new JpaToscaTimeInterval(ttiKey, startTime, endTime);
 
         JpaToscaTimeInterval tdtClone0 = new JpaToscaTimeInterval(tti);
@@ -96,9 +97,9 @@ public class JpaToscaTimeIntervalTest {
         assertNotEquals(0, tti.compareTo(otherDt));
         otherDt.setKey(ttiKey);
         assertNotEquals(0, tti.compareTo(otherDt));
-        otherDt.setStartTime(startTime);
+        otherDt.setStartTime(Timestamp.from(startTime));
         assertNotEquals(0, tti.compareTo(otherDt));
-        otherDt.setEndTime(endTime);
+        otherDt.setEndTime(Timestamp.from(endTime));
         assertEquals(0, tti.compareTo(otherDt));
 
         assertEquals(1, tti.getKeys().size());
@@ -113,16 +114,16 @@ public class JpaToscaTimeIntervalTest {
 
         tti.setStartTime(null);
         assertFalse(tti.validate("").isValid());
-        tti.setStartTime(new Date(endTime.getTime() + 1));
+        tti.setStartTime(Timestamp.from(endTime.plusSeconds(1)));
         assertFalse(tti.validate("").isValid());
-        tti.setStartTime(startTime);
+        tti.setStartTime(Timestamp.from(startTime));
         assertTrue(tti.validate("").isValid());
 
         tti.setEndTime(null);
         assertFalse(tti.validate("").isValid());
-        tti.setEndTime(new Date(startTime.getTime() - 1));
+        tti.setEndTime(Timestamp.from(startTime.minusSeconds(1)));
         assertFalse(tti.validate("").isValid());
-        tti.setEndTime(endTime);
+        tti.setEndTime(Timestamp.from(endTime));
         assertTrue(tti.validate("").isValid());
 
         assertThatThrownBy(() -> tti.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
index 2eb6b10..38be5f6 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,7 +29,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.time.Duration;
-import java.util.Date;
+import java.time.Instant;
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfReferenceKey;
@@ -81,7 +81,7 @@ public class JpaToscaTriggerTest {
         JpaToscaTrigger tdt = new JpaToscaTrigger(tkey, EVENT_TYPE, ACTION);
 
         JpaToscaTimeInterval schedule =
-                new JpaToscaTimeInterval(new PfReferenceKey(tkey, "sched"), new Date(), new Date());
+                new JpaToscaTimeInterval(new PfReferenceKey(tkey, "sched"), Instant.now(), Instant.now());
         tdt.setSchedule(schedule);
 
         JpaToscaEventFilter targetFilter =