diff options
Diffstat (limited to 'participant/participant-impl/participant-impl-dcae/src/test')
10 files changed, 316 insertions, 361 deletions
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java new file mode 100644 index 000000000..6d7592db0 --- /dev/null +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java @@ -0,0 +1,171 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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.clamp.controlloop.participant.dcae.endtoend; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.mockserver.model.HttpRequest.request; +import static org.mockserver.model.HttpResponse.response; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockserver.integration.ClientAndServer; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate; +import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.CommonTestData; +import org.onap.policy.clamp.controlloop.participant.dcae.main.rest.TestListenerUtils; +import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi; +import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopStateChangeListener; +import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.utils.coder.CoderException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@TestPropertySource(properties = "participant.file=src/test/resources/parameters/TestParameters.json") +class PartecipantDcaeTest { + + private static final CommInfrastructure INFRA = CommInfrastructure.NOOP; + private static final String TOPIC = "my-topic"; + + private static final String LOOP = "pmsh_loop"; + private static final String BLUEPRINT_DEPLOYED = "BLUEPRINT_DEPLOYED"; + + private static ClientAndServer mockClampServer; + private static ClientAndServer mockConsulServer; + + @Autowired + private ParticipantIntermediaryApi participantIntermediaryApi; + + /** + * start Servers. + */ + @BeforeAll + public static void startServers() { + + // Clamp + mockClampServer = ClientAndServer.startClientAndServer(8443); + + mockClampServer.when(request().withMethod("GET").withPath("/restservices/clds/v2/loop/getstatus/" + LOOP)) + .respond(response().withBody(CommonTestData.createJsonStatus(BLUEPRINT_DEPLOYED).toString()) + .withStatusCode(200)); + + mockClampServer.when(request().withMethod("PUT").withPath("/restservices/clds/v2/loop/deploy/" + LOOP)) + .respond(response().withStatusCode(202)); + + mockClampServer.when(request().withMethod("PUT").withPath("/restservices/clds/v2/loop/undeploy/" + LOOP)) + .respond(response().withStatusCode(202)); + + // Consul + mockConsulServer = ClientAndServer.startClientAndServer(31321); + + mockConsulServer.when(request().withMethod("PUT").withPath("/v1/kv/dcae-pmsh:policy")) + .respond(response().withStatusCode(200)); + } + + /** + * stop Server. + */ + @AfterAll + public static void stopServer() { + mockClampServer.stop(); + mockClampServer = null; + + mockConsulServer.stop(); + mockConsulServer = null; + } + + @Test + void testParticipantControlLoopStateChangeMessageListener() { + ParticipantControlLoopStateChange participantControlLoopStateChangeMsg = + TestListenerUtils.createControlLoopStateChangeMsg(ControlLoopOrderedState.UNINITIALISED); + participantControlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.PASSIVE); + + ControlLoopStateChangeListener clStateChangeListener = + new ControlLoopStateChangeListener(participantIntermediaryApi.getParticipantHandler()); + + clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopStateChangeMsg); + assertEquals(ControlLoopOrderedState.PASSIVE, participantControlLoopStateChangeMsg.getOrderedState()); + + participantControlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.RUNNING); + clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopStateChangeMsg); + assertEquals(ControlLoopOrderedState.RUNNING, participantControlLoopStateChangeMsg.getOrderedState()); + + participantControlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.RUNNING); + clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopStateChangeMsg); + assertEquals(ControlLoopOrderedState.RUNNING, participantControlLoopStateChangeMsg.getOrderedState()); + } + + @Test + void testControlLoopUpdateListener_ParticipantIdNoMatch() throws CoderException { + ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg(); + participantControlLoopUpdateMsg.getParticipantId().setName("DummyName"); + participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE); + + ControlLoopUpdateListener clUpdateListener = + new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler()); + clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg); + + // Verify the content in participantHandler + assertNotEquals(participantControlLoopUpdateMsg.getParticipantId().getName(), + participantIntermediaryApi.getParticipantHandler().getParticipantId().getName()); + } + + @Test + void testControlLoopUpdateListenerPassive() throws CoderException { + ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg(); + participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE); + + ControlLoopUpdateListener clUpdateListener = + new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler()); + clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg); + + // Verify the content in participantHandler + assertEquals(participantIntermediaryApi.getParticipantHandler().getParticipantId(), + participantControlLoopUpdateMsg.getParticipantId()); + assertEquals(1, participantIntermediaryApi.getParticipantHandler().getControlLoopHandler().getControlLoops() + .getControlLoopList().size()); + } + + @Test + void testControlLoopUpdateListenerUninitialised() throws CoderException { + ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg(); + participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.UNINITIALISED); + + ControlLoopUpdateListener clUpdateListener = + new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler()); + clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg); + + // Verify the content in participantHandler + assertEquals(participantIntermediaryApi.getParticipantHandler().getParticipantId(), + participantControlLoopUpdateMsg.getParticipantId()); + assertEquals(1, participantIntermediaryApi.getParticipantHandler().getControlLoopHandler().getControlLoops() + .getControlLoopList().size()); + } +} diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClientTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClientTest.java index 040b33f5e..6e375222e 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClientTest.java +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClientTest.java @@ -26,21 +26,25 @@ import static org.junit.Assert.assertTrue; import static org.mockserver.model.HttpRequest.request; import static org.mockserver.model.HttpResponse.response; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import javax.ws.rs.core.MediaType; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockserver.integration.ClientAndServer; import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.CommonTestData; import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameters; import org.onap.policy.clamp.controlloop.participant.dcae.model.Loop; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.StandardCoder; +import org.springframework.test.context.junit.jupiter.SpringExtension; /** * Class to perform unit test of {@link ClampHttpClient}. * */ -public class ClampHttpClientTest { +@ExtendWith(SpringExtension.class) +class ClampHttpClientTest { private static final String LOOP = "pmsh_loop"; private static final String BLUEPRINT_DEPLOYED = "BLUEPRINT_DEPLOYED"; @@ -52,7 +56,7 @@ public class ClampHttpClientTest { /** * Set up. */ - @BeforeClass + @BeforeAll public static void setUp() { CommonTestData commonTestData = new CommonTestData(); @@ -63,7 +67,8 @@ public class ClampHttpClientTest { mockServer = ClientAndServer.startClientAndServer(parameters.getClampClientParameters().getPort()); mockServer.when(request().withMethod("GET").withPath("/restservices/clds/v2/loop/getstatus/" + LOOP)) - .respond(response().withBody(CommonTestData.createJsonStatus(BLUEPRINT_DEPLOYED)).withStatusCode(200)); + .respond(response().withBody(CommonTestData.createJsonStatus(BLUEPRINT_DEPLOYED)).withStatusCode(200) + .withHeader("Content-Type", MediaType.APPLICATION_JSON)); mockServer.when(request().withMethod("PUT").withPath("/restservices/clds/v2/loop/deploy/" + LOOP)) .respond(response().withStatusCode(202)); @@ -72,15 +77,15 @@ public class ClampHttpClientTest { .respond(response().withStatusCode(202)); } - @AfterClass + @AfterAll public static void stopServer() { mockServer.stop(); mockServer = null; } @Test - public void test_getstatus() throws Exception { - try (ClampHttpClient client = new ClampHttpClient(parameters.getClampClientParameters())) { + void test_getstatus() throws Exception { + try (ClampHttpClient client = new ClampHttpClient(parameters)) { Loop status = client.getstatus(LOOP); @@ -95,8 +100,8 @@ public class ClampHttpClientTest { } @Test - public void test_deploy() throws Exception { - try (ClampHttpClient client = new ClampHttpClient(parameters.getClampClientParameters())) { + void test_deploy() throws Exception { + try (ClampHttpClient client = new ClampHttpClient(parameters)) { assertTrue(client.deploy(LOOP)); @@ -106,8 +111,8 @@ public class ClampHttpClientTest { } @Test - public void test_undeploy() throws Exception { - try (ClampHttpClient client = new ClampHttpClient(parameters.getClampClientParameters())) { + void test_undeploy() throws Exception { + try (ClampHttpClient client = new ClampHttpClient(parameters)) { assertTrue(client.undeploy(LOOP)); @@ -117,12 +122,12 @@ public class ClampHttpClientTest { } @Test - public void test_getStatusCodeNull() { + void test_getStatusCodeNull() { assertThat(ClampHttpClient.getStatusCode(null)).isEqualTo(ClampHttpClient.STATUS_NOT_FOUND); } @Test - public void test_getStatusEmptyMap() { + void test_getStatusEmptyMap() { assertThat(ClampHttpClient.getStatusCode(new Loop())).isEqualTo(ClampHttpClient.STATUS_NOT_FOUND); } } diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ConsulDcaeHttpClientTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ConsulDcaeHttpClientTest.java new file mode 100644 index 000000000..734919e4c --- /dev/null +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ConsulDcaeHttpClientTest.java @@ -0,0 +1,77 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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.clamp.controlloop.participant.dcae.httpclient; + +import static org.junit.Assert.assertTrue; +import static org.mockserver.model.HttpRequest.request; +import static org.mockserver.model.HttpResponse.response; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockserver.integration.ClientAndServer; +import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.CommonTestData; +import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameters; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +/** + * Class to perform unit test of {@link ConsulDcaeHttpClient}. + * + */ +@ExtendWith(SpringExtension.class) +class ConsulDcaeHttpClientTest { + + private static ClientAndServer mockServer; + private static ParticipantDcaeParameters parameters; + + @BeforeAll + public static void startServer() { + CommonTestData commonTestData = new CommonTestData(); + + parameters = commonTestData.toObject( + commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME), + ParticipantDcaeParameters.class); + + mockServer = ClientAndServer.startClientAndServer(parameters.getConsulClientParameters().getPort()); + + mockServer.when(request().withMethod("PUT").withPath("/v1/kv/dcae-pmsh:policy")) + .respond(response().withStatusCode(200)); + } + + @AfterAll + public static void stopServer() { + mockServer.stop(); + mockServer = null; + } + + @Test + void test_deploy() throws Exception { + try (ConsulDcaeHttpClient client = new ConsulDcaeHttpClient(parameters)) { + + assertTrue(client.deploy("policy", "")); + + } catch (Exception e) { + Assertions.fail(e.getMessage()); + } + } +} diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java index bcfaf8bb9..cb06fcb15 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java @@ -35,6 +35,7 @@ import org.onap.policy.common.parameters.ParameterGroup; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** @@ -47,10 +48,8 @@ public class CommonTestData { public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams()); private static final String REST_CLIENT_PASSWORD = "password"; private static final String REST_CLIENT_USER = "admin"; - private static final int REST_CLAMP_PORT = 8443; - private static final int REST_CONSUL_PORT = 31321; - private static final String REST_CLAMP_HOST = "localhost"; - private static final String REST_CONSUL_HOST = "consul"; + private static final String REST_CLAMP_HOST = "0.0.0.0"; + private static final String REST_CONSUL_HOST = "0.0.0.0"; private static final boolean REST_CLAMP_HTTPS = false; private static final boolean REST_CONSUL_HTTPS = false; private static final boolean REST_CLIENT_AAF = false; @@ -99,12 +98,17 @@ public class CommonTestData { */ public Map<String, Object> getClampClientParametersMap(final boolean isEmpty) { final Map<String, Object> map = new TreeMap<>(); + map.put("clientName", "Clamp"); map.put("https", REST_CLAMP_HTTPS); map.put("aaf", REST_CLIENT_AAF); if (!isEmpty) { - map.put("host", REST_CLAMP_HOST); - map.put("port", REST_CLAMP_PORT); + map.put("hostname", REST_CLAMP_HOST); + try { + map.put("port", NetworkUtil.allocPort()); + } catch (IOException e) { + throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE, "not valid port", e); + } map.put("userName", REST_CLIENT_USER); map.put("password", REST_CLIENT_PASSWORD); } @@ -120,12 +124,17 @@ public class CommonTestData { */ public Map<String, Object> getConsulClientParametersMap(final boolean isEmpty) { final Map<String, Object> map = new TreeMap<>(); + map.put("clientName", "Consul"); map.put("https", REST_CONSUL_HTTPS); map.put("aaf", REST_CLIENT_AAF); if (!isEmpty) { - map.put("host", REST_CONSUL_HOST); - map.put("port", REST_CONSUL_PORT); + map.put("hostname", REST_CONSUL_HOST); + try { + map.put("port", NetworkUtil.allocPort()); + } catch (IOException e) { + throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE, "not valid port", e); + } map.put("userName", REST_CLIENT_USER); map.put("password", REST_CLIENT_PASSWORD); } @@ -209,7 +218,7 @@ public class CommonTestData { */ public static ToscaConceptIdentifier getParticipantId() { final ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(); - participantId.setName("CDSParticipant0"); + participantId.setName("DCAEParticipant0"); participantId.setVersion("1.0.0"); return participantId; } @@ -276,7 +285,7 @@ public class CommonTestData { } /** - * create Json response from getstatus call. + * Create Json response from getstatus call. * * @param status the status of Partecipant * @return the JSON diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameterHandler.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameterHandler.java index 058a3dae4..2eb833204 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameterHandler.java +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameterHandler.java @@ -20,83 +20,45 @@ package org.onap.policy.clamp.controlloop.participant.dcae.main.parameters; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import java.io.FileNotFoundException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; -import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameterHandler; -import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameters; -import org.onap.policy.clamp.controlloop.participant.dcae.main.startstop.ParticipantDcaeCommandLineArguments; import org.onap.policy.common.utils.coder.CoderException; + /** * Class to perform unit test of {@link ParticipantParameterHandler}. * */ -public class TestParticipantDcaeParameterHandler { +class TestParticipantDcaeParameterHandler { @Test - public void testParameterHandlerNoParameterFile() throws ControlLoopException { - final String[] emptyArgumentString = { "-c", "src/test/resources/parameters/NoParametersFile.json" }; - - final ParticipantDcaeCommandLineArguments emptyArguments = new ParticipantDcaeCommandLineArguments(); - emptyArguments.parse(emptyArgumentString); + void testParameterHandlerNoParameterFile() throws ControlLoopException { + final String path = "src/test/resources/parameters/NoParametersFile.json"; - assertThatThrownBy(() -> new ParticipantDcaeParameterHandler().getParameters(emptyArguments)) + assertThatThrownBy(() -> new ParticipantDcaeParameterHandler().toParticipantDcaeParameters(path)) .hasCauseInstanceOf(CoderException.class) .hasRootCauseInstanceOf(FileNotFoundException.class); } @Test - public void testParameterHandlerInvalidParameters() throws ControlLoopException { - final String[] invalidArgumentString = { "-c", "src/test/resources/parameters/InvalidParameters.json" }; + void testParameterHandlerInvalidParameters() throws ControlLoopException { + final String path = "src/test/resources/parameters/InvalidParameters.json"; - final ParticipantDcaeCommandLineArguments invalidArguments = - new ParticipantDcaeCommandLineArguments(); - invalidArguments.parse(invalidArgumentString); - - assertThatThrownBy(() -> new ParticipantDcaeParameterHandler().getParameters(invalidArguments)) + assertThatThrownBy(() -> new ParticipantDcaeParameterHandler().toParticipantDcaeParameters(path)) .hasMessageStartingWith("error reading parameters from") .hasCauseInstanceOf(CoderException.class); } @Test - public void testParticipantParameterGroup() throws ControlLoopException { - final String[] participantConfigParameters = { "-c", "src/test/resources/parameters/TestParameters.json" }; - - final ParticipantDcaeCommandLineArguments arguments = new ParticipantDcaeCommandLineArguments(); - arguments.parse(participantConfigParameters); + void testParticipantParameterGroup() throws ControlLoopException { + final String path = "src/test/resources/parameters/TestParameters.json"; final ParticipantDcaeParameters parGroup = new ParticipantDcaeParameterHandler() - .getParameters(arguments); - assertTrue(arguments.checkSetConfigurationFilePath()); + .toParticipantDcaeParameters(path); assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, parGroup.getName()); } - - @Test - public void testParticipantVersion() throws ControlLoopException { - final String[] participantConfigParameters = { "-v" }; - final ParticipantDcaeCommandLineArguments arguments = new ParticipantDcaeCommandLineArguments(); - assertThat(arguments.parse(participantConfigParameters)).startsWith( - "ONAP Tosca defined control loop Participant"); - } - - @Test - public void testParticipantHelp() throws ControlLoopException { - final String[] participantConfigParameters = { "-h" }; - final ParticipantDcaeCommandLineArguments arguments = new ParticipantDcaeCommandLineArguments(); - assertThat(arguments.parse(participantConfigParameters)).startsWith("usage:"); - } - - @Test - public void testParticipantInvalidOption() throws ControlLoopException { - final String[] participantConfigParameters = { "-d" }; - final ParticipantDcaeCommandLineArguments arguments = new ParticipantDcaeCommandLineArguments(); - assertThatThrownBy(() -> arguments.parse(participantConfigParameters)) - .hasMessageStartingWith("invalid command line arguments specified"); - } } diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameters.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameters.java index edb429322..2320ae07b 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameters.java +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameters.java @@ -20,14 +20,12 @@ package org.onap.policy.clamp.controlloop.participant.dcae.main.parameters; -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.assertNull; import static org.junit.Assert.assertTrue; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters; import org.onap.policy.common.endpoints.parameters.TopicParameterGroup; import org.onap.policy.common.parameters.ValidationResult; @@ -36,17 +34,17 @@ import org.onap.policy.common.parameters.ValidationResult; * Class to perform unit test of {@link ParticipantParameterGroup}. * */ -public class TestParticipantDcaeParameters { +class TestParticipantDcaeParameters { CommonTestData commonTestData = new CommonTestData(); @Test - public void testParticipantParameterGroup_Named() { + void testParticipantParameterGroup_Named() { final ParticipantDcaeParameters participantParameters = new ParticipantDcaeParameters("my-name"); assertEquals("my-name", participantParameters.getName()); } @Test - public void testParticipantParameterGroup() { + void testParticipantParameterGroup() { final ParticipantDcaeParameters participantParameters = commonTestData.toObject( commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME), ParticipantDcaeParameters.class); @@ -64,7 +62,7 @@ public class TestParticipantDcaeParameters { } @Test - public void testParticipantParameterGroup_EmptyParticipantIntermediaryParameters() { + void testParticipantParameterGroup_EmptyParticipantIntermediaryParameters() { final Map<String, Object> map = commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME); map.replace("intermediaryParameters", commonTestData.getIntermediaryParametersMap(true)); @@ -75,7 +73,7 @@ public class TestParticipantDcaeParameters { } @Test - public void testParticipantParameterGroup_EmptyTopicParameters() { + void testParticipantParameterGroup_EmptyTopicParameters() { final Map<String, Object> map = commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME); final Map<String, Object> intermediaryParametersMap = commonTestData.getIntermediaryParametersMap(false); diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java index c3cc8b755..f414b7a10 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java @@ -25,7 +25,6 @@ import java.time.Instant; import java.util.LinkedHashMap; import java.util.Map; import java.util.UUID; -import lombok.Getter; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; @@ -35,10 +34,7 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantHealthCheck; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange; -import org.onap.policy.clamp.controlloop.participant.dcae.main.handler.DcaeProvider; import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.CommonTestData; -import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameters; -import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -55,23 +51,6 @@ public class TestListenerUtils { private static final String TOSCA_TEMPLATE_YAML = "examples/controlloop/PMSubscriptionHandling.yaml"; static CommonTestData commonTestData = new CommonTestData(); - @Getter - private static ParticipantHandler participantHandler; - - /** - * Method to initialize participantHandler. - */ - public static void initParticipantHandler() { - - final ParticipantDcaeParameters parameters = commonTestData.toObject( - commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME), - ParticipantDcaeParameters.class); - - DcaeProvider dcaeProvider = new DcaeProvider(parameters); - - participantHandler = dcaeProvider.getIntermediaryApi().getParticipantHandler(); - } - /** * Method to create a controlLoop from a yaml file. * @@ -120,7 +99,7 @@ public class TestListenerUtils { public static ParticipantStateChange createParticipantStateChangeMsg(final ParticipantState participantState) { final ParticipantStateChange participantStateChangeMsg = new ParticipantStateChange(); ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(); - participantId.setName("CDSParticipant0"); + participantId.setName("DCAEParticipant0"); participantId.setVersion("1.0.0"); participantStateChangeMsg.setParticipantId(participantId); @@ -146,7 +125,7 @@ public class TestListenerUtils { controlLoopId.setVersion("1.0.0"); ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(); - participantId.setName("CDSParticipant0"); + participantId.setName("DCAEParticipant0"); participantId.setVersion("1.0.0"); participantClStateChangeMsg.setControlLoopId(controlLoopId); @@ -169,7 +148,7 @@ public class TestListenerUtils { controlLoopId.setVersion("1.0.0"); ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(); - participantId.setName("CDSParticipant0"); + participantId.setName("DCAEParticipant0"); participantId.setVersion("1.0.0"); clUpdateMsg.setControlLoopId(controlLoopId); @@ -212,7 +191,7 @@ public class TestListenerUtils { */ public static ParticipantHealthCheck createParticipantHealthCheckMsg() { ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(); - participantId.setName("CDSParticipant0"); + participantId.setName("DCAEParticipant0"); participantId.setVersion("1.0.0"); ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier(); diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/startstop/TestMain.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/startstop/TestMain.java deleted file mode 100644 index f779f3a57..000000000 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/startstop/TestMain.java +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 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.clamp.controlloop.participant.dcae.main.startstop; - -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.policy.clamp.controlloop.common.ControlLoopConstants; -import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException; -import org.onap.policy.clamp.controlloop.participant.dcae.main.startstop.Main; -import org.onap.policy.clamp.controlloop.participant.dcae.main.startstop.ParticipantDcaeActivator; -import org.onap.policy.common.utils.resources.MessageConstants; -import org.onap.policy.common.utils.services.Registry; - -/** - * Class to perform unit test of {@link Main}}. - */ -public class TestMain { - - /** - * Set up. - */ - @BeforeClass - public static void setUp() { - Registry.newRegistry(); - } - - /** - * Shuts "main" down. - * - * @throws Exception if an error occurs - */ - @AfterClass - public static void tearDown() throws Exception { - // shut down activator - final ParticipantDcaeActivator activator = - Registry.getOrDefault(ControlLoopConstants.REG_CLRUNTIME_ACTIVATOR, - ParticipantDcaeActivator.class, null); - if (activator != null && activator.isAlive()) { - activator.shutdown(); - } - } - - @Test - public void testMain_Help() { - final String[] configParameters = {"-h"}; - Main main = new Main(configParameters); - assertFalse(main.isRunning()); - } - - @Test - public void testMain_Version() { - final String[] configParameters = {"-v"}; - Main main = new Main(configParameters); - assertFalse(main.isRunning()); - } - - @Test - public void testMain_Valid() { - final String[] configParameters = {"-c", "src/test/resources/parameters/TestParameters.json"}; - Main main = new Main(configParameters); - assertTrue(main.isRunning()); - - // ensure items were added to the registry - assertNotNull(Registry.get(ControlLoopConstants.REG_CLRUNTIME_ACTIVATOR, ParticipantDcaeActivator.class)); - - assertThatCode(() -> main.shutdown()).doesNotThrowAnyException(); - - assertFalse(main.isRunning()); - } - - @Test - public void testMain_NoParameter() { - assertThatConfigParameterThrownException(new String[] {}); - } - - @Test - public void testMain_FilePathNotDefined() { - assertThatConfigParameterThrownException(new String[] {"-c"}); - } - - @Test - public void testMain_TooManyCommand() { - assertThatConfigParameterThrownException(new String[] {"-h", "d"}); - } - - @Test - public void testMain_WrongParameter() { - assertThatConfigParameterThrownException(new String[] {"-d"}); - } - - private void assertThatConfigParameterThrownException(final String[] configParameters) { - assertThatThrownBy(() -> Main.main(configParameters)).isInstanceOf(ControlLoopRuntimeException.class) - .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_CLAMP)); - } - - @Test - public void testParticipant_NoFileWithThisName() { - assertThatConfigFileThrownException("src/test/resources/parameters/NoFileWithThisName.json"); - } - - @Test - public void testParticipant_NotValidFile() { - assertThatConfigFileThrownException("src/test/resources/parameters"); - } - - @Test - public void testParticipant_NoParameters() { - assertThatConfigFileThrownException("src/test/resources/parameters/NoParameters.json"); - } - - @Test - public void testParticipant_InvalidParameters() { - assertThatConfigFileThrownException("src/test/resources/parameters/InvalidParameters.json"); - } - - @Test - public void testParticipant_WrongJsonFormat() { - assertThatConfigFileThrownException("src/test/resources/parameters/Unreadable.json"); - } - - private void assertThatConfigFileThrownException(final String configFilePath) { - final String[] configParameters = new String[] {"-c", configFilePath}; - assertThatThrownBy(() -> new Main(configParameters)).isInstanceOf(ControlLoopRuntimeException.class) - .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_CLAMP)); - } -} diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/startstop/TestParticipantDcaeActivator.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/startstop/TestParticipantDcaeActivator.java deleted file mode 100644 index 1903868e2..000000000 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/startstop/TestParticipantDcaeActivator.java +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 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.clamp.controlloop.participant.dcae.main.startstop; - -import static org.assertj.core.api.Assertions.assertThatIllegalStateException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.CommonTestData; -import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameterHandler; -import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameters; -import org.onap.policy.clamp.controlloop.participant.dcae.main.startstop.ParticipantDcaeActivator; -import org.onap.policy.clamp.controlloop.participant.dcae.main.startstop.ParticipantDcaeCommandLineArguments; -import org.onap.policy.common.utils.services.Registry; - -/** - * Class to perform unit test of {@link ParticipantDcaeActivator}}. - * - */ -public class TestParticipantDcaeActivator { - - private static ParticipantDcaeActivator activator; - - /** - * Initializes an activator. - * - * @throws Exception if an error occurs - */ - @BeforeClass - public static void setUp() throws Exception { - Registry.newRegistry(); - final String[] participantConfigParameters = { "-c", "src/test/resources/parameters/TestParameters.json"}; - final ParticipantDcaeCommandLineArguments arguments = - new ParticipantDcaeCommandLineArguments(participantConfigParameters); - final ParticipantDcaeParameters parGroup = - new ParticipantDcaeParameterHandler().getParameters(arguments); - activator = new ParticipantDcaeActivator(parGroup); - } - - /** - * Method for cleanup after each test. - * - * @throws Exception if an error occurs - */ - @AfterClass - public static void teardown() throws Exception { - // shut down activator - if (activator != null && activator.isAlive()) { - activator.shutdown(); - } - } - - @Test - public void testParticipantActivator() { - activator.start(); - assertTrue(activator.isAlive()); - assertTrue(activator.getParameters().isValid()); - assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, activator.getParameters().getName()); - - // repeat - should throw an exception - assertThatIllegalStateException().isThrownBy(() -> activator.start()); - assertTrue(activator.isAlive()); - assertTrue(activator.getParameters().isValid()); - - activator.shutdown(); - assertFalse(activator.isAlive()); - - // repeat - should throw an exception - assertThatIllegalStateException().isThrownBy(() -> activator.shutdown()); - assertFalse(activator.isAlive()); - } -} diff --git a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParameters.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParameters.json index 789fc7bbd..580eea734 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParameters.json +++ b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParameters.json @@ -1,22 +1,21 @@ { "name": "ControlLoopParticipantGroup", "clampClientParameters": { - "name": "Clamp", - "host": "0.0.0.0", + "clientName": "Clamp", + "hostname": "0.0.0.0", "port": 8443, "userName": "admin", "password": "password", - "https": true, - "aaf": false + "useHttps": true, + "allowSelfSignedCerts": false }, "consulClientParameters": { - "name": "Clamp", - "host": "consul", + "clientName": "Consul", + "hostname": "consul", "port": 31321, "userName": "admin", "password": "password", - "https": false, - "aaf": false + "useHttps": false }, "intermediaryParameters": { "name": "Participant parameters", |