Merge "Allow providers other than PolicyModelsProvider"
authorRam Krishna Verma <ram_krishna.verma@bell.ca>
Tue, 19 Jan 2021 22:21:53 +0000 (22:21 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 19 Jan 2021 22:21:53 +0000 (22:21 +0000)
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityKey.java
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyConceptIdentifierTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeConceptIdentifierTest.java

index 36e460e..ade1a28 100644 (file)
@@ -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) {
index adde63b..caf02fc 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ * 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.
@@ -35,4 +35,8 @@ import lombok.NoArgsConstructor;
 public class ToscaEntityKey {
     private String name;
     private String version;
+
+    public ToscaConceptIdentifier asIdentifier() {
+        return new ToscaConceptIdentifier(name, version);
+    }
 }
index 6f49fd4..993c21e 100644 (file)
@@ -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);
index 59f471a..ba39621 100644 (file)
@@ -46,6 +46,7 @@ public class ToscaPolicyTest {
         policy.setTypeVersion("3.2.1");
 
         assertEquals("ToscaEntityKey(name=my_name, version=1.2.3)", policy.getKey().toString());
+        assertEquals(new ToscaConceptIdentifier("my_name", "1.2.3"), policy.getKey().asIdentifier());
 
         ToscaConceptIdentifier ident = policy.getIdentifier();
         assertEquals("my_name", ident.getName());
index 7845a1f..d37f293 100644 (file)
@@ -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();