summaryrefslogtreecommitdiffstats
path: root/models-tosca/src
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-tosca/src
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-tosca/src')
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java19
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java33
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java6
3 files changed, 30 insertions, 28 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java
index 63921610a..819b7d812 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java
@@ -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);
}
/**
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java
index 2d52f504b..b0a8ab709 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java
@@ -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");
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java
index 2eb6b10e0..38be5f6a6 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java
@@ -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 =