aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java5
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java25
2 files changed, 28 insertions, 2 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java
index d5ddb0522..adfd616c3 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java
@@ -51,6 +51,11 @@ public class ToscaPolicyIdentifierOptVersion implements Comparable<ToscaPolicyId
this.version = source.version;
}
+ public ToscaPolicyIdentifierOptVersion(ToscaPolicyIdentifier source) {
+ this.name = source.getName();
+ this.version = source.getVersion();
+ }
+
/**
* Determines if the version is null/missing.
*
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java
index 3f0a7b09c..1d393c1d5 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java
@@ -39,7 +39,7 @@ public class ToscaPolicyIdentifierOptVersionTest extends ToscaIdentifierTestBase
@Test
public void testAllArgsConstructor_testIsNullVersion() {
assertThatThrownBy(() -> new ToscaPolicyIdentifierOptVersion(null, VERSION))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
// with null version
ToscaPolicyIdentifierOptVersion orig = new ToscaPolicyIdentifierOptVersion(NAME, null);
@@ -55,7 +55,8 @@ public class ToscaPolicyIdentifierOptVersionTest extends ToscaIdentifierTestBase
@Test
public void testCopyConstructor() throws Exception {
- assertThatThrownBy(() -> new ToscaPolicyIdentifierOptVersion(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new ToscaPolicyIdentifierOptVersion((ToscaPolicyIdentifierOptVersion) null))
+ .isInstanceOf(NullPointerException.class);
ToscaPolicyIdentifierOptVersion orig = new ToscaPolicyIdentifierOptVersion();
@@ -68,6 +69,26 @@ public class ToscaPolicyIdentifierOptVersionTest extends ToscaIdentifierTestBase
}
@Test
+ public void testCopyToscaPolicyIdentifierConstructor() throws Exception {
+ assertThatThrownBy(() -> new ToscaPolicyIdentifierOptVersion((ToscaPolicyIdentifier) null))
+ .isInstanceOf(NullPointerException.class);
+
+ ToscaPolicyIdentifier orig = new ToscaPolicyIdentifier();
+
+ // verify with null values
+ ToscaPolicyIdentifierOptVersion newIdent = new ToscaPolicyIdentifierOptVersion(orig);
+ assertEquals(null, newIdent.getName());
+ assertEquals(null, newIdent.getVersion());
+
+ // verify with all values
+ orig.setName(NAME);
+ orig.setVersion(VERSION);
+ newIdent = new ToscaPolicyIdentifierOptVersion(orig);
+ assertEquals(NAME, newIdent.getName());
+ assertEquals(VERSION, newIdent.getVersion());
+ }
+
+ @Test
public void testCompareTo() throws Exception {
super.testCompareTo();
}