aboutsummaryrefslogtreecommitdiffstats
path: root/applications/optimization/src
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-04-08 08:47:38 -0400
committerPamela Dragosh <pdragosh@research.att.com>2019-04-10 08:39:41 -0400
commite034d785a227815f66138d1f83f49624c402aa97 (patch)
tree38feabe112c00b97bc3deab32c4fb845f63a7b04 /applications/optimization/src
parent5dd6d165a0b3ee88563e5bcabd4c2a7fc42a676b (diff)
Test decision from main entry
Tests a decision upon startup. This also updates the use of ToscaPolicyTypeIdentifier for all the applications. Very basic packaging for applications and their properties. Added cleaning of unused imports to remove sonar issues. Added production persistence.xml file to guard application. Not sure if we need a copy in the application/common resource directory. Issue-ID: POLICY-1440 Change-Id: If96eef5a9e0a7c6cc5461c0bdb6f0cd708cc41bb Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'applications/optimization/src')
-rw-r--r--applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java55
-rw-r--r--applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java14
2 files changed, 44 insertions, 25 deletions
diff --git a/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java b/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java
index 4a4a6046..accf7a0c 100644
--- a/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java
+++ b/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java
@@ -25,12 +25,12 @@ package org.onap.policy.xacml.pdp.application.optimization;
import com.att.research.xacml.api.Request;
import com.att.research.xacml.api.Response;
import com.att.research.xacml.util.XACMLPolicyWriter;
-import com.google.common.collect.Lists;
import java.io.IOException;
import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -39,6 +39,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
import org.onap.policy.models.decisions.concepts.DecisionResponse;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
import org.onap.policy.pdp.xacml.application.common.std.StdMatchableTranslator;
@@ -52,26 +53,35 @@ public class OptimizationPdpApplication extends StdXacmlApplicationServiceProvid
private static final String STRING_VERSION100 = "1.0.0";
private StdMatchableTranslator translator = new StdMatchableTranslator();
- private Map<String, String> supportedPolicyTypes = new HashMap<>();
+ private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>();
/**
* Constructor.
*/
public OptimizationPdpApplication() {
- this.supportedPolicyTypes.put("onap.policies.optimization.AffinityPolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.DistancePolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.HpaPolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.OptimizationPolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.PciPolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.QueryPolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.SubscriberPolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.Vim_fit", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.VnfPolicy", STRING_VERSION100);
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.AffinityPolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.DistancePolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.HpaPolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.OptimizationPolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.PciPolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.QueryPolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.SubscriberPolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.Vim_fit", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.VnfPolicy", STRING_VERSION100));
}
@Override
public String applicationName() {
- return "Optimization Application";
+ return "optimization";
}
@Override
@@ -80,23 +90,26 @@ public class OptimizationPdpApplication extends StdXacmlApplicationServiceProvid
}
@Override
- public synchronized List<String> supportedPolicyTypes() {
- return Lists.newArrayList(supportedPolicyTypes.keySet());
+ public synchronized List<ToscaPolicyTypeIdentifier> supportedPolicyTypes() {
+ return Collections.unmodifiableList(supportedPolicyTypes);
}
@Override
- public boolean canSupportPolicyType(String policyType, String policyTypeVersion) {
+ public boolean canSupportPolicyType(ToscaPolicyTypeIdentifier policyTypeId) {
//
// For the time being, restrict this if the version isn't known.
// Could be too difficult to support changing of versions dynamically.
//
- if (! this.supportedPolicyTypes.containsKey(policyType)) {
- return false;
- }
//
- // Must match version exactly
+ // For the time being, restrict this if the version isn't known.
+ // Could be too difficult to support changing of versions dynamically.
//
- return this.supportedPolicyTypes.get(policyType).equals(policyTypeVersion);
+ for (ToscaPolicyTypeIdentifier supported : this.supportedPolicyTypes) {
+ if (policyTypeId.equals(supported)) {
+ return true;
+ }
+ }
+ return false;
}
@Override
diff --git a/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java b/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java
index efbf730c..e593d5fe 100644
--- a/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java
+++ b/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java
@@ -47,6 +47,8 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.TextFileUtils;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
import org.onap.policy.models.decisions.concepts.DecisionResponse;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
import org.slf4j.Logger;
@@ -139,8 +141,10 @@ public class OptimizationPdpApplicationTest {
// Ensure it has the supported policy types and
// can support the correct policy types.
//
- assertThat(service.canSupportPolicyType("onap.policies.optimization.AffinityPolicy", "1.0.0")).isTrue();
- assertThat(service.canSupportPolicyType("onap.foobar", "1.0.0")).isFalse();
+ assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.AffinityPolicy", "1.0.0"))).isTrue();
+ assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier(
+ "onap.foobar", "1.0.0"))).isFalse();
}
@Test
@@ -157,7 +161,8 @@ public class OptimizationPdpApplicationTest {
@SuppressWarnings("unchecked")
@Test
- public void test3AddOptimizationPolicies() throws CoderException, FileNotFoundException, IOException {
+ public void test3AddOptimizationPolicies() throws CoderException, FileNotFoundException, IOException,
+ XacmlApplicationException {
//
// Now load the optimization policies
//
@@ -184,8 +189,9 @@ public class OptimizationPdpApplicationTest {
//
assertThat(policyDefinition.containsKey("type")).isTrue();
assertThat(service.canSupportPolicyType(
+ new ToscaPolicyTypeIdentifier(
policyDefinition.get("type").toString(),
- policyDefinition.get("version").toString()))
+ policyDefinition.get("version").toString())))
.isTrue();
}
}