From aba606406dded6ea6d9bf140ea2cbbf11fe90238 Mon Sep 17 00:00:00 2001 From: "a.sreekumar" Date: Thu, 4 Jul 2019 14:14:39 +0000 Subject: Remove topic.properties and incorporate into overall config file for xacml Change-Id: I3be6248db65041f5d9b7acfcf0fcd2f49d9d70f8 Issue-ID: POLICY-1744 Signed-off-by: a.sreekumar --- .../pdpx/main/parameters/RestServerBuilder.java | 84 ----------- .../pdpx/main/parameters/RestServerParameters.java | 156 --------------------- .../main/parameters/XacmlPdpParameterGroup.java | 23 ++- .../policy/pdpx/main/rest/XacmlPdpRestServer.java | 3 +- .../org/onap/policy/pdpx/main/startstop/Main.java | 13 +- .../java/org/onap/policy/pdpx/main/CommonRest.java | 3 +- .../pdpx/main/parameters/CommonTestData.java | 100 +++++++++++-- .../parameters/TestXacmlPdpParameterGroup.java | 52 +++++-- .../onap/policy/pdpx/main/rest/TestDecision.java | 22 +-- .../onap/policy/pdpx/main/startstop/TestMain.java | 3 +- .../pdpx/main/startstop/TestXacmlPdpActivator.java | 12 +- .../resources/parameters/MinimumParameters.json | 14 +- .../test/resources/parameters/NoParameters.json | 12 ++ .../parameters/XacmlPdpConfigParameters.json | 14 +- .../parameters/XacmlPdpConfigParameters_Std.json | 14 +- .../src/test/resources/parameters/topic.properties | 22 --- 16 files changed, 226 insertions(+), 321 deletions(-) delete mode 100644 main/src/main/java/org/onap/policy/pdpx/main/parameters/RestServerBuilder.java delete mode 100644 main/src/main/java/org/onap/policy/pdpx/main/parameters/RestServerParameters.java delete mode 100644 main/src/test/resources/parameters/topic.properties (limited to 'main/src') diff --git a/main/src/main/java/org/onap/policy/pdpx/main/parameters/RestServerBuilder.java b/main/src/main/java/org/onap/policy/pdpx/main/parameters/RestServerBuilder.java deleted file mode 100644 index 6c729f21..00000000 --- a/main/src/main/java/org/onap/policy/pdpx/main/parameters/RestServerBuilder.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============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.pdpx.main.parameters; - -public class RestServerBuilder { - private String host; - private int port; - private String userName; - private String password; - private boolean https; - private boolean aaf; - - public String getHost() { - return host; - } - - public int getPort() { - return port; - } - - public String getUserName() { - return userName; - } - - public String getPassword() { - return password; - } - - public boolean isHttps() { - return https; - } - - public boolean isAaf() { - return aaf; - } - - public RestServerBuilder setHost(String host) { - this.host = host; - return this; - } - - public RestServerBuilder setPort(int port) { - this.port = port; - return this; - } - - public RestServerBuilder setUserName(String userName) { - this.userName = userName; - return this; - } - - public RestServerBuilder setPassword(String password) { - this.password = password; - return this; - } - - public RestServerBuilder setHttps(boolean https) { - this.https = https; - return this; - } - - public RestServerBuilder setAaf(boolean aaf) { - this.aaf = aaf; - return this; - } -} diff --git a/main/src/main/java/org/onap/policy/pdpx/main/parameters/RestServerParameters.java b/main/src/main/java/org/onap/policy/pdpx/main/parameters/RestServerParameters.java deleted file mode 100644 index c452c758..00000000 --- a/main/src/main/java/org/onap/policy/pdpx/main/parameters/RestServerParameters.java +++ /dev/null @@ -1,156 +0,0 @@ -/*- - * ============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.pdpx.main.parameters; - -import org.onap.policy.common.parameters.GroupValidationResult; -import org.onap.policy.common.parameters.ParameterGroup; -import org.onap.policy.common.parameters.ValidationStatus; -import org.onap.policy.common.utils.validation.ParameterValidationUtils; - -/** - * Class to hold all parameters needed for xacml pdp rest server. - * - */ -public class RestServerParameters implements ParameterGroup { - private String name; - private String host; - private int port; - private String userName; - private String password; - private boolean https; - private boolean aaf; - - /** - * Constructor for instantiating RestServerParameters. - * - * @param builder the RestServer builder - */ - public RestServerParameters(final RestServerBuilder builder) { - super(); - this.host = builder.getHost(); - this.port = builder.getPort(); - this.userName = builder.getUserName(); - this.password = builder.getPassword(); - this.https = builder.isHttps(); - this.aaf = builder.isAaf(); - } - - /** - * Return the name of this RestServerParameters instance. - * - * @return name the name of this RestServerParameters - */ - @Override - public String getName() { - return name; - } - - /** - * Return the host of this RestServerParameters instance. - * - * @return the host - */ - public String getHost() { - return host; - } - - /** - * Return the port of this RestServerParameters instance. - * - * @return the port - */ - public int getPort() { - return port; - } - - /** - * Return the user name of this RestServerParameters instance. - * - * @return the userName - */ - public String getUserName() { - return userName; - } - - /** - * Return the password of this RestServerParameters instance. - * - * @return the password - */ - public String getPassword() { - return password; - } - - /** - * Return the https flag of this RestServerParameters instance. - * - * @return the https flag - */ - public boolean isHttps() { - return https; - } - - /** - * Return the aaf flag of this RestServerParameters instance. - * - * @return the aaf flag - */ - public boolean isAaf() { - return aaf; - } - - /** - * Set the name of this RestServerParameters instance. - * - * @param name the name to set - */ - @Override - public void setName(final String name) { - this.name = name; - } - - /** - * Validate the rest server parameters. - * - * @return the result of the validation - */ - @Override - public GroupValidationResult validate() { - final GroupValidationResult validationResult = new GroupValidationResult(this); - if (!ParameterValidationUtils.validateStringParameter(host)) { - validationResult.setResult("host", ValidationStatus.INVALID, - "must be a non-blank string containing hostname/ipaddress of the xacml pdp rest server"); - } - if (!ParameterValidationUtils.validateStringParameter(userName)) { - validationResult.setResult("userName", ValidationStatus.INVALID, - "must be a non-blank string containing userName for xacml pdp rest server credentials"); - } - if (!ParameterValidationUtils.validateStringParameter(password)) { - validationResult.setResult("password", ValidationStatus.INVALID, - "must be a non-blank string containing password for xacml pdp rest server credentials"); - } - if (!ParameterValidationUtils.validateIntParameter(port)) { - validationResult.setResult("port", ValidationStatus.INVALID, - "must be a positive integer containing port of the xacml pdp rest server"); - } - return validationResult; - } -} 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 e442a087..167a2c45 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 @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +21,8 @@ package org.onap.policy.pdpx.main.parameters; +import org.onap.policy.common.endpoints.parameters.RestServerParameters; +import org.onap.policy.common.endpoints.parameters.TopicParameterGroup; import org.onap.policy.common.parameters.GroupValidationResult; import org.onap.policy.common.parameters.ParameterGroup; import org.onap.policy.common.parameters.ValidationStatus; @@ -31,9 +34,11 @@ import org.onap.policy.common.utils.validation.ParameterValidationUtils; */ public class XacmlPdpParameterGroup implements ParameterGroup { private static final String PARAM_REST_SERVER = "restServerParameters"; + private static final String PARAM_TOPIC_PARAMETER_GROUP = "topicParameterGroup"; private static final String PARAM_APPLICATION_PATH = "applicationPath"; private String name; private RestServerParameters restServerParameters; + private TopicParameterGroup topicParameterGroup; private String applicationPath; /** @@ -42,9 +47,10 @@ public class XacmlPdpParameterGroup implements ParameterGroup { * @param name the parameter group name */ public XacmlPdpParameterGroup(final String name, final RestServerParameters restServerParameters, - final String applicationPath) { + final TopicParameterGroup topicParameterGroup, final String applicationPath) { this.name = name; this.restServerParameters = restServerParameters; + this.topicParameterGroup = topicParameterGroup; this.applicationPath = applicationPath; } @@ -77,6 +83,15 @@ public class XacmlPdpParameterGroup implements ParameterGroup { 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. * @@ -103,6 +118,12 @@ public class XacmlPdpParameterGroup implements ParameterGroup { } else { validationResult.setResult(PARAM_REST_SERVER, restServerParameters.validate()); } + if (topicParameterGroup == null) { + validationResult.setResult(PARAM_TOPIC_PARAMETER_GROUP, ValidationStatus.INVALID, + "must have topicParameterGroup to configure xacml pdp topic sink and source"); + } else { + validationResult.setResult(PARAM_TOPIC_PARAMETER_GROUP, topicParameterGroup.validate()); + } // // Validate the application path directory // diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java index 4b89cb16..a8441524 100644 --- a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java +++ b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +26,8 @@ import java.util.List; import java.util.Properties; import org.onap.policy.common.capabilities.Startable; import org.onap.policy.common.endpoints.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.parameters.RestServerParameters; import org.onap.policy.common.gson.GsonMessageBodyHandler; -import org.onap.policy.pdpx.main.parameters.RestServerParameters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/main/src/main/java/org/onap/policy/pdpx/main/startstop/Main.java b/main/src/main/java/org/onap/policy/pdpx/main/startstop/Main.java index 020bfcbf..62b811d8 100644 --- a/main/src/main/java/org/onap/policy/pdpx/main/startstop/Main.java +++ b/main/src/main/java/org/onap/policy/pdpx/main/startstop/Main.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +21,10 @@ package org.onap.policy.pdpx.main.startstop; -import java.io.FileInputStream; import java.util.Arrays; import java.util.Properties; import lombok.Getter; +import org.onap.policy.common.endpoints.utils.ParameterUtils; import org.onap.policy.pdpx.main.PolicyXacmlPdpException; import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup; import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterHandler; @@ -71,15 +72,7 @@ public class Main { XacmlPdpParameterGroup parameterGroup = new XacmlPdpParameterHandler().getParameters(arguments); // Read the properties - Properties props = new Properties(); - try { - String propFile = arguments.getFullPropertyFilePath(); - try (FileInputStream stream = new FileInputStream(propFile)) { - props.load(stream); - } - } catch (final Exception e) { - throw new PolicyXacmlPdpException("cannot load property file", e); - } + Properties props = ParameterUtils.getTopicProperties(parameterGroup.getTopicParameterGroup()); // Now, create the activator for the policy xacml pdp service activator = new XacmlPdpActivator(parameterGroup, props); diff --git a/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java b/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java index 0c84419f..a32bc6fd 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -116,7 +117,7 @@ public class CommonRest { writeJsonConfig(); - final String[] xacmlPdpConfigParameters = {"-c", CommonRest.CONFIG_FILE, "-p", "parameters/topic.properties"}; + final String[] xacmlPdpConfigParameters = {"-c", CommonRest.CONFIG_FILE}; main = new Main(xacmlPdpConfigParameters); if (!NetworkUtil.isTcpPortOpen("localhost", port, 20, 1000L)) { 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 1bf2294c..24bf48f3 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 @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +21,16 @@ package org.onap.policy.pdpx.main.parameters; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import org.onap.policy.common.endpoints.parameters.TopicParameters; +import org.onap.policy.common.parameters.ParameterGroup; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; + /** * Class to hold/create all parameters for test cases. * @@ -33,25 +44,90 @@ public class CommonTestData { private static final boolean REST_SERVER_HTTPS = false; private static final boolean REST_SERVER_AAF = false; public static final String PDPX_GROUP_NAME = "XacmlPdpGroup"; + public static final List TOPIC_PARAMS = Arrays.asList(getTopicParams()); + + public static final Coder coder = new StandardCoder(); + + /** + * Returns topic parameters for test cases. + * + * @return topic parameters + */ + public static TopicParameters getTopicParams() { + final TopicParameters topicParams = new TopicParameters(); + topicParams.setTopic("POLICY-PDP-PAP"); + topicParams.setTopicCommInfrastructure("dmaap"); + topicParams.setServers(Arrays.asList("message-router")); + return topicParams; + } /** - * Returns an instance of RestServerParameters for test cases. + * 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 the restServerParameters object + * @return a property map suitable for constructing an object */ - public RestServerParameters getRestServerParameters(final boolean isEmpty) { - final RestServerBuilder builder; + public Map getRestServerParametersMap(final boolean isEmpty) { + final Map map = new TreeMap<>(); + map.put("https", REST_SERVER_HTTPS); + map.put("aaf", REST_SERVER_AAF); + if (!isEmpty) { - builder = new RestServerBuilder().setHost(REST_SERVER_HOST).setPort(REST_SERVER_PORT) - .setUserName(REST_SERVER_USER).setPassword(REST_SERVER_PASSWORD).setHttps(REST_SERVER_HTTPS) - .setAaf(REST_SERVER_AAF); - } else { - builder = new RestServerBuilder().setHost(null).setPort(0).setUserName(null).setPassword(null) - .setHttps(REST_SERVER_HTTPS).setAaf(REST_SERVER_AAF); + map.put("host", REST_SERVER_HOST); + map.put("port", REST_SERVER_PORT); + map.put("userName", REST_SERVER_USER); + map.put("password", REST_SERVER_PASSWORD); } - final RestServerParameters restServerParameters = new RestServerParameters(builder); - return restServerParameters; + + return map; + } + + /** + * Returns a property map for a RestServerParameters map for test cases. + * + * @param port the port for RestServer + * @return a property map suitable for constructing an object + */ + public Map getRestServerParametersMap(final int port) { + final Map 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); + + return map; } + /** + * Converts the contents of a map to a parameter class. + * + * @param source property map + * @param clazz class of object to be created from the map + * @return a new object represented by the map + */ + public T toObject(final Map source, final Class clazz) { + try { + return coder.decode(coder.encode(source), clazz); + + } catch (final CoderException e) { + throw new RuntimeException("cannot create " + clazz.getName() + " from map", e); + } + } + + /** + * 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 + * @return a property map suitable for constructing an object + */ + public Map getTopicParametersMap(final boolean isEmpty) { + final Map map = new TreeMap<>(); + if (!isEmpty) { + map.put("topicSources", TOPIC_PARAMS); + map.put("topicSinks", TOPIC_PARAMS); + } + return map; + } } 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 2bf6fd81..1484edfd 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 @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,11 +28,12 @@ import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; - import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.onap.policy.common.endpoints.parameters.RestServerParameters; +import org.onap.policy.common.endpoints.parameters.TopicParameterGroup; import org.onap.policy.common.parameters.GroupValidationResult; /** @@ -41,6 +43,7 @@ import org.onap.policy.common.parameters.GroupValidationResult; public class TestXacmlPdpParameterGroup { CommonTestData commonTestData = new CommonTestData(); private static File applicationPath; + private static CommonTestData testData = new CommonTestData(); @ClassRule public static final TemporaryFolder applicationFolder = new TemporaryFolder(); @@ -52,11 +55,13 @@ public class TestXacmlPdpParameterGroup { @Test public void testXacmlPdpParameterGroup() throws IOException { - final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false); + final RestServerParameters restServerParameters = + testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class); + final TopicParameterGroup topicParameterGroup = + testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, - restServerParameters, - applicationPath.getAbsolutePath()); + restServerParameters, topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertTrue(validationResult.isValid()); assertEquals(restServerParameters.getHost(), pdpxParameters.getRestServerParameters().getHost()); @@ -70,9 +75,12 @@ public class TestXacmlPdpParameterGroup { @Test public void testXacmlPdpParameterGroup_NullName() { - final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false); + final RestServerParameters restServerParameters = + testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class); + final TopicParameterGroup topicParameterGroup = + testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(null, restServerParameters, - applicationPath.getAbsolutePath()); + topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertEquals(null, pdpxParameters.getName()); @@ -82,10 +90,12 @@ public class TestXacmlPdpParameterGroup { @Test public void testXacmlPdpParameterGroup_EmptyName() { - final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false); - + final RestServerParameters restServerParameters = + testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class); + final TopicParameterGroup topicParameterGroup = + testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup("", restServerParameters, - applicationPath.getAbsolutePath()); + topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertEquals("", pdpxParameters.getName()); @@ -95,15 +105,33 @@ public class TestXacmlPdpParameterGroup { @Test public void testXacmlPdpParameterGroup_EmptyRestServerParameters() { - final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(true); + final RestServerParameters restServerParameters = + testData.toObject(testData.getRestServerParametersMap(true), 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()); + 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")); + } + @Test + public void testXacmlPdpParameterGroup_EmptyTopicParameterGroup() { + final RestServerParameters restServerParameters = + testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class); + final TopicParameterGroup topicParameterGroup = + testData.toObject(testData.getTopicParametersMap(true), TopicParameterGroup.class); final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters, - applicationPath.getAbsolutePath()); + topicParameterGroup, applicationPath.getAbsolutePath()); final GroupValidationResult validationResult = pdpxParameters.validate(); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() - .contains("\"org.onap.policy.pdpx.main.parameters.RestServerParameters\" INVALID, " + .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, " + "parameter group has status INVALID")); } } 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 5f7eb78c..b1732048 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 @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +26,6 @@ import static org.junit.Assert.assertEquals; import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -37,12 +37,10 @@ import java.security.NoSuchAlgorithmException; import java.util.Collections; import java.util.HashMap; import java.util.Map; - import javax.ws.rs.client.Entity; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; - import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.ClassRule; @@ -50,14 +48,15 @@ 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.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.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.RestServerBuilder; -import org.onap.policy.pdpx.main.parameters.RestServerParameters; +import org.onap.policy.pdpx.main.parameters.CommonTestData; import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup; import org.onap.policy.pdpx.main.startstop.Main; import org.slf4j.Logger; @@ -70,6 +69,7 @@ public class TestDecision { private static int port; private static Main main; private static HttpClient client; + private static CommonTestData testData = new CommonTestData(); @ClassRule public static final TemporaryFolder appsFolder = new TemporaryFolder(); @@ -97,9 +97,12 @@ public class TestDecision { // // Get the parameters file correct. // - RestServerParameters rest = new RestServerParameters(new RestServerBuilder() - .setHost("0.0.0.0").setPort(port).setUserName("healthcheck").setPassword("zb!XztG34")); - XacmlPdpParameterGroup params = new XacmlPdpParameterGroup("XacmlPdpGroup", rest, apps.getAbsolutePath()); + RestServerParameters rest = + testData.toObject(testData.getRestServerParametersMap(port), RestServerParameters.class); + TopicParameterGroup topicParameterGroup = + testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class); + XacmlPdpParameterGroup params = + new XacmlPdpParameterGroup("XacmlPdpGroup", rest, topicParameterGroup, apps.getAbsolutePath()); final Gson gson = new GsonBuilder().create(); File fileParams = appsFolder.newFile("params.json"); String jsonParams = gson.toJson(params); @@ -169,8 +172,7 @@ public class TestDecision { } private static Main startXacmlPdpService(File params) throws PolicyXacmlPdpException { - final String[] XacmlPdpConfigParameters = {"-c", params.getAbsolutePath(), "-p", - "parameters/topic.properties"}; + final String[] XacmlPdpConfigParameters = {"-c", params.getAbsolutePath()}; return new Main(XacmlPdpConfigParameters); } diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java index e8448ab2..8b6889d6 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,7 +68,7 @@ public class TestMain extends CommonRest { @Test public void testMain() throws PolicyXacmlPdpException { - final String[] xacmlPdpConfigParameters = {"-c", CONFIG_FILE, "-p", "parameters/topic.properties"}; + final String[] xacmlPdpConfigParameters = {"-c", CONFIG_FILE}; main = new Main(xacmlPdpConfigParameters); main.shutdown(); main = null; diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java index b60f4589..7e7dee22 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,12 +26,12 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import java.io.FileInputStream; import java.util.Properties; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.common.endpoints.utils.ParameterUtils; import org.onap.policy.pdpx.main.CommonRest; import org.onap.policy.pdpx.main.PolicyXacmlPdpException; import org.onap.policy.pdpx.main.parameters.CommonTestData; @@ -55,16 +56,11 @@ public class TestXacmlPdpActivator extends CommonRest { public static void setUpBeforeClass() throws Exception { CommonRest.setUpBeforeClass(); - final String[] xacmlPdpConfigParameters = - {"-c", CommonRest.CONFIG_FILE, "-p", "parameters/topic.properties"}; + final String[] xacmlPdpConfigParameters = {"-c", CommonRest.CONFIG_FILE}; final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments(xacmlPdpConfigParameters); parGroup = new XacmlPdpParameterHandler().getParameters(arguments); - props = new Properties(); - String propFile = arguments.getFullPropertyFilePath(); - try (FileInputStream stream = new FileInputStream(propFile)) { - props.load(stream); - } + props = ParameterUtils.getTopicProperties(parGroup.getTopicParameterGroup()); // don't want the common "main" running CommonRest.stopMain(); diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json index ab52cc85..6ae2aa94 100644 --- a/main/src/test/resources/parameters/MinimumParameters.json +++ b/main/src/test/resources/parameters/MinimumParameters.json @@ -6,5 +6,17 @@ "userName": "healthcheck", "password": "zb!XztG34" }, - "applicationPath": "apps.test" + "applicationPath": "apps.test", + "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/NoParameters.json b/main/src/test/resources/parameters/NoParameters.json index bbe1ee13..953f70e7 100644 --- a/main/src/test/resources/parameters/NoParameters.json +++ b/main/src/test/resources/parameters/NoParameters.json @@ -4,5 +4,17 @@ "port": 6969, "userName": "healthcheck", "password": "zb!XztG34" + }, + "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.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters.json index 58eba71d..e5ab198b 100644 --- a/main/src/test/resources/parameters/XacmlPdpConfigParameters.json +++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters.json @@ -6,5 +6,17 @@ "userName": "healthcheck", "password": "zb!XztG34" }, - "applicationPath": "src/test/resources/apps" + "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 5b6586a3..2d1f7cde 100644 --- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json +++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json @@ -7,5 +7,17 @@ "password":"zb!XztG34", "https":true }, - "applicationPath": "src/test/resources/apps" + "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/topic.properties b/main/src/test/resources/parameters/topic.properties deleted file mode 100644 index 11c17dac..00000000 --- a/main/src/test/resources/parameters/topic.properties +++ /dev/null @@ -1,22 +0,0 @@ -# ============LICENSE_START======================================================= -# ONAP PAP -# ================================================================================ -# 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. -# ============LICENSE_END========================================================= - -noop.sink.topics=POLICY-PDP-PAP -noop.sink.topics.POLICY-PDP-PAP.servers=anyserver -noop.source.topics=POLICY-PDP-PAP -noop.source.topics.POLICY-PDP-PAP.servers=anyserver -- cgit 1.2.3-korg