summaryrefslogtreecommitdiffstats
path: root/plugins/forwarding-plugins/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/forwarding-plugins/src/test/java')
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParametersTest.java (renamed from plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderParameterGroupTest.java)53
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java133
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycleApiSimulatorMain.java66
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycycleApiSimulatorEndpoint.java95
4 files changed, 321 insertions, 26 deletions
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderParameterGroupTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParametersTest.java
index fe27b74f..fd8422d6 100644
--- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderParameterGroupTest.java
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParametersTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.distribution.forwarding.lifecycle.api;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@@ -28,60 +29,60 @@ import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData;
/**
- * Class to perform unit test of {@link LifecycleApiPolicyForwarderParameterGroup}.
+ * Class to perform unit test of {@link LifecycleApiForwarderParameters}.
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
-public class LifecycleApiPolicyForwarderParameterGroupTest {
+public class LifecycleApiForwarderParametersTest {
- private static final String POLICY_API_HOST_NAME = "10.10.10.10";
- private static final int POLICY_API_PORT = 1234;
- private static final String POLICY_API_USER = "api_user";
- private static final String POLICY_API_PASSWORD = "api_password";
- private static final String POLICY_PAP_HOST_NAME = "20.20.20.20";
- private static final int POLICY_PAP_PORT = 4321;
- private static final String POLICY_PAP_USER = "pap_user";
- private static final String POLICY_PAP_PASSWORD = "pap_password";
+ private static final String POLICY_API_HOST_NAME = "0.0.0.0";
+ private static final int POLICY_API_PORT = 6969;
+ private static final String POLICY_API_USER = "healthcheck";
+ private static final String POLICY_API_PASSWORD = "zb!XztG34";
+ private static final String POLICY_PAP_HOST_NAME = "0.0.0.0";
+ private static final int POLICY_PAP_PORT = 6969;
+ private static final String POLICY_PAP_USER = "healthcheck";
+ private static final String POLICY_PAP_PASSWORD = "zb!XztG34";
@Test
public void testValidParameters() {
- final LifecycleApiPolicyForwarderParameterGroup configurationParameters =
+ final LifecycleApiForwarderParameters configurationParameters =
CommonTestData.getPolicyForwarderParameters(
"src/test/resources/parameters/LifecycleApiPolicyForwarderParameters.json",
- LifecycleApiPolicyForwarderParameterGroup.class);
+ LifecycleApiForwarderParameters.class);
- assertEquals(LifecycleApiPolicyForwarderParameterGroup.class.getSimpleName(),
+ assertEquals(LifecycleApiForwarderParameters.class.getSimpleName(),
configurationParameters.getName());
- assertTrue(configurationParameters.isHttps());
+ assertFalse(configurationParameters.isHttps());
assertTrue(configurationParameters.isDeployPolicies());
- assertEquals(POLICY_API_HOST_NAME, configurationParameters.getPolicyApiHostName());
- assertEquals(POLICY_API_PORT, configurationParameters.getPolicyApiPort());
- assertEquals(POLICY_API_USER, configurationParameters.getPolicyApiUserName());
- assertEquals(POLICY_API_PASSWORD, configurationParameters.getPolicyApiPassword());
- assertEquals(POLICY_PAP_HOST_NAME, configurationParameters.getPolicyPapHostName());
- assertEquals(POLICY_PAP_PORT, configurationParameters.getPolicyPapPort());
- assertEquals(POLICY_PAP_USER, configurationParameters.getPolicyPapUserName());
- assertEquals(POLICY_PAP_PASSWORD, configurationParameters.getPolicyPapPassword());
+ assertEquals(POLICY_API_HOST_NAME, configurationParameters.getApiParameters().getHostName());
+ assertEquals(POLICY_API_PORT, configurationParameters.getApiParameters().getPort());
+ assertEquals(POLICY_API_USER, configurationParameters.getApiParameters().getUserName());
+ assertEquals(POLICY_API_PASSWORD, configurationParameters.getApiParameters().getPassword());
+ assertEquals(POLICY_PAP_HOST_NAME, configurationParameters.getPapParameters().getHostName());
+ assertEquals(POLICY_PAP_PORT, configurationParameters.getPapParameters().getPort());
+ assertEquals(POLICY_PAP_USER, configurationParameters.getPapParameters().getUserName());
+ assertEquals(POLICY_PAP_PASSWORD, configurationParameters.getPapParameters().getPassword());
assertEquals(ValidationStatus.CLEAN, configurationParameters.validate().getStatus());
}
@Test
public void testInvalidParameters() {
- final LifecycleApiPolicyForwarderParameterGroup configurationParameters =
+ final LifecycleApiForwarderParameters configurationParameters =
CommonTestData.getPolicyForwarderParameters(
"src/test/resources/parameters/LifecycleApiPolicyForwarderParametersInvalid.json",
- LifecycleApiPolicyForwarderParameterGroup.class);
+ LifecycleApiForwarderParameters.class);
assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
}
@Test
public void testEmptyParameters() {
- final LifecycleApiPolicyForwarderParameterGroup configurationParameters =
+ final LifecycleApiForwarderParameters configurationParameters =
CommonTestData.getPolicyForwarderParameters("src/test/resources/parameters/EmptyParameters.json",
- LifecycleApiPolicyForwarderParameterGroup.class);
+ LifecycleApiForwarderParameters.class);
assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
}
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java
new file mode 100644
index 00000000..4d837cdf
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderTest.java
@@ -0,0 +1,133 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * 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.
+ * 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.forwarding.lifecycle.api;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.distribution.forwarding.PolicyForwardingException;
+import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData;
+import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.LifecycleApiSimulatorMain;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+
+/**
+ * Class to perform unit test of {@link LifecycleApiPolicyForwarder}.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class LifecycleApiPolicyForwarderTest {
+
+ private static final String POLICY = "src/test/resources/parameters/sample_policy.json";
+ private static final String POLICY_ERROR = "src/test/resources/parameters/sample_policy_failure.json";
+ private static final String POLICY_TYPE = "src/test/resources/parameters/sample_policy_type.json";
+ private StandardCoder standardCoder = new StandardCoder();
+ private static LifecycleApiSimulatorMain simulator = new LifecycleApiSimulatorMain();
+
+ /**
+ * Set up.
+ *
+ * @throws CoderException if any error occurs
+ * @throws PolicyForwardingException if any error occurs
+ * @throws InterruptedException if any error occurs
+ */
+ @BeforeClass
+ public static void setUp() throws PolicyForwardingException, CoderException, InterruptedException {
+ final ParameterGroup parameterGroup = CommonTestData.getPolicyForwarderParameters(
+ "src/test/resources/parameters/LifecycleApiPolicyForwarderParameters.json",
+ LifecycleApiForwarderParameters.class);
+ ParameterService.register(parameterGroup);
+ simulator.startLifecycycleApiSimulator();
+ if (!NetworkUtil.isTcpPortOpen("0.0.0.0", 6969, 6, 10000L)) {
+ throw new IllegalStateException("cannot connect to port 6969");
+ }
+ }
+
+ /**
+ * Tear down.
+ */
+ @AfterClass
+ public static void tearDown() {
+ ParameterService.deregister(LifecycleApiForwarderParameters.class.getSimpleName());
+ simulator.stopLifecycycleApiSimulator();
+ }
+
+ @Test
+ public void testForwardPolicyUsingSimulator() throws Exception {
+
+ final ToscaServiceTemplate toscaServiceTemplate1 =
+ standardCoder.decode(ResourceUtils.getResourceAsString(POLICY_TYPE), ToscaServiceTemplate.class);
+ final ToscaServiceTemplate toscaServiceTemplate2 =
+ standardCoder.decode(ResourceUtils.getResourceAsString(POLICY), ToscaServiceTemplate.class);
+
+ final LifecycleApiPolicyForwarder forwarder = new LifecycleApiPolicyForwarder();
+ forwarder.configure(LifecycleApiForwarderParameters.class.getSimpleName());
+
+ final Collection<ToscaEntity> policies = new ArrayList<>();
+ policies.add(toscaServiceTemplate1);
+ policies.add(toscaServiceTemplate2);
+
+ forwarder.forward(policies);
+ }
+
+ @Test
+ public void testForwardPolicyFailureUsingSimulator() throws Exception {
+
+ final ToscaServiceTemplate toscaServiceTemplate1 =
+ standardCoder.decode(ResourceUtils.getResourceAsString(POLICY_TYPE), ToscaServiceTemplate.class);
+ final ToscaServiceTemplate toscaServiceTemplate2 =
+ standardCoder.decode(ResourceUtils.getResourceAsString(POLICY), ToscaServiceTemplate.class);
+ final ToscaServiceTemplate toscaServiceTemplate3 =
+ standardCoder.decode(ResourceUtils.getResourceAsString(POLICY_ERROR), ToscaServiceTemplate.class);
+ final ToscaEntity unsupportedPolicy = new UnsupportedPolicy();
+
+ final LifecycleApiPolicyForwarder forwarder = new LifecycleApiPolicyForwarder();
+ forwarder.configure(LifecycleApiForwarderParameters.class.getSimpleName());
+
+ final Collection<ToscaEntity> policies = new ArrayList<>();
+ policies.add(toscaServiceTemplate1);
+ policies.add(toscaServiceTemplate2);
+ policies.add(toscaServiceTemplate3);
+ policies.add(unsupportedPolicy);
+
+ assertThatThrownBy(() -> forwarder.forward(policies)).isInstanceOf(PolicyForwardingException.class)
+ .hasMessageContaining("Failed forwarding the following entities:");
+ }
+
+ class UnsupportedPolicy extends ToscaEntity {
+
+ @Override
+ public String getName() {
+ return "unsupported";
+ }
+ }
+}
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycleApiSimulatorMain.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycleApiSimulatorMain.java
new file mode 100644
index 00000000..9aa68876
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycleApiSimulatorMain.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * 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.
+ * 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.forwarding.xacml.pdp.testclasses;
+
+import org.onap.policy.common.endpoints.http.server.RestServer;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.distribution.forwarding.PolicyForwardingException;
+import org.onap.policy.distribution.forwarding.lifecycle.api.LifecycleApiPolicyForwarder;
+import org.onap.policy.distribution.main.rest.aaf.AafDistributionFilter;
+
+/**
+ * The class for starting/stopping simulator for testing {@link LifecycleApiPolicyForwarder} .
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class LifecycleApiSimulatorMain {
+ private RestServer restServer;
+
+ /**
+ * Starts the simulator.
+ *
+ * @throws PolicyForwardingException if error occurs
+ * @throws CoderException if error occurs
+ */
+ public void startLifecycycleApiSimulator() throws PolicyForwardingException, CoderException {
+ final StandardCoder standardCoder = new StandardCoder();
+ final RestServerParameters restServerParameters = standardCoder.decode(
+ ResourceUtils.getResourceAsString("src/test/resources/parameters/RestServerParameters.json"),
+ RestServerParameters.class);
+ restServer = new RestServer(restServerParameters, AafDistributionFilter.class,
+ LifecycycleApiSimulatorEndpoint.class);
+ if (!restServer.start()) {
+ throw new PolicyForwardingException("Failed to start rest simulator. Check log for more details...");
+ }
+ }
+
+ /**
+ * Shut down Execution.
+ */
+ public void stopLifecycycleApiSimulator() {
+ if (restServer != null) {
+ restServer.stop();
+ }
+ }
+}
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycycleApiSimulatorEndpoint.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycycleApiSimulatorEndpoint.java
new file mode 100644
index 00000000..f07605f0
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/LifecycycleApiSimulatorEndpoint.java
@@ -0,0 +1,95 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * 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.
+ * 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.forwarding.xacml.pdp.testclasses;
+
+import io.swagger.annotations.ApiParam;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.onap.policy.models.pap.concepts.PdpDeployPolicies;
+import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+
+/**
+ * Class to provide rest end points for LifecycycleApiSimulator.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+@Path("/policy")
+@Produces(MediaType.APPLICATION_JSON)
+public class LifecycycleApiSimulatorEndpoint {
+
+ /**
+ * Create policy type endpoint.
+ *
+ * @param body the post body
+ * @return the response object
+ */
+ @POST
+ @Path("/api/v1/policytypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createPolicyTypes(final ToscaServiceTemplate body) {
+ return Response.status(Response.Status.OK).entity(body).build();
+ }
+
+ /**
+ * Create policy endpoint.
+ *
+ * @param policyTypeId the policy type id
+ * @param policyTypeVersion the policy type version
+ * @param body the post body
+ * @return the response object
+ */
+ @POST
+ @Path("/api/v1/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createPolicies(@PathParam("policyTypeId") final String policyTypeId,
+ @PathParam("policyTypeVersion") final String policyTypeVersion,
+ @ApiParam(value = "Entity body of policy", required = true) final ToscaServiceTemplate body) {
+ if ("onap.policies.controlloop.operational.ApexFailure".equals(policyTypeId)) {
+ return Response.status(Response.Status.NOT_FOUND).build();
+ } else {
+ return Response.status(Response.Status.OK).entity(body).build();
+ }
+ }
+
+ /**
+ * Deploy policy endpoint.
+ *
+ * @param policies the post body
+ * @return the response object
+ */
+ @POST
+ @Path("/pap/v1/pdps/policies")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response deployPolicies(final PdpDeployPolicies policies) {
+ return Response.status(Response.Status.OK).entity(new PdpGroupDeployResponse()).build();
+ }
+}