aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2021-01-19 13:18:06 +0000
committerGerrit Code Review <gerrit@onap.org>2021-01-19 13:18:06 +0000
commitc908b4953e00de5a4728480af3467ec5e987f8bc (patch)
treeb137abd52564aeb1cb387c4a3c07097bfa2bb7f5 /models-tosca
parenta00536c5c65efbef3fc23bcd83fdcca940b3ceba (diff)
parentcc12166b729fba5ec91e00897af4803f0fe6889a (diff)
Merge "Add PfKey translation to ToscaConceptIdentifier"
Diffstat (limited to 'models-tosca')
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java16
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyConceptIdentifierTest.java19
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeConceptIdentifierTest.java5
3 files changed, 36 insertions, 4 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java
index 36e460e83..ade1a28d4 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java
@@ -27,6 +27,8 @@ import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
/**
* Identifies a concept. Both the name and version must be non-null.
@@ -47,6 +49,11 @@ public class ToscaConceptIdentifier implements Comparable<ToscaConceptIdentifier
this.version = version;
}
+ public ToscaConceptIdentifier(@NonNull PfKey key) {
+ this.name = key.getName();
+ this.version = key.getVersion();
+ }
+
public ToscaConceptIdentifier(ToscaConceptIdentifier source) {
this.name = source.name;
this.version = source.version;
@@ -66,6 +73,15 @@ public class ToscaConceptIdentifier implements Comparable<ToscaConceptIdentifier
return result;
}
+ /**
+ * Create a PfConcceptKey from the TOSCA identifier.
+ *
+ * @return the key
+ */
+ public PfConceptKey asConceptKey() {
+ return new PfConceptKey(name, version);
+ }
+
@Override
public int compareTo(ToscaConceptIdentifier other) {
if (this == other) {
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyConceptIdentifierTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyConceptIdentifierTest.java
index 6f49fd433..993c21e35 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyConceptIdentifierTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyConceptIdentifierTest.java
@@ -1,4 +1,4 @@
-/*
+/*-
* ============LICENSE_START=======================================================
* ONAP Policy Models
* ================================================================================
@@ -30,6 +30,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.models.base.PfConceptKey;
/**
* Test methods not tested by {@link PojosTest}.
@@ -52,7 +53,8 @@ public class ToscaPolicyConceptIdentifierTest extends ToscaIdentifierTestBase<To
@Test
public void testCopyConstructor() {
- assertThatThrownBy(() -> new ToscaConceptIdentifier(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new ToscaConceptIdentifier((ToscaConceptIdentifier) null))
+ .isInstanceOf(NullPointerException.class);
ToscaConceptIdentifier orig = new ToscaConceptIdentifier();
@@ -64,6 +66,19 @@ public class ToscaPolicyConceptIdentifierTest extends ToscaIdentifierTestBase<To
assertEquals(orig.toString(), new ToscaConceptIdentifier(orig).toString());
}
+
+ @Test
+ public void testPfKey() {
+ assertThatThrownBy(() -> new ToscaConceptIdentifier((PfConceptKey) null))
+ .isInstanceOf(NullPointerException.class);
+
+ PfConceptKey origKey = new PfConceptKey("Hello", "0.0.1");
+
+ assertEquals(origKey.getName(), new ToscaConceptIdentifier(origKey).getName());
+
+ assertEquals(origKey, new ToscaConceptIdentifier(origKey).asConceptKey());
+ }
+
@Test
public void testValidatePapRest() throws Exception {
ToscaConceptIdentifier ident = new ToscaConceptIdentifier(NAME, VERSION);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeConceptIdentifierTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeConceptIdentifierTest.java
index 7845a1f32..d37f29360 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeConceptIdentifierTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeConceptIdentifierTest.java
@@ -1,4 +1,4 @@
-/*
+/*-
* ============LICENSE_START=======================================================
* ONAP Policy Models
* ================================================================================
@@ -52,7 +52,8 @@ public class ToscaPolicyTypeConceptIdentifierTest extends ToscaIdentifierTestBas
@Test
public void testCopyConstructor() {
- assertThatThrownBy(() -> new ToscaConceptIdentifier(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new ToscaConceptIdentifier((ToscaConceptIdentifier) null))
+ .isInstanceOf(NullPointerException.class);
ToscaConceptIdentifier orig = new ToscaConceptIdentifier();