Fix Raw XACML Decision API Serialization 22/129822/1
authordc443y <dc443y@att.com>
Wed, 6 Jul 2022 19:25:55 +0000 (14:25 -0500)
committerdc443y <dc443y@att.com>
Thu, 7 Jul 2022 14:27:27 +0000 (09:27 -0500)
Issue-ID: POLICY-4274
Signed-off-by: dc443y <dc443y@att.com>
Change-Id: I0d367d35e7ec52c7587ec75194b654cc41303868
Signed-off-by: dc443y <dc443y@att.com>
main/src/main/java/org/onap/policy/pdpx/main/rest/serialization/XacmlJsonMessageBodyHandler.java
main/src/main/java/org/onap/policy/pdpx/main/rest/serialization/XacmlXmlMessageBodyHandler.java
main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java

index a6d9952..58ed5f7 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2022 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.
@@ -98,6 +98,6 @@ public class XacmlJsonMessageBodyHandler implements MessageBodyReader<Request>,
             return false;
         }
         return ("xacml+json".equals(mediaType.getSubtype()))
-                && (type == Request.class || type == Response.class);
+                && (Request.class.isAssignableFrom(type) || Response.class.isAssignableFrom(type));
     }
 }
index 4ddfbe2..5ec1763 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2022 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.
@@ -98,6 +98,6 @@ public class XacmlXmlMessageBodyHandler implements MessageBodyReader<Request>, M
         }
 
         return ("xacml+xml".equals(mediaType.getSubtype()))
-                && (type == Request.class || type == Response.class);
+                && (Request.class.isAssignableFrom(type) || Response.class.isAssignableFrom(type));
     }
 }
index fb7d717..b369ad3 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -201,11 +201,11 @@ public class TestDecision {
 
         String responseFromXmlRequest = getNativeDecision(xmlRequestAsString, APPLICATION_XACML_XML);
         LOGGER.info("Response from xml request {}", responseFromXmlRequest);
-        assertThat(responseFromXmlRequest).contains("NOTAPPLICABLE");
+        assertThat(responseFromXmlRequest).contains("<Response xmlns=").contains("NotApplicable");
 
         String responseFromJsonRequest = getNativeDecision(jsonRequestAsString, APPLICATION_XACML_JSON);
         LOGGER.info("Response from json request {}", responseFromJsonRequest);
-        assertThat(responseFromJsonRequest).contains("NOTAPPLICABLE");
+        assertThat(responseFromJsonRequest).contains("\"Response\":").contains("NotApplicable");
     }
 
     private static Main startXacmlPdpService(File params) throws PolicyXacmlPdpException {
@@ -228,7 +228,7 @@ public class TestDecision {
 
     private String getNativeDecision(String request, String mediaType) {
         Entity<String> entityRequest = Entity.entity(request, mediaType);
-        Response response = client.post("/xacml", entityRequest, Collections.emptyMap());
+        Response response = client.post("/xacml", entityRequest, Map.of("Accept", mediaType));
 
         assertEquals(200, response.getStatus());