Fix Raw XACML Decision API Serialization
[policy/xacml-pdp.git] / main / src / test / java / org / onap / policy / pdpx / main / rest / TestDecision.java
index 6f7dec6..b369ad3 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 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");
@@ -46,13 +46,12 @@ import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
 import org.onap.policy.common.endpoints.http.client.HttpClient;
 import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.parameters.RestClientParameters;
 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
-import org.onap.policy.common.gson.GsonMessageBodyHandler;
 import org.onap.policy.common.utils.network.NetworkUtil;
 import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
@@ -60,6 +59,7 @@ import org.onap.policy.models.decisions.concepts.DecisionResponse;
 import org.onap.policy.models.errors.concepts.ErrorResponse;
 import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
 import org.onap.policy.pdpx.main.parameters.CommonTestData;
+import org.onap.policy.pdpx.main.parameters.XacmlApplicationParameters;
 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
 import org.onap.policy.pdpx.main.startstop.Main;
 import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator;
@@ -105,13 +105,16 @@ public class TestDecision {
         //
         RestServerParameters rest =
             testData.toObject(testData.getRestServerParametersMap(port), RestServerParameters.class);
-        RestServerParameters policyApiParameters =
-                        testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
+        RestClientParameters policyApiParameters =
+                        testData.toObject(testData.getPolicyApiParametersMap(false), RestClientParameters.class);
         TopicParameterGroup topicParameterGroup =
                         testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
+        final XacmlApplicationParameters xacmlApplicationParameters =
+                testData.toObject(testData.getXacmlapplicationParametersMap(false,
+                        apps.getAbsolutePath().toString()), XacmlApplicationParameters.class);
         XacmlPdpParameterGroup params =
-                new XacmlPdpParameterGroup("XacmlPdpParameters", "XacmlPdpGroup", rest, policyApiParameters,
-                        topicParameterGroup, apps.getAbsolutePath());
+                new XacmlPdpParameterGroup("XacmlPdpParameters", "XacmlPdpGroup", "xacml", rest, policyApiParameters,
+                        topicParameterGroup, xacmlApplicationParameters);
         final Gson gson = new GsonBuilder().create();
         File fileParams = appsFolder.newFile("params.json");
         String jsonParams = gson.toJson(params);
@@ -121,7 +124,7 @@ public class TestDecision {
         // Start the service
         //
         main = startXacmlPdpService(fileParams);
-        XacmlPdpActivator.getCurrent().startXacmlRestController();
+        XacmlPdpActivator.getCurrent().enableApi();
         //
         // Make sure it is running
         //
@@ -198,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 {
@@ -225,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());
 
@@ -242,9 +245,8 @@ public class TestDecision {
     }
 
     private static HttpClient getNoAuthHttpClient() throws HttpClientConfigException {
-        return HttpClientFactoryInstance.getClientFactory().build(BusTopicParams.builder()
+        return HttpClientFactoryInstance.getClientFactory().build(RestClientParameters.builder()
                 .clientName("testDecisionClient")
-                .serializationProvider(GsonMessageBodyHandler.class.getName())
                 .useHttps(false).allowSelfSignedCerts(false).hostname("localhost").port(port)
                 .basePath("policy/pdpx/v1")
                 .userName("healthcheck").password("zb!XztG34").managed(true).build());
@@ -258,4 +260,4 @@ public class TestDecision {
             LOGGER.error("Failed to copy {} to {}", source, dest);
         }
     }
-}
\ No newline at end of file
+}