aboutsummaryrefslogtreecommitdiffstats
path: root/auth/cli-editor/src/test
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2022-07-08 12:29:25 +0100
committerrameshiyer27 <ramesh.murugan.iyer@est.tech>2022-07-18 11:03:46 +0100
commit093d515e4f5e018dc33048b4f0d31c7ead6717ed (patch)
tree41e643642e3c68ced3b05df1a7dee0dc343eef8b /auth/cli-editor/src/test
parent3b9e1d6eff05e0523c43f066a3e0a7e70025352f (diff)
Support MetadataSet generation in APEX CLI Editor
In addition to the existing capabilities of CLI editor, new arguments added for generating Tosca policy template excluding the policy model entity. Also generates independent json file for node template comprising the policy model data. Issue-ID: POLICY-4084 Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech> Change-Id: I7c6a9570846e3ebfaa3f4ebc8d60faa94b533240
Diffstat (limited to 'auth/cli-editor/src/test')
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java30
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/CommonTestData.java1
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java2
3 files changed, 32 insertions, 1 deletions
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java
index b75199ac3..51659c2ea 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java
@@ -24,9 +24,12 @@ package org.onap.policy.apex.auth.clieditor.tosca;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -42,6 +45,7 @@ public class ApexCliToscaEditorTest {
private File tempOutputToscaFile;
private File tempLogFile;
String[] sampleArgs;
+ private File tempNodeTemplateFile;
/**
* Initialise args.
@@ -52,6 +56,7 @@ public class ApexCliToscaEditorTest {
public void initialiseArgs() throws IOException {
tempOutputToscaFile = File.createTempFile("ToscaPolicyOutput", ".json");
+ tempNodeTemplateFile = File.createTempFile("ToscaNodeTemplate", ".json");
tempLogFile = File.createTempFile("ApexCliTosca", ".log");
sampleArgs = new String[] {
"-c", CommonTestData.COMMAND_FILE_NAME,
@@ -69,6 +74,7 @@ public class ApexCliToscaEditorTest {
public void removeGeneratedFiles() {
tempOutputToscaFile.delete();
tempLogFile.delete();
+ tempNodeTemplateFile.delete();
}
@Test
@@ -110,4 +116,28 @@ public class ApexCliToscaEditorTest {
};
assertThatThrownBy(() -> new ApexCliToscaEditorMain(sampleArgs)).hasMessage("Insufficient arguments provided.");
}
+
+ @Test
+ public void testGenerateToscaPolicyMetadataSet() throws Exception {
+ // @formatter:off
+ final String[] cliArgs = new String[] {
+ "-c", CommonTestData.COMMAND_FILE_NAME,
+ "-l", tempLogFile.getAbsolutePath(),
+ "-ac", CommonTestData.APEX_CONFIG_FILE_NAME,
+ "-t", CommonTestData.INPUT_TOSCA_TEMPLATE_FILE_NAME,
+ "-ot", tempOutputToscaFile.getAbsolutePath(),
+ "-on", tempNodeTemplateFile.getAbsolutePath(),
+ "-nt", CommonTestData.NODE_TYPE
+ };
+ // @formatter:on
+
+ new ApexCliToscaEditorMain(cliArgs);
+
+ assertTrue(tempOutputToscaFile.length() > 0);
+ assertTrue(Files.lines(Paths.get(tempOutputToscaFile.toString()))
+ .noneMatch(l -> l.contains("policy_type_impl")));
+ assertTrue(tempNodeTemplateFile.length() > 0);
+ assertTrue(Files.lines(Paths.get(tempNodeTemplateFile.toString()))
+ .anyMatch(l -> l.contains("policyModel")));
+ }
}
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/CommonTestData.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/CommonTestData.java
index 23d927e24..a3b4bcd44 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/CommonTestData.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/CommonTestData.java
@@ -36,4 +36,5 @@ public final class CommonTestData {
public static final String APEX_CONFIG_FILE_NAME = "src/test/resources/tosca/ApexConfig.json";
public static final String COMMAND_FILE_NAME = "src/test/resources/tosca/PolicyModel.apex";
public static final String POLICY_MODEL_FILE_NAME = "src/test/resources/tosca/PolicyModel.json";
+ public static final String NODE_TYPE = "org.onap.nodetypes.policy.MetadataSet";
}
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java
index 2ce34e148..ba3ab7627 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java
@@ -79,7 +79,7 @@ public class CliUtilsTest {
@Test
public void testCreateToscaServiceTemplate() throws IOException, CoderException {
ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs);
- CliUtils.createToscaServiceTemplate(params, policyModelFilePath);
+ CliUtils.createToscaPolicy(params, policyModelFilePath, null);
String outputTosca = TextFileUtils.getTextFileAsString(tempOutputToscaFile.getAbsolutePath());
String outputToscaCompare =
TextFileUtils.getTextFileAsString("src/test/resources/tosca/ToscaPolicyOutput_compare_1.json").trim();