summaryrefslogtreecommitdiffstats
path: root/models-base
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2021-02-16 16:25:18 +0000
committerrameshiyer27 <ramesh.murugan.iyer@est.tech>2021-02-19 15:26:11 +0000
commit5a94ebda407e82a8df4abea1b8a916ea4f88d9cd (patch)
tree9372cfd5e716196ddd1bf908d4da5db7e64f93c0 /models-base
parent7e4f9950ed004042e36e7e1f6f78224d62888e74 (diff)
Refactor timestamp property in policy models to use Instant
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
Diffstat (limited to 'models-base')
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java69
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java42
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfReferenceTimestampKeyTest.java66
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java37
4 files changed, 114 insertions, 100 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java
index 5cb639ed5..47a72e8cd 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java
@@ -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);
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java
index d12466c60..a99651999 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java
@@ -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");
@@ -23,17 +23,18 @@
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());
}
+
}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceTimestampKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceTimestampKeyTest.java
index b6eae6745..c4762a201 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceTimestampKeyTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceTimestampKeyTest.java
@@ -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));
}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java
index 180e8b7a9..e6a998894 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java
@@ -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());
}