Modify policy/distribution to use RestServer from common 68/91768/3
authorJim Hahn <jrh3@att.com>
Fri, 19 Jul 2019 19:19:22 +0000 (15:19 -0400)
committerJim Hahn <jrh3@att.com>
Fri, 19 Jul 2019 19:35:18 +0000 (15:35 -0400)
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 <jrh3@att.com>
13 files changed:
main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java
main/src/main/java/org/onap/policy/distribution/main/parameters/RestServerParameters.java [deleted file]
main/src/main/java/org/onap/policy/distribution/main/rest/DistributionRestServer.java [deleted file]
main/src/main/java/org/onap/policy/distribution/main/rest/aaf/AafDistributionFilter.java [new file with mode: 0644]
main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java
main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java
main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java
main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java
main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt
main/src/test/resources/parameters/RestServerParameters.json [new file with mode: 0644]
main/src/test/resources/parameters/RestServerParametersEmpty.json [new file with mode: 0644]
plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java

index f967375..d568980 100644 (file)
@@ -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 (file)
index 4685b7d..0000000
+++ /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 (file)
index 895827f..0000000
+++ /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<HttpServletServer> 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 (file)
index 0000000..d32c29d
--- /dev/null
@@ -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;
+    }
+}
index 8db118a..a50fa6b 100644 (file)
@@ -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...");
index ccd3db6..19beadb 100644 (file)
@@ -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.
 
 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;
     }
 
     /**
index 8a33ac2..f612c81 100644 (file)
@@ -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"));
     }
 }
index 356a586..3644864 100644 (file)
@@ -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);
index 6c95a2a..0b47bcc 100644 (file)
@@ -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();
index ceb195a..f3152e4 100644 (file)
@@ -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 (file)
index 0000000..86aee27
--- /dev/null
@@ -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 (file)
index 0000000..e02aef2
--- /dev/null
@@ -0,0 +1,2 @@
+{\r
+}
\ No newline at end of file
index 9b49586..f9cd868 100644 (file)
@@ -21,6 +21,7 @@
 
 package org.onap.policy.distribution.forwarding.xacml.pdp.engine;
 
+import static org.junit.Assert.assertSame;
 import static org.mockito.Matchers.anyObject;
 import static org.mockito.Matchers.argThat;
 import static org.mockito.Matchers.eq;
@@ -175,6 +176,8 @@ public class XacmlPdpPolicyForwarderTest {
         final ToscaPolicy policy = createPolicy(policies, "policy", "optimization");
         forwarder.forward(policies);
 
+        assertSame(policy, policies.iterator().next());
+
         verify(httpClientMock, times(0)).put(eq("createPolicy"), anyObject(), anyObject());
         verify(httpClientMock, times(0)).put(eq("pushPolicy"), anyObject(), anyObject());
     }