From 9d05da454d5adaa894b52e22affd0f155353206b Mon Sep 17 00:00:00 2001 From: rameshiyer27 Date: Tue, 23 Feb 2021 15:10:39 +0000 Subject: Fix Null key issue in PfReferenceTimestampKey isNUllKey check for PfReferenceTimestamp key is always returning false as the parent class is validating the child object in its method which has additional parameters (timestamp). Fixing the issue by validating only the fields of parent class. Issue-ID: POLICY-3069 Signed-off-by: zrrmmua Change-Id: Ie22d09552c9d0cedb7535bda359df0d70e1ebe77 --- .../src/main/java/org/onap/policy/models/base/PfReferenceKey.java | 6 ++++-- .../org/onap/policy/models/base/PfReferenceTimestampKeyTest.java | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'models-base/src') diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java index 9a986481b..b25d4632b 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 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"); @@ -253,7 +253,9 @@ public class PfReferenceKey extends PfKey { @Override public boolean isNullKey() { - return this.equals(PfReferenceKey.getNullKey()); + return (PfReferenceKey.NULL_KEY_NAME.equals(this.getParentKeyName()) && PfReferenceKey.NULL_KEY_VERSION + .equals(this.getParentKeyVersion()) && PfReferenceKey.NULL_KEY_NAME.equals(this.getParentLocalName()) + && PfReferenceKey.NULL_KEY_NAME.equals(this.getLocalName())); } /** 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 c4762a201..061760aeb 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 @@ -67,9 +67,12 @@ 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()); + String id = "NULL:0.0.0:NULL:NULL:" + timeStamp; assertThat(new PfReferenceTimestampKey(id).getTimeStamp().getTime()).isEqualTo(timeStamp); - } @Test -- cgit 1.2.3-korg