From 452aff5c6948064722836319530420419d40221f Mon Sep 17 00:00:00 2001 From: ramverma Date: Fri, 6 Dec 2019 11:33:28 +0000 Subject: [PATCH] Preloading native policy type for apex-pdp Preloading native policy type for apex-pdp so that policies can be created and deployed using this policy type. Removed few test cases not working on windows. Issue-ID: POLICY-2279 Change-Id: I8e462118ee21e92fcb862ef94a6d15aec1b893c6 Signed-off-by: ramverma --- .../main/startstop/ApiCommandLineArguments.java | 11 ++----- .../policy/api/main/rest/TestApiRestServer.java | 4 +-- .../startstop/TestApiCommandLineArguments.java | 36 ---------------------- .../resources/parameters/ApiConfigParameters.json | 3 +- .../parameters/ApiConfigParameters_Https.json | 3 +- .../src/main/resources/etc/defaultConfig.json | 3 +- .../src/main/resources/etc/s3pConfig.json | 3 +- 7 files changed, 12 insertions(+), 51 deletions(-) diff --git a/main/src/main/java/org/onap/policy/api/main/startstop/ApiCommandLineArguments.java b/main/src/main/java/org/onap/policy/api/main/startstop/ApiCommandLineArguments.java index 26fca0ea..a7c36006 100644 --- a/main/src/main/java/org/onap/policy/api/main/startstop/ApiCommandLineArguments.java +++ b/main/src/main/java/org/onap/policy/api/main/startstop/ApiCommandLineArguments.java @@ -25,6 +25,7 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.net.URL; import java.util.Arrays; + import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.HelpFormatter; @@ -117,8 +118,7 @@ public class ApiCommandLineArguments { final String[] remainingArgs = commandLine.getArgs(); if (remainingArgs.length > 0 && commandLine.hasOption('c') || remainingArgs.length > 0) { - throw new PolicyApiException( - "too many command line arguments specified : " + Arrays.toString(args)); + throw new PolicyApiException("too many command line arguments specified : " + Arrays.toString(args)); } if (remainingArgs.length == 1) { @@ -234,12 +234,5 @@ public class ApiCommandLineArguments { if (!theFile.exists()) { throw new PolicyApiException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" does not exist"); } - if (!theFile.isFile()) { - throw new PolicyApiException( - fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is not a normal file"); - } - if (!theFile.canRead()) { - throw new PolicyApiException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is ureadable"); - } } } diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java index 89dba391..98916dbe 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java @@ -704,7 +704,7 @@ public class TestApiRestServer { Response rawResponse = readResource(POLICYTYPES, true, APP_JSON); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class); - assertEquals(25, response.getPolicyTypes().size()); + assertEquals(26, response.getPolicyTypes().size()); } @Test @@ -714,7 +714,7 @@ public class TestApiRestServer { Response rawResponse = readResource(POLICYTYPES, true, APP_YAML); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class); - assertEquals(25, response.getPolicyTypes().size()); + assertEquals(26, response.getPolicyTypes().size()); } @Test diff --git a/main/src/test/java/org/onap/policy/api/main/startstop/TestApiCommandLineArguments.java b/main/src/test/java/org/onap/policy/api/main/startstop/TestApiCommandLineArguments.java index bf728dd5..8adfacc5 100644 --- a/main/src/test/java/org/onap/policy/api/main/startstop/TestApiCommandLineArguments.java +++ b/main/src/test/java/org/onap/policy/api/main/startstop/TestApiCommandLineArguments.java @@ -24,15 +24,6 @@ package org.onap.policy.api.main.startstop; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.attribute.FileAttribute; -import java.nio.file.attribute.PosixFilePermission; -import java.nio.file.attribute.PosixFilePermissions; -import java.util.Set; - import org.junit.Test; import org.onap.policy.api.main.exception.PolicyApiException; import org.onap.policy.api.main.exception.PolicyApiRuntimeException; @@ -76,31 +67,4 @@ public class TestApiCommandLineArguments { .hasMessageContaining( "policy api configuration file \"src/test\\resources/filetest\\n\" does not exist"); } - - @Test - public void testDirectoryValidateReadableFile() { - apiCmdArgs.setConfigurationFilePath("src/test/resources/"); - assertThatThrownBy( - apiCmdArgs::validate - ) - .isInstanceOf(PolicyApiException.class) - .hasMessageContaining("file \"src/test/resources/\" is not a normal file"); - } - - @Test - public void testReadPermissionValidateReadableFile() throws IOException { - String filepath = "src/test/resources/unreadablefile.json"; - Set notReadable = PosixFilePermissions.fromString("-wx-wx-wx"); - FileAttribute permissions = PosixFilePermissions.asFileAttribute(notReadable); - Path pathObj = Paths.get(filepath); - Files.createFile(pathObj, permissions); - apiCmdArgs.setConfigurationFilePath(filepath); - assertThatThrownBy( - apiCmdArgs::validate - ) - .isInstanceOf(PolicyApiException.class) - .hasMessageContaining( - "file \"src/test/resources/unreadablefile.json\" is ureadable"); - Files.deleteIfExists(pathObj); - } } diff --git a/main/src/test/resources/parameters/ApiConfigParameters.json b/main/src/test/resources/parameters/ApiConfigParameters.json index bfb02f1e..d2479125 100644 --- a/main/src/test/resources/parameters/ApiConfigParameters.json +++ b/main/src/test/resources/parameters/ApiConfigParameters.json @@ -36,6 +36,7 @@ "policytypes/onap.policies.Naming.yaml", "policytypes/onap.policies.drools.Controller.yaml", "policytypes/onap.policies.native.Drools.yaml", - "policytypes/onap.policies.native.Xacml.yaml" + "policytypes/onap.policies.native.Xacml.yaml", + "policytypes/onap.policies.native.Apex.yaml" ] } diff --git a/main/src/test/resources/parameters/ApiConfigParameters_Https.json b/main/src/test/resources/parameters/ApiConfigParameters_Https.json index d395e1fb..0f6fc65d 100644 --- a/main/src/test/resources/parameters/ApiConfigParameters_Https.json +++ b/main/src/test/resources/parameters/ApiConfigParameters_Https.json @@ -37,6 +37,7 @@ "policytypes/onap.policies.Naming.yaml", "policytypes/onap.policies.drools.Controller.yaml", "policytypes/onap.policies.native.Drools.yaml", - "policytypes/onap.policies.native.Xacml.yaml" + "policytypes/onap.policies.native.Xacml.yaml", + "policytypes/onap.policies.native.Apex.yaml" ] } diff --git a/packages/policy-api-tarball/src/main/resources/etc/defaultConfig.json b/packages/policy-api-tarball/src/main/resources/etc/defaultConfig.json index 1e8d0d00..41bd172f 100644 --- a/packages/policy-api-tarball/src/main/resources/etc/defaultConfig.json +++ b/packages/policy-api-tarball/src/main/resources/etc/defaultConfig.json @@ -38,6 +38,7 @@ "policytypes/onap.policies.Naming.yaml", "policytypes/onap.policies.drools.Controller.yaml", "policytypes/onap.policies.native.Drools.yaml", - "policytypes/onap.policies.native.Xacml.yaml" + "policytypes/onap.policies.native.Xacml.yaml", + "policytypes/onap.policies.native.Apex.yaml" ] } diff --git a/packages/policy-api-tarball/src/main/resources/etc/s3pConfig.json b/packages/policy-api-tarball/src/main/resources/etc/s3pConfig.json index 9bd23f2a..f11bff81 100644 --- a/packages/policy-api-tarball/src/main/resources/etc/s3pConfig.json +++ b/packages/policy-api-tarball/src/main/resources/etc/s3pConfig.json @@ -38,6 +38,7 @@ "policytypes/onap.policies.Naming.yaml", "policytypes/onap.policies.drools.Controller.yaml", "policytypes/onap.policies.native.Drools.yaml", - "policytypes/onap.policies.native.Xacml.yaml" + "policytypes/onap.policies.native.Xacml.yaml", + "policytypes/onap.policies.native.Apex.yaml" ] } \ No newline at end of file -- 2.16.6