aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java
diff options
context:
space:
mode:
authorPamela Dragosh <pd1248@att.com>2021-07-15 15:27:05 -0400
committerPamela Dragosh <pd1248@att.com>2021-07-16 09:42:38 -0400
commit7711185bb36b387e3596653ca170262f919ff474 (patch)
tree3928d1eeb6508ebb8ebb72f332656efae9aa5074 /main/src/test/java
parent85bf9c859768611cf1cc9ab38cf8f75ec33fc0ee (diff)
Add exclusions parameter
Adds the exclusions parameter to exclude applications that are in the java classpath. This allows overriding default packaged applications with another that can support new policy types and/or modify existing functionality. Issue-ID: POLICY-3326 Change-Id: Iaad8d26fc4122ad17226ad1e83b72c9f284e6ebd Signed-off-by: Pamela Dragosh <pd1248@att.com>
Diffstat (limited to 'main/src/test/java')
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java7
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java1
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java15
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestGuardOverrideApplication.java70
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java12
5 files changed, 101 insertions, 4 deletions
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
index 8b79ae9b..21475da8 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
@@ -176,12 +176,17 @@ public class CommonTestData {
*
* @param isEmpty boolean value to represent that object created should be empty or not
* @param tempPath Application Path string
+ * @param exclusions An optional list of application classnames for exclusion
* @return a property map suitable for constructing an object
*/
- public Map<String, Object> getXacmlapplicationParametersMap(boolean isEmpty, String tempPath) {
+ public Map<String, Object> getXacmlapplicationParametersMap(boolean isEmpty, String tempPath,
+ String... exclusions) {
final Map<String, Object> map = new TreeMap<>();
if (!isEmpty) {
map.put("applicationPath", tempPath);
+ if (exclusions != null) {
+ map.put("exclusions", List.of(exclusions));
+ }
}
return map;
}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
index f71c99c2..cb9825cc 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
@@ -81,6 +81,7 @@ public class TestXacmlPdpParameterGroup {
assertEquals("flavor", pdpxParameters.getPdpType());
assertFalse(pdpxParameters.getRestServerParameters().isHttps());
assertFalse(pdpxParameters.getRestServerParameters().isAaf());
+ assertThat(pdpxParameters.getApplicationParameters().getExclusions()).isEmpty();
}
@Test
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java
index 1e86fee7..00e95db7 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java
@@ -21,6 +21,7 @@
package org.onap.policy.pdpx.main.parameters;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -169,6 +170,20 @@ public class TestXacmlPdpParameterHandler {
}
@Test
+ public void testXacmlPdpParameterGroup_Exclusions() throws PolicyXacmlPdpException {
+ final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters_Exclusions.json"};
+
+ final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
+ arguments.parse(xacmlPdpConfigParameters);
+
+ final XacmlPdpParameterGroup parGroup = new XacmlPdpParameterHandler().getParameters(arguments);
+ assertTrue(arguments.checkSetConfigurationFilePath());
+ assertEquals(CommonTestData.PDPX_PARAMETER_GROUP_NAME, parGroup.getName());
+ assertEquals(CommonTestData.PDPX_GROUP, parGroup.getPdpGroup());
+ assertThat(parGroup.getApplicationParameters().getExclusions()).hasSize(2);
+ }
+
+ @Test
public void testXacmlPdpVersion() throws PolicyXacmlPdpException {
final String[] xacmlPdpConfigParameters = {"-v"};
final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestGuardOverrideApplication.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestGuardOverrideApplication.java
new file mode 100644
index 00000000..1b8411e5
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestGuardOverrideApplication.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pdpx.main.rest;
+
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator;
+import org.onap.policy.xacml.pdp.application.guard.GuardPdpApplication;
+import org.onap.policy.xacml.pdp.application.guard.GuardTranslator;
+
+public class TestGuardOverrideApplication extends GuardPdpApplication {
+ public static final String MY_EXTRAGUARD_POLICY_TYPE = "onap.policies.controlloop.guard.common.myGuard";
+
+ private static class MyTranslator extends GuardTranslator {
+
+ }
+
+ private final GuardTranslator myTranslator = new MyTranslator();
+
+ /**
+ * Constructor calls the super to add all the default policy types,
+ * and then adds the extra supported guard policy type.
+ */
+ public TestGuardOverrideApplication() {
+ super();
+ this.supportedPolicyTypes.add(new ToscaConceptIdentifier(
+ MY_EXTRAGUARD_POLICY_TYPE,
+ STRING_VERSION100));
+
+ }
+
+ @Override
+ protected ToscaPolicyTranslator getTranslator(String type) {
+ if (MY_EXTRAGUARD_POLICY_TYPE.equals(type)) {
+ return myTranslator;
+ }
+ return super.getTranslator(type);
+ }
+
+ @Override
+ public boolean canSupportPolicyType(ToscaConceptIdentifier policyTypeId) {
+ boolean canSuper = super.canSupportPolicyType(policyTypeId);
+ if (canSuper) {
+ return canSuper;
+ }
+ if (MY_EXTRAGUARD_POLICY_TYPE.equals(policyTypeId.getName())) {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java
index 4619b2ae..c79ebb52 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java
@@ -46,7 +46,6 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
import org.onap.policy.pdpx.main.parameters.CommonTestData;
import org.onap.policy.pdpx.main.parameters.XacmlApplicationParameters;
-import org.onap.policy.xacml.pdp.application.guard.GuardPdpApplication;
import org.onap.policy.xacml.pdp.application.nativ.NativePdpApplication;
import org.onap.policy.xacml.pdp.application.optimization.OptimizationPdpApplication;
import org.slf4j.Logger;
@@ -142,9 +141,11 @@ public class XacmlPdpApplicationManagerTest {
@Test
public void testXacmlPdpApplicationManagerSimple() {
+ final String[] exclusions = {"org.onap.policy.xacml.pdp.application.guard.GuardPdpApplication",
+ "org.onap.policy.xacml.pdp.application.match.MatchPdpApplication" };
final XacmlApplicationParameters xacmlApplicationParameters =
testData.toObject(testData.getXacmlapplicationParametersMap(false,
- appsDirectory.toString()), XacmlApplicationParameters.class);
+ appsDirectory.toString(), exclusions), XacmlApplicationParameters.class);
XacmlPdpApplicationManager manager = new XacmlPdpApplicationManager(xacmlApplicationParameters, params);
//
// Test the basics from the startup
@@ -162,7 +163,12 @@ public class XacmlPdpApplicationManagerTest {
request.setAction("optimize");
assertThat(manager.findApplication(request)).isInstanceOf(OptimizationPdpApplication.class);
request.setAction("guard");
- assertThat(manager.findApplication(request)).isInstanceOf(GuardPdpApplication.class);
+ assertThat(manager.findApplication(request)).isInstanceOf(TestGuardOverrideApplication.class);
+ //
+ // Test Exclusion
+ //
+ request.setAction("match");
+ assertThat(manager.findApplication(request)).isNull();
//
// Try to unload a policy that isn't loaded
//