/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 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");
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;
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;
private static Main main;
private static HttpClient client;
private static CommonTestData testData = new CommonTestData();
+ private static final String APPLICATION_XACML_XML = "application/xacml+xml";
+ private static final String APPLICATION_XACML_JSON = "application/xacml+json";
@ClassRule
public static final TemporaryFolder appsFolder = new TemporaryFolder();
//
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);
- XacmlPdpParameterGroup params = new XacmlPdpParameterGroup("XacmlPdpGroup", rest, policyApiParameters,
- topicParameterGroup, apps.getAbsolutePath());
+ final XacmlApplicationParameters xacmlApplicationParameters =
+ testData.toObject(testData.getXacmlapplicationParametersMap(false,
+ apps.getAbsolutePath().toString()), XacmlApplicationParameters.class);
+ XacmlPdpParameterGroup params =
+ 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);
// Start the service
//
main = startXacmlPdpService(fileParams);
- XacmlPdpActivator.getCurrent().startXacmlRestController();
+ XacmlPdpActivator.getCurrent().enableApi();
//
// Make sure it is running
//
@Test
public void testDecision_UnsupportedAction() throws Exception {
-
LOGGER.info("Running test testDecision_UnsupportedAction");
DecisionRequest request = new DecisionRequest();
@Test
public void testDecision_Guard() throws KeyManagementException, NoSuchAlgorithmException,
ClassNotFoundException {
-
LOGGER.info("Running test testDecision_Guard");
DecisionRequest request = new DecisionRequest();
assertThat(response.getStatus()).isEqualTo("Permit");
}
+ @Test
+ public void testDecision_Native() throws IOException {
+ LOGGER.info("Running test testDecision_Native");
+
+ String xmlRequestAsString = ResourceUtils.getResourceAsString(
+ "src/test/resources/decisions/decision.native.request.xml");
+ if (xmlRequestAsString == null) {
+ throw new IOException("failed to read the xml request");
+ }
+
+ String jsonRequestAsString = ResourceUtils.getResourceAsString(
+ "src/test/resources/decisions/decision.native.request.json");
+ if (jsonRequestAsString == null) {
+ throw new IOException("failed to read the json request");
+ }
+
+ String responseFromXmlRequest = getNativeDecision(xmlRequestAsString, APPLICATION_XACML_XML);
+ LOGGER.info("Response from xml request {}", responseFromXmlRequest);
+ assertThat(responseFromXmlRequest).contains("<Response xmlns=").contains("NotApplicable");
+
+ String responseFromJsonRequest = getNativeDecision(jsonRequestAsString, APPLICATION_XACML_JSON);
+ LOGGER.info("Response from json request {}", responseFromJsonRequest);
+ assertThat(responseFromJsonRequest).contains("\"Response\":").contains("NotApplicable");
+ }
+
private static Main startXacmlPdpService(File params) throws PolicyXacmlPdpException {
final String[] XacmlPdpConfigParameters = {"-c", params.getAbsolutePath()};
return new Main(XacmlPdpConfigParameters);
}
private DecisionResponse getDecision(DecisionRequest request) {
-
Entity<DecisionRequest> entityRequest = Entity.entity(request, MediaType.APPLICATION_JSON);
- Response response = client.post("", entityRequest, Collections.emptyMap());
+ Response response = client.post("/decision", entityRequest, Collections.emptyMap());
assertEquals(200, response.getStatus());
return HttpClient.getBody(response, DecisionResponse.class);
}
- private ErrorResponse getErrorDecision(DecisionRequest request) {
+ private String getNativeDecision(String request, String mediaType) {
+ Entity<String> entityRequest = Entity.entity(request, mediaType);
+ Response response = client.post("/xacml", entityRequest, Map.of("Accept", mediaType));
+
+ assertEquals(200, response.getStatus());
+ return HttpClient.getBody(response, String.class);
+ }
+
+ private ErrorResponse getErrorDecision(DecisionRequest request) {
Entity<DecisionRequest> entityRequest = Entity.entity(request, MediaType.APPLICATION_JSON);
- Response response = client.post("", entityRequest, Collections.emptyMap());
+ Response response = client.post("/decision", entityRequest, Collections.emptyMap());
assertEquals(400, response.getStatus());
}
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/decision")
+ .basePath("policy/pdpx/v1")
.userName("healthcheck").password("zb!XztG34").managed(true).build());
}
LOGGER.error("Failed to copy {} to {}", source, dest);
}
}
-
-}
\ No newline at end of file
+}