summaryrefslogtreecommitdiffstats
path: root/models-base/src/test/java/org/onap
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2021-03-01 18:46:33 +0000
committerrameshiyer27 <ramesh.murugan.iyer@est.tech>2021-03-03 12:50:47 +0000
commitfcbf3698fa3e3fbc6ea3364d80d4a3f3a8d37650 (patch)
tree20db6b9b856b0a3c6020b2986967c5df0c594401 /models-base/src/test/java/org/onap
parent726bec7cd5e1b0f5c45b3ec58bc64e344240e8c9 (diff)
Fix Reference Key columns persistence issue in db
Problem: When PfReferenceTimestamp Key is persisted in db, the parent class fields are ignored which causes inconsistent data while saving and fetching in db. Fix: JPA is not supporting inheritance in @Embeddable classes. Hence included the super class as @Embedded property in PfReferenceTimestamp key. @Embedded properties are unable to be queried directly. Slightly modified Dao methods to support querying @embedded fields. Issue-ID: POLICY-3049 Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech> Change-Id: I5c2e03a5ae98525764a64dd6cce1a1298c5f9816
Diffstat (limited to 'models-base/src/test/java/org/onap')
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfReferenceTimestampKeyTest.java55
1 files changed, 28 insertions, 27 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 061760aeb..12b9e3509 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
@@ -43,13 +43,14 @@ public class PfReferenceTimestampKeyTest {
@Test
public void testPfReferenceTimestampKeyConstruct() {
- assertThat(new PfReferenceTimestampKey().getLocalName()).isEqualTo(PfKey.NULL_KEY_NAME);
- assertEquals(PfKey.NULL_KEY_NAME, new PfReferenceTimestampKey(new PfConceptKey()).getParentKeyName());
+ assertThat(new PfReferenceTimestampKey().getReferenceKey().getLocalName()).isEqualTo(PfKey.NULL_KEY_NAME);
+ assertEquals(PfKey.NULL_KEY_NAME, new PfReferenceTimestampKey(new PfConceptKey()).getReferenceKey()
+ .getParentKeyName());
assertNotNull(new PfReferenceTimestampKey(new PfReferenceTimestampKey()).getTimeStamp());
assertEquals(LOCAL_NAME,
new PfReferenceTimestampKey(new PfReferenceKey(), LOCAL_NAME, Instant.ofEpochSecond(timeStamp))
- .getLocalName());
+ .getReferenceKey().getLocalName());
assertEquals(Timestamp.from(Instant.ofEpochSecond(timeStamp)), new PfReferenceTimestampKey(new PfConceptKey(),
PARENT_LOCAL_NAME, LOCAL_NAME, Instant.ofEpochSecond(timeStamp)).getTimeStamp());
@@ -58,7 +59,7 @@ public class PfReferenceTimestampKeyTest {
assertThat(
new PfReferenceTimestampKey("ParentKeyName", VERSION001, LOCAL_NAME, Instant.ofEpochSecond(timeStamp))
- .getParentLocalName()).isEqualTo(PfKey.NULL_KEY_NAME);
+ .getReferenceKey().getParentLocalName()).isEqualTo(PfKey.NULL_KEY_NAME);
assertEquals(PfReferenceTimestampKey.getNullKey().getKey(), PfReferenceTimestampKey.getNullKey());
assertEquals("NULL:0.0.0:NULL:NULL:" + Instant.EPOCH.getEpochSecond(),
@@ -67,9 +68,8 @@ public class PfReferenceTimestampKeyTest {
assertThatThrownBy(() -> new PfReferenceTimestampKey(new PfConceptKey(), null, null))
.hasMessage("parameter \"localName\" is null");
- assertTrue(new PfReferenceTimestampKey().isNullKey());
- assertFalse(new PfReferenceTimestampKey("ParentKeyName", VERSION001, PfKey.NULL_KEY_NAME,
- LOCAL_NAME, Instant.EPOCH).isNullKey());
+ PfReferenceTimestampKey testNullKey = new PfReferenceTimestampKey();
+ assertTrue(testNullKey.isNullKey());
String id = "NULL:0.0.0:NULL:NULL:" + timeStamp;
assertThat(new PfReferenceTimestampKey(id).getTimeStamp().getTime()).isEqualTo(timeStamp);
@@ -78,26 +78,26 @@ public class PfReferenceTimestampKeyTest {
@Test
public void testPfReferenceTimestampKey() {
PfReferenceTimestampKey testReferenceKey = new PfReferenceTimestampKey();
- testReferenceKey.setParentConceptKey(new PfConceptKey("PN", VERSION001));
- assertEquals("PN:0.0.1", testReferenceKey.getParentConceptKey().getId());
+ testReferenceKey.setReferenceKey(new PfReferenceKey(new PfConceptKey("PN", VERSION001)));
+ assertEquals("PN:0.0.1", testReferenceKey.getReferenceKey().getParentConceptKey().getId());
assertEquals(1, testReferenceKey.getKeys().size());
assertFalse(testReferenceKey.isNullKey());
- testReferenceKey.setParentReferenceKey(new PfReferenceKey("PN", VERSION001, "LN"));
- assertEquals("PN:0.0.1:NULL:LN", testReferenceKey.getParentReferenceKey().getId());
+ testReferenceKey.setReferenceKey(new PfReferenceKey("PN", VERSION001, "LN"));
+ assertEquals("PN:0.0.1:NULL:LN", testReferenceKey.getReferenceKey().getId());
- testReferenceKey.setParentKeyName("PKN");
- assertEquals("PKN", testReferenceKey.getParentKeyName());
+ testReferenceKey.getReferenceKey().setParentKeyName("PKN");
+ assertEquals("PKN", testReferenceKey.getReferenceKey().getParentKeyName());
- testReferenceKey.setParentKeyVersion(VERSION001);
- assertEquals(VERSION001, testReferenceKey.getParentKeyVersion());
+ testReferenceKey.getReferenceKey().setParentKeyVersion(VERSION001);
+ assertEquals(VERSION001, testReferenceKey.getReferenceKey().getParentKeyVersion());
- testReferenceKey.setParentLocalName(PARENT_LOCAL_NAME);
- assertEquals(PARENT_LOCAL_NAME, testReferenceKey.getParentLocalName());
+ testReferenceKey.getReferenceKey().setParentLocalName(PARENT_LOCAL_NAME);
+ assertEquals(PARENT_LOCAL_NAME, testReferenceKey.getReferenceKey().getParentLocalName());
- testReferenceKey.setLocalName("LN");
- assertEquals("LN", testReferenceKey.getLocalName());
+ testReferenceKey.getReferenceKey().setLocalName("LN");
+ assertEquals("LN", testReferenceKey.getReferenceKey().getLocalName());
testReferenceKey.setTimeStamp(Timestamp.from(DEFAULT_TIMESTAMP));
assertEquals(Timestamp.from(DEFAULT_TIMESTAMP), testReferenceKey.getTimeStamp());
@@ -116,22 +116,23 @@ public class PfReferenceTimestampKeyTest {
PfReferenceTimestampKey clonedReferenceKey = new PfReferenceTimestampKey(testReferenceKey);
- assertEquals("PfReferenceTimestampKey(super=PfReferenceKey(parentKeyName=PKN, parentKeyVersion=0.0.1, "
- + "parentLocalName=ParentLocalName, localName=LN), timeStamp=" + Timestamp.from(Instant.EPOCH) + ")",
- clonedReferenceKey.toString());
+ assertEquals("PfReferenceTimestampKey(timeStamp=" + Timestamp.from(Instant.EPOCH) + ","
+ + " referenceKey=PfReferenceKey(parentKeyName=PKN, parentKeyVersion=0.0.1, "
+ + "parentLocalName=ParentLocalName, localName=LN))", clonedReferenceKey.toString());
assertNotEquals(0, testReferenceKey.hashCode());
assertEquals(testReferenceKey, clonedReferenceKey);
- assertNotEquals(testReferenceKey,
- new PfReferenceTimestampKey("PKN", VERSION001, "PLN", "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))));
+ assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceTimestampKey()));
+ 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))));