summaryrefslogtreecommitdiffstats
path: root/models-base/src/test
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/src/test
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/src/test')
-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
2 files changed, 54 insertions, 49 deletions
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());
}