summaryrefslogtreecommitdiffstats
path: root/plugins/forwarding-plugins/src/test/java
diff options
context:
space:
mode:
authorSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-12-14 18:12:07 +0000
committerSirisha_Manchikanti <sirisha.manchikanti@est.tech>2022-01-06 13:12:50 +0000
commit3d170c6e14976549cd2edc405c5c242110bff2ff (patch)
tree2201c54f4c9a227b4337c9a640ab2e2b8c1cc630 /plugins/forwarding-plugins/src/test/java
parent5f46449a3a73a101fb6e7926dd48e1672ad3ed7b (diff)
Add ControlLoop distribution to runtime
This commit unpacks the csar received either from SDC or for local verification from file-system, prepares the toscaservicetemplate with needed node-types and data-types, forwards the template to controlloop runtime components for commisioning of controlloop. Issue-ID: POLICY-3808 Signed-off-by: Sirisha_Manchikanti <sirisha.manchikanti@est.tech> Change-Id: Ib3600542aca7b32ae19242c2f924bdaf2ab870a8
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/LifecycleApiControlLoopForwarderParametersTest.java88
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiControlLoopForwarderTest.java115
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycleApiControlLoopSimulatorEndpoint.java54
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycleApiControlLoopSimulatorMain.java67
4 files changed, 324 insertions, 0 deletions
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiControlLoopForwarderParametersTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiControlLoopForwarderParametersTest.java
new file mode 100644
index 00000000..ba8d9bfb
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiControlLoopForwarderParametersTest.java
@@ -0,0 +1,88 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022 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.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.distribution.forwarding.testclasses.CommonTestData;
+
+/**
+ * Class to perform unit test of {@link LifecycleApiControlLoopForwarderParameters}.
+ *
+ * @author Sirisha Manchikanti (sirisha.manchikanti@est.tech)
+ */
+public class LifecycleApiControlLoopForwarderParametersTest {
+
+ private static final String CONTROLLOOP_RUNTIME_HOST_NAME = "0.0.0.0";
+ private static final int CONTROLLOOP_RUNTIME_PORT = 6969;
+ private static final String CONTROLLOOP_RUNTIME_USER = "policyadmin";
+ private static final String CONTROLLOOP_RUNTIME_PASSWORD = "zb!XztG34";
+
+
+ @Test
+ public void testValidParameters() {
+ final LifecycleApiControlLoopForwarderParameters configurationParameters =
+ CommonTestData.getPolicyForwarderParameters(
+ "src/test/resources/parameters/LifecycleApiControlLoopForwarderParameters.json",
+ LifecycleApiControlLoopForwarderParameters.class);
+
+ assertEquals(LifecycleApiControlLoopForwarderParameters.class.getSimpleName(),
+ configurationParameters.getName());
+
+ assertEquals(CONTROLLOOP_RUNTIME_HOST_NAME,
+ configurationParameters.getControlLoopRuntimeParameters().getHostname());
+ assertEquals(CONTROLLOOP_RUNTIME_PORT,
+ configurationParameters.getControlLoopRuntimeParameters().getPort());
+ assertFalse(configurationParameters.getControlLoopRuntimeParameters().isUseHttps());
+ assertEquals(CONTROLLOOP_RUNTIME_USER,
+ configurationParameters.getControlLoopRuntimeParameters().getUserName());
+ assertEquals(CONTROLLOOP_RUNTIME_PASSWORD,
+ configurationParameters.getControlLoopRuntimeParameters().getPassword());
+
+ assertThat(configurationParameters.validate().getResult()).isNull();
+ assertEquals(ValidationStatus.CLEAN, configurationParameters.validate().getStatus());
+ }
+
+ @Test
+ public void testInvalidParameters() {
+ final LifecycleApiForwarderParameters configurationParameters =
+ CommonTestData.getPolicyForwarderParameters(
+ "src/test/resources/parameters/LifecycleApiPolicyForwarderParametersInvalid.json",
+ LifecycleApiForwarderParameters.class);
+
+ assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
+ }
+
+ @Test
+ public void testEmptyParameters() {
+ final LifecycleApiForwarderParameters configurationParameters =
+ CommonTestData.getPolicyForwarderParameters("src/test/resources/parameters/EmptyParameters.json",
+ LifecycleApiForwarderParameters.class);
+
+ assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
+ }
+}
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiControlLoopForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiControlLoopForwarderTest.java
new file mode 100644
index 00000000..047482ef
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiControlLoopForwarderTest.java
@@ -0,0 +1,115 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022 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.assertThatCode;
+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.testclasses.CommonTestData;
+import org.onap.policy.distribution.forwarding.testclasses.LifecycleApiControlLoopSimulatorMain;
+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 LifecycleApiControlLoopForwarder}.
+ *
+ * @author Sirisha Manchikanti (sirisha.manchikanti@est.tech)
+ */
+public class LifecycleApiControlLoopForwarderTest {
+
+ private static final String CONTROL_LOOP = "src/test/resources/parameters/sample_control_loop.json";
+ private final StandardCoder standardCoder = new StandardCoder();
+ private static final LifecycleApiControlLoopSimulatorMain simulator = new LifecycleApiControlLoopSimulatorMain();
+
+ /**
+ * 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/LifecycleApiControlLoopForwarderParameters.json",
+ LifecycleApiControlLoopForwarderParameters.class);
+ ParameterService.register(parameterGroup);
+ simulator.startLifecycycleApiSimulator();
+ if (!NetworkUtil.isTcpPortOpen("0.0.0.0", 6969, 50, 200L)) {
+ throw new IllegalStateException("cannot connect to port 6969");
+ }
+ }
+
+ /**
+ * Tear down.
+ */
+ @AfterClass
+ public static void tearDown() {
+ ParameterService.deregister(LifecycleApiControlLoopForwarderParameters.class.getSimpleName());
+ simulator.stopLifecycycleApiSimulator();
+ }
+
+ @Test
+ public void testForwardControlLoopUsingSimulator() throws Exception {
+ assertThatCode(() -> {
+ final ToscaServiceTemplate toscaServiceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(CONTROL_LOOP), ToscaServiceTemplate.class);
+
+ final LifecycleApiControlLoopForwarder forwarder = new LifecycleApiControlLoopForwarder();
+ forwarder.configure(LifecycleApiControlLoopForwarderParameters.class.getSimpleName());
+
+ final Collection<ToscaEntity> controlLoopList = new ArrayList<>();
+ controlLoopList.add(toscaServiceTemplate);
+
+ forwarder.forward(controlLoopList);
+
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testForwardControlLoopFailureUsingSimulator() throws Exception {
+
+ final ToscaEntity toscaEntity = new ToscaEntity();
+ toscaEntity.setName("FailureCase");
+
+ final LifecycleApiControlLoopForwarder forwarder = new LifecycleApiControlLoopForwarder();
+ forwarder.configure(LifecycleApiControlLoopForwarderParameters.class.getSimpleName());
+
+ final Collection<ToscaEntity> controlLoopList = new ArrayList<>();
+ controlLoopList.add(toscaEntity);
+
+ assertThatThrownBy(() -> forwarder.forward(controlLoopList)).isInstanceOf(PolicyForwardingException.class)
+ .hasMessageContaining("Failed forwarding the following entities:");
+ }
+}
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycleApiControlLoopSimulatorEndpoint.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycleApiControlLoopSimulatorEndpoint.java
new file mode 100644
index 00000000..d361d166
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycleApiControlLoopSimulatorEndpoint.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022 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.testclasses;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+
+/**
+ * Class to provide rest end points for LifecycleApiControlLoopSimulator.
+ *
+ * @author Sirisha Manchikanti (sirisha.manchikanti@est.tech)
+ */
+@Path("/onap")
+@Produces(MediaType.APPLICATION_JSON)
+public class LifecycleApiControlLoopSimulatorEndpoint {
+
+ /**
+ * ControlLoop commissioning end-point.
+ *
+ * @param body the post body
+ * @return the response object
+ */
+ @POST
+ @Path("/controlloop/v2/commission")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response commissionControlLoop(final ToscaServiceTemplate body) {
+ return Response.status(Response.Status.OK).entity(body).build();
+ }
+}
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycleApiControlLoopSimulatorMain.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycleApiControlLoopSimulatorMain.java
new file mode 100644
index 00000000..a60fda1d
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/testclasses/LifecycleApiControlLoopSimulatorMain.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022 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.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.LifecycleApiControlLoopForwarder;
+import org.onap.policy.distribution.main.rest.aaf.AafDistributionFilter;
+
+/**
+ * The class for starting/stopping simulator for testing {@link LifecycleApiControlLoopForwarder} .
+ *
+ * @author Sirisha Manchikanti (sirisha.manchikanti@est.tech)
+ */
+public class LifecycleApiControlLoopSimulatorMain {
+ 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,
+ LifecycleApiControlLoopSimulatorEndpoint.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();
+ }
+ }
+}