Create ToscaConceptIdentifier from ToscaEntityKey 43/116943/1
authorliamfallon <liam.fallon@est.tech>
Mon, 18 Jan 2021 09:25:34 +0000 (09:25 +0000)
committerliamfallon <liam.fallon@est.tech>
Mon, 18 Jan 2021 09:29:25 +0000 (09:29 +0000)
THis change adds a method to create a ToscaConceptIdentifer from a
ToscaEntityKey class. This method reduces the code vloume when
translating between these identifiers.

Issue-ID: POLICY-2971
Change-Id: Idd62339935d2ba78e6c60b40ee95fedac0642bef
Signed-off-by: liamfallon <liam.fallon@est.tech>
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/ToscaPolicyTest.java

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 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());