summaryrefslogtreecommitdiffstats
path: root/applications/native
diff options
context:
space:
mode:
Diffstat (limited to 'applications/native')
-rw-r--r--applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java25
-rw-r--r--applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java6
2 files changed, 18 insertions, 13 deletions
diff --git a/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java b/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java
index 7302b676..3411d365 100644
--- a/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java
+++ b/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java
@@ -30,13 +30,15 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
-import java.util.Map;
-import org.apache.commons.collections4.MapUtils;
+import lombok.Getter;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
import org.onap.policy.models.decisions.concepts.DecisionResponse;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator;
+import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslatorUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,7 +51,6 @@ import org.slf4j.LoggerFactory;
public class NativePdpApplicationTranslator implements ToscaPolicyTranslator {
private static final Logger LOGGER = LoggerFactory.getLogger(NativePdpApplicationTranslator.class);
- private static final String POLICY = "policy";
public NativePdpApplicationTranslator() {
super();
@@ -87,14 +88,11 @@ public class NativePdpApplicationTranslator implements ToscaPolicyTranslator {
private String getNativeXacmlPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
- Map<String, Object> propertyMap = toscaPolicy.getProperties();
- if (MapUtils.isEmpty(propertyMap) || !propertyMap.containsKey(POLICY)) {
- throw new ToscaPolicyConversionException("no xacml native policy found in the tosca policy");
- }
+ NativeDefinition nativeDefinition = ToscaPolicyTranslatorUtils.decodeProperties(toscaPolicy.getProperties(),
+ NativeDefinition.class);
- var nativePolicyString = propertyMap.get(POLICY).toString();
- LOGGER.debug("Base64 encoded native xacml policy {}", nativePolicyString);
- return nativePolicyString;
+ LOGGER.debug("Base64 encoded native xacml policy {}", nativeDefinition.getPolicy());
+ return nativeDefinition.getPolicy();
}
@Override
@@ -109,4 +107,11 @@ public class NativePdpApplicationTranslator implements ToscaPolicyTranslator {
//
return null;
}
+
+ @Getter
+ public static class NativeDefinition {
+ @NotNull
+ @NotBlank
+ private String policy;
+ }
}
diff --git a/applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java b/applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java
index 3a405a89..83b65e5a 100644
--- a/applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java
+++ b/applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java
@@ -160,15 +160,15 @@ public class NativePdpApplicationTest {
if ("bad.base64".equals(policy.getName())) {
assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
translator.convertPolicy(policy)
- ).withMessageContaining("error on Base64 decoding the native policy");
+ ).as(policy.getName()).withMessageContaining("error on Base64 decoding the native policy");
} else if ("bad.noproperties".equals(policy.getName())) {
assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
translator.convertPolicy(policy)
- ).withMessageContaining("no xacml native policy found in the tosca policy");
+ ).as(policy.getName()).withMessageContaining("Cannot decode NativeDefinition from null properties");
} else if ("bad.policy".equals(policy.getName())) {
assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
translator.convertPolicy(policy)
- ).withMessageContaining("Invalid XACML Policy");
+ ).as(policy.getName()).withMessageContaining("Invalid XACML Policy");
}
}
}