summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-08-28 15:20:18 -0400
committerJim Hahn <jrh3@att.com>2019-08-30 12:07:32 -0400
commit98873e8c202426b9d74d9460ebd30b57fa4c7eb7 (patch)
treedb56b53965c37b36008c99c49acf9e5d079c2fbf
parent30b9aa0d2e2e6b954e2ce25537d7d7ca81d3a5a4 (diff)
Get policy type from policy-api
Added a class to retrieve a policy type from the policy-api. Updated property files to include parameters that are needed to configure it. Updates per review comments: - change PolicyApi to PolicyApiCaller - use HttpClientFactory - removed superfluous constructors from exception classes - changed parameters to use RestServerParameters instead of BusTopicParams Change-Id: I8aad6ca5a733c8ad9cc983496e745ebe7400dd17 Issue-ID: POLICY-1911 Signed-off-by: Jim Hahn <jrh3@att.com>
-rw-r--r--applications/common/pom.xml5
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/NotFoundException.java41
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCaller.java106
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiException.java40
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/ExceptionTest.java37
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCallerTest.java201
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java67
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java66
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java45
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java8
-rw-r--r--main/src/test/resources/parameters/MinimumParameters.json8
-rw-r--r--main/src/test/resources/parameters/NoParameters.json6
-rw-r--r--main/src/test/resources/parameters/XacmlPdpConfigParameters.json6
-rw-r--r--main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json26
-rw-r--r--main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json19
-rw-r--r--main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json6
-rw-r--r--packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json8
17 files changed, 616 insertions, 79 deletions
diff --git a/applications/common/pom.xml b/applications/common/pom.xml
index 01447677..acc74ea7 100644
--- a/applications/common/pom.xml
+++ b/applications/common/pom.xml
@@ -49,6 +49,11 @@
</dependency>
<dependency>
<groupId>org.onap.policy.common</groupId>
+ <artifactId>policy-endpoints</artifactId>
+ <version>${policy.common.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
<artifactId>utils-test</artifactId>
<version>${policy.common.version}</version>
</dependency>
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/NotFoundException.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/NotFoundException.java
new file mode 100644
index 00000000..260d16f2
--- /dev/null
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/NotFoundException.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pdp.xacml.application.common;
+
+/**
+ * Exception indicating that the data of interest was not found when querying the
+ * policy-api.
+ */
+public class NotFoundException extends PolicyApiException {
+ private static final long serialVersionUID = 1L;
+
+ public NotFoundException(String message) {
+ super(message);
+ }
+
+ public NotFoundException(Throwable cause) {
+ super(cause);
+ }
+
+ public NotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCaller.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCaller.java
new file mode 100644
index 00000000..9d47517a
--- /dev/null
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCaller.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pdp.xacml.application.common;
+
+import java.net.HttpURLConnection;
+import javax.ws.rs.core.Response;
+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.RestServerParameters;
+import org.onap.policy.common.gson.GsonMessageBodyHandler;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Methods to access policy-api via REST service calls.
+ */
+public class PolicyApiCaller {
+ private static Logger logger = LoggerFactory.getLogger(PolicyApiCaller.class);
+
+ private static final String POLICY_TYPE_URI = "/policy/api/v1/policytypes/";
+ private static final String POLICY_TYPE_VERSION_URI = "/versions/";
+
+ private final HttpClient httpClient;
+
+ /**
+ * Constructs the object.
+ *
+ * @param params target specification
+ * @throws PolicyApiException if an error occurs
+ */
+ public PolicyApiCaller(RestServerParameters params) throws PolicyApiException {
+ BusTopicParams busParams = new BusTopicParams();
+ busParams.setClientName("policy-api");
+ busParams.setHostname(params.getHost());
+ busParams.setManaged(false);
+ busParams.setPassword(params.getPassword());
+ busParams.setPort(params.getPort());
+ busParams.setSerializationProvider(GsonMessageBodyHandler.class.getName());
+ busParams.setUseHttps(params.isHttps());
+ busParams.setUserName(params.getUserName());
+
+ try {
+ httpClient = makeClient(busParams);
+ } catch (HttpClientConfigException e) {
+ throw new PolicyApiException("connection to host: " + busParams.getHostname(), e);
+ }
+ }
+
+ /**
+ * Gets a policy type from policy-api.
+ *
+ * @param type policy type of interest
+ * @return the desired policy type
+ * @throws PolicyApiException if an error occurs
+ */
+ public ToscaPolicyType getPolicyType(ToscaPolicyTypeIdentifier type) throws PolicyApiException {
+
+ try {
+ Response resp = httpClient
+ .get(POLICY_TYPE_URI + type.getName() + POLICY_TYPE_VERSION_URI + type.getVersion());
+
+ switch (resp.getStatus()) {
+ case HttpURLConnection.HTTP_OK:
+ return resp.readEntity(ToscaPolicyType.class);
+ case HttpURLConnection.HTTP_NOT_FOUND:
+ logger.warn("policy-api not found {}", resp);
+ throw new NotFoundException(type.toString());
+ default:
+ logger.warn("policy-api request error {}", resp);
+ throw new PolicyApiException(type.toString());
+ }
+
+ } catch (RuntimeException e) {
+ logger.warn("policy-api connection error");
+ throw new PolicyApiException(type.toString(), e);
+ }
+ }
+
+ // these methods may be overridden by junit tests
+
+ protected HttpClient makeClient(BusTopicParams busParams) throws HttpClientConfigException {
+ return HttpClientFactoryInstance.getClientFactory().build(busParams);
+ }
+}
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiException.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiException.java
new file mode 100644
index 00000000..380bd19a
--- /dev/null
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/PolicyApiException.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pdp.xacml.application.common;
+
+/**
+ * Exception occurring while accessing the policy-api.
+ */
+public class PolicyApiException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public PolicyApiException(String message) {
+ super(message);
+ }
+
+ public PolicyApiException(Throwable cause) {
+ super(cause);
+ }
+
+ public PolicyApiException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/ExceptionTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/ExceptionTest.java
new file mode 100644
index 00000000..63c6b246
--- /dev/null
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/ExceptionTest.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pdp.xacml.application.common;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.common.utils.test.ExceptionsTester;
+
+public class ExceptionTest {
+
+ @Test
+ public void test() {
+ ExceptionsTester tester = new ExceptionsTester();
+
+ assertEquals(3, tester.test(PolicyApiException.class));
+ assertEquals(3, tester.test(NotFoundException.class));
+ }
+}
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCallerTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCallerTest.java
new file mode 100644
index 00000000..6e7ec7c8
--- /dev/null
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCallerTest.java
@@ -0,0 +1,201 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pdp.xacml.application.common;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.Properties;
+import java.util.UUID;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+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.server.HttpServletServer;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
+import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.gson.GsonMessageBodyHandler;
+import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PolicyApiCallerTest {
+ private static final String MY_TYPE = "my-type";
+
+ private static final String MY_VERSION = "1.0.0";
+
+ private static final Logger logger = LoggerFactory.getLogger(PolicyApiCallerTest.class);
+
+ private static final String CLIENT_NAME = "policy-api";
+ private static final String NOT_A_TYPE = "other-type";
+ private static final String INVALID_TYPE = "invalid";
+ private static final String UNKNOWN_TYPE = "unknown";
+
+ private static int port;
+ private static RestServerParameters clientParams;
+
+ private PolicyApiCaller api;
+
+ /**
+ * Initializes {@link #clientParams} and starts a simple REST server to handle the
+ * test requests.
+ *
+ * @throws IOException if an error occurs
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ port = NetworkUtil.allocPort();
+
+ clientParams = mock(RestServerParameters.class);
+ when(clientParams.getHost()).thenReturn("localhost");
+ when(clientParams.getPort()).thenReturn(port);
+
+ Properties props = new Properties();
+ props.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES, CLIENT_NAME);
+
+ final String svcpfx =
+ PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + CLIENT_NAME;
+
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, clientParams.getHost());
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX,
+ Integer.toString(clientParams.getPort()));
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX,
+ ApiRestController.class.getName());
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, "false");
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_AAF_SUFFIX, "false");
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER,
+ GsonMessageBodyHandler.class.getName());
+
+ HttpServletServerFactoryInstance.getServerFactory().build(props).forEach(HttpServletServer::start);
+
+ assertTrue(NetworkUtil.isTcpPortOpen(clientParams.getHost(), clientParams.getPort(), 100, 100));
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ HttpServletServerFactoryInstance.getServerFactory().destroy();
+ }
+
+ /**
+ * Resets {@link #clientParams} and populates {@link #api}.
+ *
+ * @throws PolicyApiException if an error occurs
+ */
+ @Before
+ public void setUp() throws PolicyApiException {
+ when(clientParams.getPort()).thenReturn(port);
+
+ api = new PolicyApiCaller(clientParams);
+ }
+
+ @Test
+ public void testPolicyApi() {
+ assertThatThrownBy(() -> new PolicyApiCaller(clientParams) {
+ @Override
+ protected HttpClient makeClient(BusTopicParams busParams) throws HttpClientConfigException {
+ throw new HttpClientConfigException("expected exception");
+ }
+ }).isInstanceOf(PolicyApiException.class);
+ }
+
+ @Test
+ public void testGetPolicyType() throws Exception {
+
+ assertNotNull(api.getPolicyType(new ToscaPolicyTypeIdentifier(MY_TYPE, MY_VERSION)));
+
+ assertThatThrownBy(() -> api.getPolicyType(new ToscaPolicyTypeIdentifier(INVALID_TYPE, MY_VERSION)))
+ .isInstanceOf(PolicyApiException.class);
+
+ assertThatThrownBy(() -> api.getPolicyType(new ToscaPolicyTypeIdentifier(UNKNOWN_TYPE, MY_VERSION)))
+ .isInstanceOf(NotFoundException.class);
+
+ assertThatThrownBy(() -> api.getPolicyType(new ToscaPolicyTypeIdentifier(NOT_A_TYPE, MY_VERSION)))
+ .isInstanceOf(PolicyApiException.class);
+
+ // connect to a port that has no server
+ when(clientParams.getPort()).thenReturn(NetworkUtil.allocPort());
+ api = new PolicyApiCaller(clientParams);
+
+ assertThatThrownBy(() -> api.getPolicyType(new ToscaPolicyTypeIdentifier(MY_TYPE, MY_VERSION)))
+ .isInstanceOf(PolicyApiException.class);
+ }
+
+ /**
+ * Simple REST server to handle test requests.
+ */
+
+ @Path("/policy/api/v1")
+ @Produces({"application/json", "application/yaml"})
+ @Consumes({"application/json", "application/yaml"})
+ public static class ApiRestController {
+
+ /**
+ * Retrieves the specified version of a particular policy type.
+ *
+ * @param policyTypeId ID of desired policy type
+ * @param versionId version of desired policy type
+ * @param requestId optional request ID
+ *
+ * @return the Response object containing the results of the API operation
+ */
+ @GET
+ @Path("/policytypes/{policyTypeId}/versions/{versionId}")
+ public Response getSpecificVersionOfPolicyType(@PathParam("policyTypeId") String policyTypeId,
+ @PathParam("versionId") String versionId, @HeaderParam("X-ONAP-RequestID") UUID requestId) {
+
+ assertEquals(MY_VERSION, versionId);
+
+ switch (policyTypeId) {
+ case UNKNOWN_TYPE:
+ logger.info("request for unknown policy type");
+ return Response.status(Response.Status.NOT_FOUND).build();
+ case INVALID_TYPE:
+ logger.info("invalid request for policy type");
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ case NOT_A_TYPE:
+ logger.info("invalid request for policy type");
+ return Response.status(Response.Status.OK).entity("string-type").build();
+ default:
+ logger.info("request for policy type={} version={}", policyTypeId, versionId);
+ return Response.status(Response.Status.OK).entity(new ToscaPolicyType()).build();
+ }
+ }
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java b/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java
index 167a2c45..5731a7b2 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlPdpParameterGroup.java
@@ -21,6 +21,8 @@
package org.onap.policy.pdpx.main.parameters;
+import lombok.Getter;
+import lombok.Setter;
import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.parameters.GroupValidationResult;
@@ -32,12 +34,18 @@ import org.onap.policy.common.utils.validation.ParameterValidationUtils;
* Class to hold all parameters needed for xacml pdp component.
*
*/
+@Getter
public class XacmlPdpParameterGroup implements ParameterGroup {
private static final String PARAM_REST_SERVER = "restServerParameters";
+ private static final String PARAM_POLICY_API = "policyApiParameters";
private static final String PARAM_TOPIC_PARAMETER_GROUP = "topicParameterGroup";
private static final String PARAM_APPLICATION_PATH = "applicationPath";
+
+ @Setter
private String name;
+
private RestServerParameters restServerParameters;
+ private RestServerParameters policyApiParameters;
private TopicParameterGroup topicParameterGroup;
private String applicationPath;
@@ -47,61 +55,16 @@ public class XacmlPdpParameterGroup implements ParameterGroup {
* @param name the parameter group name
*/
public XacmlPdpParameterGroup(final String name, final RestServerParameters restServerParameters,
- final TopicParameterGroup topicParameterGroup, final String applicationPath) {
+ final RestServerParameters policyApiParameters, final TopicParameterGroup topicParameterGroup,
+ final String applicationPath) {
this.name = name;
this.restServerParameters = restServerParameters;
+ this.policyApiParameters = policyApiParameters;
this.topicParameterGroup = topicParameterGroup;
this.applicationPath = applicationPath;
}
/**
- * Return the name of this parameter group instance.
- *
- * @return name the parameter group name
- */
- @Override
- public String getName() {
- return name;
- }
-
- /**
- * Set the name of this parameter group instance.
- *
- * @param name the parameter group name
- */
- @Override
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * Return the restServerParameters of this parameter group instance.
- *
- * @return the restServerParameters
- */
- public RestServerParameters getRestServerParameters() {
- return restServerParameters;
- }
-
- /**
- * Return the topicParameterGroup of this parameter group instance.
- *
- * @return the topicParameterGroup
- */
- public TopicParameterGroup getTopicParameterGroup() {
- return topicParameterGroup;
- }
-
- /**
- * Returns the path where applications will store their data.
- *
- * @return String to the path
- */
- public String getApplicationPath() {
- return applicationPath;
- }
-
- /**
* Validate the parameter group.
*
* @return the result of the validation
@@ -118,6 +81,14 @@ public class XacmlPdpParameterGroup implements ParameterGroup {
} else {
validationResult.setResult(PARAM_REST_SERVER, restServerParameters.validate());
}
+ if (policyApiParameters == null) {
+ validationResult.setResult(PARAM_POLICY_API, ValidationStatus.INVALID,
+ "must have policyApiParameters to configure xacml pdp rest server");
+ } else {
+ // set the name - this only really matters for validation messages
+ policyApiParameters.setName(PARAM_POLICY_API);
+ validationResult.setResult(PARAM_POLICY_API, policyApiParameters.validate());
+ }
if (topicParameterGroup == null) {
validationResult.setResult(PARAM_TOPIC_PARAMETER_GROUP, ValidationStatus.INVALID,
"must have topicParameterGroup to configure xacml pdp topic sink and source");
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
index fd79035e..76d07045 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
@@ -22,6 +22,7 @@
package org.onap.policy.pdpx.main.parameters;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -37,14 +38,30 @@ import org.onap.policy.common.utils.coder.StandardCoder;
*/
public class CommonTestData {
- private static final String REST_SERVER_PASSWORD = "zb!XztG34";
+ private static final String PASS_KEY = "password";
+ private static final String USER_KEY = "userName";
+ private static final String PORT_KEY = "port";
+ private static final String HOST_KEY = "host";
+ private static final String AAF_KEY = "aaf";
+ private static final String HTTPS_KEY = "https";
+
+ private static final String REST_SERVER_PASS = "zb!XztG34";
private static final String REST_SERVER_USER = "healthcheck";
private static final int REST_SERVER_PORT = 6969;
private static final String REST_SERVER_HOST = "0.0.0.0";
private static final boolean REST_SERVER_HTTPS = false;
private static final boolean REST_SERVER_AAF = false;
+
+ private static final String POLICY_API_PASS = "zb!XztG34";
+ private static final String POLICY_API_USER = "healthcheck";
+ private static final int POLICY_API_PORT = 6970;
+ private static final String POLICY_API_HOST = "0.0.0.0";
+ private static final boolean POLICY_API_HTTPS = false;
+ private static final boolean POLICY_API_AAF = false;
+
public static final String PDPX_GROUP_NAME = "XacmlPdpGroup";
- public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
+ public static final List<TopicParameters> TOPIC_PARAMS =
+ Collections.unmodifiableList(Arrays.asList(getTopicParams()));
public static final Coder coder = new StandardCoder();
@@ -69,14 +86,14 @@ public class CommonTestData {
*/
public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
final Map<String, Object> map = new TreeMap<>();
- map.put("https", REST_SERVER_HTTPS);
- map.put("aaf", REST_SERVER_AAF);
+ map.put(HTTPS_KEY, REST_SERVER_HTTPS);
+ map.put(AAF_KEY, REST_SERVER_AAF);
if (!isEmpty) {
- map.put("host", REST_SERVER_HOST);
- map.put("port", REST_SERVER_PORT);
- map.put("userName", REST_SERVER_USER);
- map.put("password", REST_SERVER_PASSWORD);
+ map.put(HOST_KEY, REST_SERVER_HOST);
+ map.put(PORT_KEY, REST_SERVER_PORT);
+ map.put(USER_KEY, REST_SERVER_USER);
+ map.put(PASS_KEY, REST_SERVER_PASS);
}
return map;
@@ -90,12 +107,12 @@ public class CommonTestData {
*/
public Map<String, Object> getRestServerParametersMap(final int port) {
final Map<String, Object> map = new TreeMap<>();
- map.put("https", REST_SERVER_HTTPS);
- map.put("aaf", REST_SERVER_AAF);
- map.put("host", REST_SERVER_HOST);
- map.put("port", port);
- map.put("userName", REST_SERVER_USER);
- map.put("password", REST_SERVER_PASSWORD);
+ map.put(HTTPS_KEY, REST_SERVER_HTTPS);
+ map.put(AAF_KEY, REST_SERVER_AAF);
+ map.put(HOST_KEY, REST_SERVER_HOST);
+ map.put(PORT_KEY, port);
+ map.put(USER_KEY, REST_SERVER_USER);
+ map.put(PASS_KEY, REST_SERVER_PASS);
return map;
}
@@ -117,6 +134,27 @@ public class CommonTestData {
}
/**
+ * Returns a property map for a RestServerParameters map for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return a property map suitable for constructing an object
+ */
+ public Map<String, Object> getPolicyApiParametersMap(final boolean isEmpty) {
+ final Map<String, Object> map = new TreeMap<>();
+ map.put(HTTPS_KEY, POLICY_API_HTTPS);
+ map.put(AAF_KEY, POLICY_API_AAF);
+
+ if (!isEmpty) {
+ map.put(HOST_KEY, POLICY_API_HOST);
+ map.put(PORT_KEY, POLICY_API_PORT);
+ map.put(USER_KEY, POLICY_API_USER);
+ map.put(PASS_KEY, POLICY_API_PASS);
+ }
+
+ return map;
+ }
+
+ /**
* Returns a property map for a TopicParameters map for test cases.
*
* @param isEmpty boolean value to represent that object created should be empty or not
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
index 1484edfd..c66af0ce 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
@@ -57,11 +57,13 @@ public class TestXacmlPdpParameterGroup {
public void testXacmlPdpParameterGroup() throws IOException {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters =
- new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME,
- restServerParameters, topicParameterGroup, applicationPath.getAbsolutePath());
+ new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
+ policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(restServerParameters.getHost(), pdpxParameters.getRestServerParameters().getHost());
@@ -77,10 +79,12 @@ public class TestXacmlPdpParameterGroup {
public void testXacmlPdpParameterGroup_NullName() {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(null, restServerParameters,
- topicParameterGroup, applicationPath.getAbsolutePath());
+ policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
assertEquals(null, pdpxParameters.getName());
@@ -92,10 +96,12 @@ public class TestXacmlPdpParameterGroup {
public void testXacmlPdpParameterGroup_EmptyName() {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup("", restServerParameters,
- topicParameterGroup, applicationPath.getAbsolutePath());
+ policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
assertEquals("", pdpxParameters.getName());
@@ -107,31 +113,50 @@ public class TestXacmlPdpParameterGroup {
public void testXacmlPdpParameterGroup_EmptyRestServerParameters() {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(true), RestServerParameters.class);
+ final RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
- topicParameterGroup, applicationPath.getAbsolutePath());
+ policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, "
- + "parameter group has status INVALID"));
+ .contains("parameter group \"RestServerParameters\""));
+ }
+
+ @Test
+ public void testXacmlPdpParameterGroup_EmptyPolicyApiParameters() {
+ final RestServerParameters restServerParameters =
+ testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(true), RestServerParameters.class);
+ final TopicParameterGroup topicParameterGroup =
+ testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
+ final XacmlPdpParameterGroup pdpxParameters =
+ new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
+ policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath());
+ final GroupValidationResult validationResult = pdpxParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("parameter group \"policyApiParameters\""));
}
@Test
public void testXacmlPdpParameterGroup_EmptyTopicParameterGroup() {
final RestServerParameters restServerParameters =
testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
final TopicParameterGroup topicParameterGroup =
testData.toObject(testData.getTopicParametersMap(true), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
- topicParameterGroup, applicationPath.getAbsolutePath());
+ policyApiParameters, topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, "
- + "parameter group has status INVALID"));
+ .contains("parameter group \"TopicParameterGroup\""));
}
}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
index 0edfc6f5..5f75e6dd 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
@@ -101,10 +101,12 @@ public class TestDecision {
//
RestServerParameters rest =
testData.toObject(testData.getRestServerParametersMap(port), RestServerParameters.class);
+ RestServerParameters policyApiParameters =
+ testData.toObject(testData.getPolicyApiParametersMap(false), RestServerParameters.class);
TopicParameterGroup topicParameterGroup =
- testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
- XacmlPdpParameterGroup params =
- new XacmlPdpParameterGroup("XacmlPdpGroup", rest, topicParameterGroup, apps.getAbsolutePath());
+ testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
+ XacmlPdpParameterGroup params = new XacmlPdpParameterGroup("XacmlPdpGroup", rest, policyApiParameters,
+ topicParameterGroup, apps.getAbsolutePath());
final Gson gson = new GsonBuilder().create();
File fileParams = appsFolder.newFile("params.json");
String jsonParams = gson.toJson(params);
diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json
index 6ae2aa94..42e54581 100644
--- a/main/src/test/resources/parameters/MinimumParameters.json
+++ b/main/src/test/resources/parameters/MinimumParameters.json
@@ -6,8 +6,14 @@
"userName": "healthcheck",
"password": "zb!XztG34"
},
+ "policyApiParameters": {
+ "host": "0.0.0.0",
+ "port": 6970,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+ },
"applicationPath": "apps.test",
- "topicParameterGroup": {
+ "topicParameterGroup": {
"topicSources" : [{
"topic" : "POLICY-PDP-PAP",
"servers" : [ "anyserver" ],
diff --git a/main/src/test/resources/parameters/NoParameters.json b/main/src/test/resources/parameters/NoParameters.json
index 953f70e7..1b25951c 100644
--- a/main/src/test/resources/parameters/NoParameters.json
+++ b/main/src/test/resources/parameters/NoParameters.json
@@ -5,6 +5,12 @@
"userName": "healthcheck",
"password": "zb!XztG34"
},
+ "policyApiParameters": {
+ "host": "0.0.0.0",
+ "port": 6970,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+ },
"topicParameterGroup": {
"topicSources" : [{
"topic" : "POLICY-PDP-PAP",
diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters.json
index e5ab198b..186a7b26 100644
--- a/main/src/test/resources/parameters/XacmlPdpConfigParameters.json
+++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters.json
@@ -6,6 +6,12 @@
"userName": "healthcheck",
"password": "zb!XztG34"
},
+ "policyApiParameters": {
+ "host": "0.0.0.0",
+ "port": 6970,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+ },
"applicationPath": "src/test/resources/apps",
"topicParameterGroup": {
"topicSources" : [{
diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json
index 8949a3c4..27e7ef46 100644
--- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json
+++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidName.json
@@ -1,9 +1,29 @@
{
"name": " ",
- "restServerParameters": {
- "host": "0.0.0.0",
+ "restServerParameters":{
+ "host":"0.0.0.0",
"port": 6969,
+ "userName":"healthcheck",
+ "password":"zb!XztG34",
+ "https":true
+ },
+ "policyApiParameters": {
+ "host": "0.0.0.0",
+ "port": 6970,
"userName": "healthcheck",
"password": "zb!XztG34"
+ },
+ "applicationPath": "src/test/resources/apps",
+ "topicParameterGroup": {
+ "topicSources" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "anyserver" ],
+ "topicCommInfrastructure" : "noop"
+ }],
+ "topicSinks" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "anyserver" ],
+ "topicCommInfrastructure" : "noop"
+ }]
}
-}
+} \ No newline at end of file
diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json
index 8b8e5c67..d320b11d 100644
--- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json
+++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json
@@ -5,5 +5,24 @@
"port": -1,
"userName": "",
"password": ""
+ },
+ "policyApiParameters": {
+ "host": "0.0.0.0",
+ "port": 6970,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+ },
+ "applicationPath": "src/test/resources/apps",
+ "topicParameterGroup": {
+ "topicSources" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "anyserver" ],
+ "topicCommInfrastructure" : "noop"
+ }],
+ "topicSinks" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "anyserver" ],
+ "topicCommInfrastructure" : "noop"
+ }]
}
}
diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json
index 2d1f7cde..1c17414b 100644
--- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json
+++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json
@@ -7,6 +7,12 @@
"password":"zb!XztG34",
"https":true
},
+ "policyApiParameters": {
+ "host": "0.0.0.0",
+ "port": 6970,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+ },
"applicationPath": "src/test/resources/apps",
"topicParameterGroup": {
"topicSources" : [{
diff --git a/packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json b/packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json
index cc56bd17..c7b7fe24 100644
--- a/packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json
+++ b/packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json
@@ -8,6 +8,14 @@
"https": true,
"aaf": false
},
+ "policyApiParameters": {
+ "host": "pap",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "https": true,
+ "aaf": false
+ },
"applicationPath": "/opt/app/policy/pdpx/apps",
"topicParameterGroup": {
"topicSources" : [{