From 538a204455ca708eaf20785972be3ac1c2a7ed3f Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 19 Jul 2019 15:19:22 -0400 Subject: Modify policy/distribution to use RestServer from common This also entailed removing the local copy of RestServerParameters. Also added an AafFilter, which was missing from the original code. Change-Id: Ibbdce8c395e0149ab540a3704b3554a9d96b9705 Issue-ID: POLICY-1652 Signed-off-by: Jim Hahn --- .../parameters/DistributionParameterGroup.java | 3 +- .../main/parameters/RestServerParameters.java | 150 --------------------- .../main/rest/DistributionRestServer.java | 148 -------------------- .../main/rest/aaf/AafDistributionFilter.java | 39 ++++++ .../main/startstop/DistributionActivator.java | 11 +- .../main/parameters/CommonTestData.java | 31 +++-- .../parameters/TestDistributionParameterGroup.java | 4 +- .../main/rest/TestDistributionRestServer.java | 8 +- .../main/rest/TestDistributionStatistics.java | 6 +- .../InvalidRestServerParameters.txt | 10 +- .../resources/parameters/RestServerParameters.json | 6 + .../parameters/RestServerParametersEmpty.json | 2 + 12 files changed, 91 insertions(+), 327 deletions(-) delete mode 100644 main/src/main/java/org/onap/policy/distribution/main/parameters/RestServerParameters.java delete mode 100644 main/src/main/java/org/onap/policy/distribution/main/rest/DistributionRestServer.java create mode 100644 main/src/main/java/org/onap/policy/distribution/main/rest/aaf/AafDistributionFilter.java create mode 100644 main/src/test/resources/parameters/RestServerParameters.json create mode 100644 main/src/test/resources/parameters/RestServerParametersEmpty.json (limited to 'main') diff --git a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java index f9673755..d568980a 100644 --- a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java +++ b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications 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. @@ -23,7 +24,7 @@ package org.onap.policy.distribution.main.parameters; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; - +import org.onap.policy.common.endpoints.parameters.RestServerParameters; import org.onap.policy.common.parameters.GroupValidationResult; import org.onap.policy.common.parameters.ParameterGroup; import org.onap.policy.common.parameters.ValidationStatus; diff --git a/main/src/main/java/org/onap/policy/distribution/main/parameters/RestServerParameters.java b/main/src/main/java/org/onap/policy/distribution/main/parameters/RestServerParameters.java deleted file mode 100644 index 4685b7d1..00000000 --- a/main/src/main/java/org/onap/policy/distribution/main/parameters/RestServerParameters.java +++ /dev/null @@ -1,150 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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.distribution.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 distribution rest server. - * - * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) - */ -public class RestServerParameters implements ParameterGroup { - private String name; - private String host; - private int port; - private String userName; - private String password; - private boolean https; - - /** - * Constructor for instantiating RestServerParameters. - * - * @param host the host name - * @param port the port - * @param userName the user name - * @param password the password - * @param https the https - */ - public RestServerParameters(final String host, final int port, final String userName, final String password, - final boolean https) { - super(); - this.host = host; - this.port = port; - this.userName = userName; - this.password = password; - this.https = https; - } - - /** - * 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 of this RestServerParameters instance. - * - * @return the password - */ - public boolean isHttps() { - return https; - } - - /** - * Set the name of this RestServerParameters instance. - * - * @param name the name to set - */ - 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 distribution rest server"); - } - if (!ParameterValidationUtils.validateStringParameter(userName)) { - validationResult.setResult("userName", ValidationStatus.INVALID, - "must be a non-blank string containing userName for distribution rest server credentials"); - } - if (!ParameterValidationUtils.validateStringParameter(password)) { - validationResult.setResult("password", ValidationStatus.INVALID, - "must be a non-blank string containing password for distribution rest server credentials"); - } - if (!ParameterValidationUtils.validateIntParameter(port)) { - validationResult.setResult("port", ValidationStatus.INVALID, - "must be a positive integer containing port of the distribution rest server"); - } - return validationResult; - } -} diff --git a/main/src/main/java/org/onap/policy/distribution/main/rest/DistributionRestServer.java b/main/src/main/java/org/onap/policy/distribution/main/rest/DistributionRestServer.java deleted file mode 100644 index 895827fc..00000000 --- a/main/src/main/java/org/onap/policy/distribution/main/rest/DistributionRestServer.java +++ /dev/null @@ -1,148 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. - * ================================================================================ - * 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.distribution.main.rest; - -import java.util.ArrayList; -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.http.server.HttpServletServerFactoryInstance; -import org.onap.policy.common.gson.JacksonHandler; -import org.onap.policy.distribution.main.parameters.RestServerParameters; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class to manage life cycle of distribution rest server. - * - * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) - */ -public class DistributionRestServer implements Startable { - - private static final Logger LOGGER = LoggerFactory.getLogger(DistributionRestServer.class); - private static final String SEPARATOR = "."; - private static final String HTTP_SERVER_SERVICES = "http.server.services"; - - private List servers = new ArrayList<>(); - - private RestServerParameters restServerParameters; - - /** - * Constructor for instantiating DistributionRestServer. - * - * @param restServerParameters the rest server parameters - */ - public DistributionRestServer(final RestServerParameters restServerParameters) { - this.restServerParameters = restServerParameters; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean start() { - try { - servers = HttpServletServerFactoryInstance.getServerFactory().build(getServerProperties()); - for (final HttpServletServer server : servers) { - server.start(); - } - } catch (final Exception exp) { - LOGGER.error("Failed to start distribution http server", exp); - return false; - } - return true; - } - - /** - * Creates the server properties object using restServerParameters. - * - * @return the properties object - */ - private Properties getServerProperties() { - final Properties props = new Properties(); - props.setProperty(HTTP_SERVER_SERVICES, restServerParameters.getName()); - props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".host", - restServerParameters.getHost()); - props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".port", - Integer.toString(restServerParameters.getPort())); - props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".restClasses", - DistributionRestController.class.getName()); - props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".managed", "false"); - props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".swagger", "true"); - props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".userName", - restServerParameters.getUserName()); - props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".password", - restServerParameters.getPassword()); - props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".https", - String.valueOf(restServerParameters.isHttps())); - props.setProperty(HTTP_SERVER_SERVICES + SEPARATOR + restServerParameters.getName() + ".serialization.provider", - JacksonHandler.class.getName()); - return props; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean stop() { - for (final HttpServletServer server : servers) { - try { - server.stop(); - } catch (final Exception exp) { - LOGGER.error("Failed to stop distribution http server", exp); - } - } - return true; - } - - /** - * {@inheritDoc}. - */ - @Override - public void shutdown() { - stop(); - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean isAlive() { - return !servers.isEmpty(); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("DistributionRestServer [servers="); - builder.append(servers); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/main/src/main/java/org/onap/policy/distribution/main/rest/aaf/AafDistributionFilter.java b/main/src/main/java/org/onap/policy/distribution/main/rest/aaf/AafDistributionFilter.java new file mode 100644 index 00000000..d32c29d1 --- /dev/null +++ b/main/src/main/java/org/onap/policy/distribution/main/rest/aaf/AafDistributionFilter.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy API + * ================================================================================ + * 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.distribution.main.rest.aaf; + +import org.onap.policy.common.endpoints.http.server.aaf.AafGranularAuthFilter; + +/** + * Distribution AAF authorization filter. + */ +public class AafDistributionFilter extends AafGranularAuthFilter { + + public static final String AAF_NODETYPE = "policy-distribution"; + public static final String AAF_ROOT_PERMISSION = DEFAULT_NAMESPACE + "." + AAF_NODETYPE; + + @Override + public String getPermissionTypeRoot() { + return AAF_ROOT_PERMISSION; + } +} diff --git a/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java b/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java index 8db118a8..a50fa6bc 100644 --- a/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java +++ b/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications 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. @@ -24,12 +25,13 @@ package org.onap.policy.distribution.main.startstop; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; - +import org.onap.policy.common.endpoints.http.server.RestServer; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.distribution.main.PolicyDistributionException; import org.onap.policy.distribution.main.parameters.DistributionParameterGroup; import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup; -import org.onap.policy.distribution.main.rest.DistributionRestServer; +import org.onap.policy.distribution.main.rest.DistributionRestController; +import org.onap.policy.distribution.main.rest.aaf.AafDistributionFilter; import org.onap.policy.distribution.reception.decoding.PluginInitializationException; import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler; import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup; @@ -54,7 +56,7 @@ public class DistributionActivator { private static boolean alive = false; - private DistributionRestServer restServer; + private RestServer restServer; /** * Instantiate the activator for policy distribution as a complete service. @@ -99,7 +101,8 @@ public class DistributionActivator { */ private void startDistributionRestServer() throws PolicyDistributionException { distributionParameterGroup.getRestServerParameters().setName(distributionParameterGroup.getName()); - restServer = new DistributionRestServer(distributionParameterGroup.getRestServerParameters()); + restServer = new RestServer(distributionParameterGroup.getRestServerParameters(), AafDistributionFilter.class, + DistributionRestController.class); if (!restServer.start()) { throw new PolicyDistributionException( "Failed to start distribution rest server. Check log for more details..."); diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java index ccd3db6c..19beadb6 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications 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. @@ -20,11 +21,18 @@ package org.onap.policy.distribution.main.parameters; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - +import org.onap.policy.common.endpoints.parameters.RestServerParameters; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters; import org.onap.policy.distribution.main.testclasses.DummyPolicyDecoderParameterGroup; import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup; @@ -44,11 +52,6 @@ import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParamet */ public class CommonTestData { - private static final String REST_SERVER_PASSWORD = "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; public static final String DISTRIBUTION_GROUP_NAME = "SDCDistributionGroup"; public static final String DECODER_TYPE = "DummyDecoder"; public static final String DECODER_CLASS_NAME = "org.onap.policy.distribution.main.testclasses.DummyDecoder"; @@ -73,6 +76,8 @@ public class CommonTestData { public static final String POLICY_NAME = "SamplePolicy"; public static final String DECODER_CONFIGURATION_PARAMETERS = "dummyDecoderConfiguration"; + private Coder coder = new StandardCoder(); + /** * Returns an instance of ReceptionHandlerParameters for test cases. * @@ -80,14 +85,14 @@ public class CommonTestData { * @return the restServerParameters object */ public RestServerParameters getRestServerParameters(final boolean isEmpty) { - final RestServerParameters restServerParameters; - if (!isEmpty) { - restServerParameters = new RestServerParameters(REST_SERVER_HOST, REST_SERVER_PORT, REST_SERVER_USER, - REST_SERVER_PASSWORD, REST_SERVER_HTTPS); - } else { - restServerParameters = new RestServerParameters(null, 0, null, null, REST_SERVER_HTTPS); + String fileName = "src/test/resources/parameters/" + + (isEmpty ? "RestServerParametersEmpty" : "RestServerParameters") + ".json"; + try { + String text = new String(Files.readAllBytes(new File(fileName).toPath()), StandardCharsets.UTF_8); + return coder.decode(text, RestServerParameters.class); + } catch (CoderException | IOException e) { + throw new RuntimeException("cannot read/decode " + fileName, e); } - return restServerParameters; } /** diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java index 8a33ac2c..f612c81e 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications 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. @@ -28,6 +29,7 @@ import static org.junit.Assert.fail; import java.util.Map; import org.junit.Test; +import org.onap.policy.common.endpoints.parameters.RestServerParameters; import org.onap.policy.common.parameters.GroupValidationResult; import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup; import org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup; @@ -226,7 +228,7 @@ public class TestDistributionParameterGroup { final GroupValidationResult validationResult = distributionParameters.validate(); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() - .contains("\"org.onap.policy.distribution.main.parameters.RestServerParameters\" INVALID, " + .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, " + "parameter group has status INVALID")); } } diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java index 356a5861..3644864e 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java +++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications 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. @@ -36,11 +37,12 @@ import javax.ws.rs.core.MediaType; import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.junit.Test; +import org.onap.policy.common.endpoints.http.server.RestServer; +import org.onap.policy.common.endpoints.parameters.RestServerParameters; import org.onap.policy.common.endpoints.report.HealthCheckReport; import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.distribution.main.PolicyDistributionException; import org.onap.policy.distribution.main.parameters.CommonTestData; -import org.onap.policy.distribution.main.parameters.RestServerParameters; import org.onap.policy.distribution.main.startstop.Main; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -77,13 +79,13 @@ public class TestDistributionRestServer { final String reportString = "Report [name=Policy SSD, url=self, healthy=false, code=500, message=not alive]"; final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false); restServerParams.setName(CommonTestData.DISTRIBUTION_GROUP_NAME); - final DistributionRestServer restServer = new DistributionRestServer(restServerParams); + final RestServer restServer = new RestServer(restServerParams, null, DistributionRestController.class); try { restServer.start(); final HealthCheckReport report = performHealthCheck(); validateReport(NAME, SELF, false, 500, NOT_ALIVE, reportString, report); assertTrue(restServer.isAlive()); - assertTrue(restServer.toString().startsWith("DistributionRestServer [servers=")); + assertTrue(restServer.toString().startsWith("RestServer [servers=")); restServer.shutdown(); } catch (final Exception exp) { LOGGER.error("testHealthCheckFailure failed", exp); diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java index 6c95a2a8..0b47bcc3 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java +++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications 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. @@ -35,10 +36,11 @@ import javax.ws.rs.core.MediaType; import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.junit.Test; +import org.onap.policy.common.endpoints.http.server.RestServer; +import org.onap.policy.common.endpoints.parameters.RestServerParameters; import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.distribution.main.PolicyDistributionException; import org.onap.policy.distribution.main.parameters.CommonTestData; -import org.onap.policy.distribution.main.parameters.RestServerParameters; import org.onap.policy.distribution.main.startstop.Main; import org.onap.policy.distribution.reception.statistics.DistributionStatisticsManager; import org.slf4j.Logger; @@ -75,7 +77,7 @@ public class TestDistributionStatistics { public void testDistributionStatistics_500() throws InterruptedException { final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false); restServerParams.setName(CommonTestData.DISTRIBUTION_GROUP_NAME); - final DistributionRestServer restServer = new DistributionRestServer(restServerParams); + final RestServer restServer = new RestServer(restServerParams, null, DistributionRestController.class); try { restServer.start(); final StatisticsReport report = getDistributionStatistics(); diff --git a/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt b/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt index ceb195ae..f3152e41 100644 --- a/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt +++ b/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt @@ -1,7 +1,7 @@ validation error(s) on parameters from "parameters/DistributionConfigParameters_InvalidRestServerParameters.json" parameter group "SDCDistributionGroup" type "org.onap.policy.distribution.main.parameters.DistributionParameterGroup" INVALID, parameter group has status INVALID - parameter group "null" type "org.onap.policy.distribution.main.parameters.RestServerParameters" INVALID, parameter group has status INVALID - field "host" type "java.lang.String" value "" INVALID, must be a non-blank string containing hostname/ipaddress of the distribution rest server - field "port" type "int" value "-1" INVALID, must be a positive integer containing port of the distribution rest server - field "userName" type "java.lang.String" value "" INVALID, must be a non-blank string containing userName for distribution rest server credentials - field "password" type "java.lang.String" value "" INVALID, must be a non-blank string containing password for distribution rest server credentials + parameter group "RestServerParameters" type "org.onap.policy.common.endpoints.parameters.RestServerParameters" INVALID, parameter group has status INVALID + field "host" type "java.lang.String" value "" INVALID, must be a non-blank string + field "port" type "int" value "-1" INVALID, must be >= 1 + field "userName" type "java.lang.String" value "" INVALID, must be a non-blank string + field "password" type "java.lang.String" value "" INVALID, must be a non-blank string \ No newline at end of file diff --git a/main/src/test/resources/parameters/RestServerParameters.json b/main/src/test/resources/parameters/RestServerParameters.json new file mode 100644 index 00000000..86aee276 --- /dev/null +++ b/main/src/test/resources/parameters/RestServerParameters.json @@ -0,0 +1,6 @@ +{ + "host": "0.0.0.0", + "port": 6969, + "userName": "healthcheck", + "password": "zb!XztG34" +} diff --git a/main/src/test/resources/parameters/RestServerParametersEmpty.json b/main/src/test/resources/parameters/RestServerParametersEmpty.json new file mode 100644 index 00000000..e02aef27 --- /dev/null +++ b/main/src/test/resources/parameters/RestServerParametersEmpty.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file -- cgit 1.2.3-korg