summaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-simulator/src/test
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2021-06-09 14:22:50 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2021-06-14 09:22:46 +0100
commit1595ed794f395816b0bfb6296aecb4a18bbbdec1 (patch)
tree9b315c1f04a4c3ff67a44b0d8cdb0debbd4435c6 /participant/participant-impl/participant-impl-simulator/src/test
parent9deb780264c7d12aa932fbb3ff2d442fcb3e8d5a (diff)
Convert Participant Simulator to SpringBoot Application
Issue-ID: POLICY-3246 Change-Id: I0e5220be826531cf0338d5cad7018d06bda3daf5 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-simulator/src/test')
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java291
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/intermediary/TestControlLoopUpdateListener.java91
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java11
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameterHandler.java77
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java18
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/CommonParticipantRestServer.java227
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/RestControllerTest.java95
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java24
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestSimulationRestController.java186
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/startstop/TestMain.java117
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/startstop/TestParticipantSimulatorActivator.java89
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties7
12 files changed, 327 insertions, 906 deletions
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
new file mode 100644
index 000000000..832399660
--- /dev/null
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
@@ -0,0 +1,291 @@
+/*-
+ * ============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.simulator.endtoend;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+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;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
+import org.onap.policy.clamp.controlloop.models.messages.rest.TypedSimpleResponse;
+import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener;
+import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.CommonTestData;
+import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.AbstractRestController;
+import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.TestListenerUtils;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+@TestPropertySource(locations = {"classpath:application_test.properties"})
+class ParticipantSimulatorTest {
+
+ private static final String PARTICIPANTS_ENDPOINT = "participants";
+ private static final String ELEMENTS_ENDPOINT = "elements";
+ private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
+ private static final String TOPIC = "my-topic";
+
+ public static final Coder coder = new StandardCoder();
+
+ @Value("${spring.security.user.name}")
+ private String user;
+
+ @Value("${spring.security.user.password}")
+ private String password;
+
+ @LocalServerPort
+ private int randomServerPort;
+
+ @Autowired
+ private TestRestTemplate restTemplate;
+
+ @Autowired
+ private ParticipantIntermediaryApi participantIntermediaryApi;
+
+ private static final Object lockit = new Object();
+ private boolean check = false;
+
+ private void setUp() throws Exception {
+ synchronized (lockit) {
+ if (!check) {
+ check = true;
+ ControlLoopUpdateListener clUpdateListener =
+ new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler());
+
+ ParticipantControlLoopUpdate participantControlLoopUpdateMsg =
+ TestListenerUtils.createControlLoopUpdateMsg();
+ participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
+ clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
+
+ }
+ }
+ }
+
+ private String getPath(String path) {
+ return "http://localhost:" + randomServerPort + "/onap/participantsim/v2/" + path;
+ }
+
+ void testSwagger(String endPoint) {
+ HttpEntity<Void> request = new HttpEntity<>(null, createHttpHeaders());
+ ResponseEntity<String> response =
+ restTemplate.exchange(getPath("api-docs"), HttpMethod.GET, request, String.class);
+ assertThat(response.getStatusCodeValue()).isEqualTo(200);
+ assertTrue(response.getBody().contains("/onap/participantsim/v2/" + endPoint));
+ }
+
+ @Test
+ void testEndParticipatsSwagger() {
+ testSwagger(PARTICIPANTS_ENDPOINT);
+ }
+
+ @Test
+ void testElementsSwagger() {
+ testSwagger(ELEMENTS_ENDPOINT);
+ }
+
+ @Test
+ void testProducerYaml() {
+ MediaType yamlMediaType = new MediaType("application", "yaml");
+ HttpHeaders headers = createHttpHeaders();
+ headers.setAccept(Collections.singletonList(yamlMediaType));
+ HttpEntity<Void> request = new HttpEntity<>(null, headers);
+ String path = getPath(PARTICIPANTS_ENDPOINT + "/org.onap.PM_CDS_Blueprint/1");
+
+ ResponseEntity<String> response = restTemplate.exchange(path, HttpMethod.GET, request, String.class);
+
+ assertThat(response.getStatusCodeValue()).isEqualTo(200);
+ assertTrue(response.getHeaders().getContentType().isCompatibleWith(yamlMediaType));
+ }
+
+ @Test
+ void testQuery_Unauthorized() throws Exception {
+ String path = getPath(PARTICIPANTS_ENDPOINT + "/org.onap.PM_CDS_Blueprint/1");
+
+ // authorized call
+ ResponseEntity<String> response =
+ restTemplate.exchange(path, HttpMethod.GET, new HttpEntity<>(null, createHttpHeaders()), String.class);
+ assertThat(response.getStatusCodeValue()).isEqualTo(200);
+
+ // unauthorized call
+ response = restTemplate.exchange(path, HttpMethod.GET, new HttpEntity<>(null, new HttpHeaders()), String.class);
+ assertThat(response.getStatusCodeValue()).isEqualTo(401);
+ }
+
+ private HttpHeaders createHttpHeaders() {
+ HttpHeaders headers = new HttpHeaders();
+ headers.setBasicAuth(user, password);
+ return headers;
+ }
+
+ protected <T> ResponseEntity<T> performGet(String endpoint, Class<T> responseType, UUID uuid) throws Exception {
+ HttpHeaders httpHeaders = createHttpHeaders();
+ if (uuid != null) {
+ httpHeaders.add(AbstractRestController.REQUEST_ID_NAME, uuid.toString());
+ }
+ HttpEntity<Void> request = new HttpEntity<>(null, httpHeaders);
+ return restTemplate.exchange(getPath(endpoint), HttpMethod.GET, request, responseType);
+ }
+
+ protected <T> ResponseEntity<T> performGet(String endpoint, Class<T> responseType) throws Exception {
+ return performGet(endpoint, responseType, null);
+ }
+
+ protected <T, R> ResponseEntity<R> performPut(String path, T body, ParameterizedTypeReference<R> responseType,
+ UUID uuid) throws Exception {
+ HttpHeaders httpHeaders = createHttpHeaders();
+ if (uuid != null) {
+ httpHeaders.add(AbstractRestController.REQUEST_ID_NAME, uuid.toString());
+ }
+ HttpEntity<T> request = new HttpEntity<>(body, httpHeaders);
+ return restTemplate.exchange(getPath(path), HttpMethod.PUT, request, responseType);
+ }
+
+ @Test
+ void testQueryParticipants() throws Exception {
+ Participant participant = new Participant();
+ ToscaConceptIdentifier participantId = CommonTestData.getParticipantId();
+ participant.setDefinition(participantId);
+ participant.setName(participantId.getName());
+ participant.setVersion(participantId.getVersion());
+ UUID uuid = UUID.randomUUID();
+
+ // GET REST call for querying the participants
+ ResponseEntity<String> response = performGet(
+ PARTICIPANTS_ENDPOINT + "/" + participant.getKey().getName() + "/" + participant.getKey().getVersion(),
+ String.class, uuid);
+ checkResponseEntity(response, 200, uuid);
+
+ Participant[] returnValue = coder.decode(response.getBody(), Participant[].class);
+ assertThat(returnValue).hasSize(1);
+ // Verify the result of GET participants with what is stored
+ assertEquals(participant.getDefinition(), returnValue[0].getDefinition());
+ }
+
+ private <T> void checkResponseEntity(ResponseEntity<T> response, int status, UUID uuid) {
+ assertThat(response.getStatusCodeValue()).isEqualTo(status);
+ assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_MINOR_NAME)).isEqualTo("0");
+ assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_PATCH_NAME)).isEqualTo("0");
+ assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_LATEST_NAME)).isEqualTo("1.0.0");
+ assertThat(getHeader(response.getHeaders(), AbstractRestController.REQUEST_ID_NAME)).isEqualTo(uuid.toString());
+ }
+
+ private String getHeader(HttpHeaders httpHeaders, String param) {
+ List<String> list = httpHeaders.get(param);
+ assertThat(list).hasSize(1);
+ return list.get(0);
+ }
+
+ @Test
+ void testQueryControlLoopElements() throws Exception {
+ setUp();
+ UUID uuid = UUID.randomUUID();
+ ToscaConceptIdentifier participantId = CommonTestData.getParticipantId();
+
+ // GET REST call for querying the controlLoop elements
+ ResponseEntity<String> response =
+ performGet(ELEMENTS_ENDPOINT + "/" + participantId.getName() + "/" + participantId.getVersion(),
+ String.class, uuid);
+ checkResponseEntity(response, 200, uuid);
+
+ Map returnValue = coder.decode(response.getBody(), Map.class);
+ // Verify the result of GET controlloop elements with what is stored
+ assertThat(returnValue).isEmpty();
+ }
+
+ @Test
+ void testUpdateParticipant() throws Exception {
+ setUp();
+ List<Participant> participants = participantIntermediaryApi.getParticipants(
+ CommonTestData.getParticipantId().getName(), CommonTestData.getParticipantId().getVersion());
+ assertEquals(ParticipantState.UNKNOWN, participants.get(0).getParticipantState());
+ // Change the state of the participant to PASSIVE from UNKNOWN
+ participants.get(0).setParticipantState(ParticipantState.PASSIVE);
+ UUID uuid = UUID.randomUUID();
+
+ // PUT REST call for updating Participant
+ ResponseEntity<TypedSimpleResponse<Participant>> response = performPut(PARTICIPANTS_ENDPOINT,
+ participants.get(0), new ParameterizedTypeReference<TypedSimpleResponse<Participant>>() {}, uuid);
+ checkResponseEntity(response, 200, uuid);
+
+ TypedSimpleResponse<Participant> resp = response.getBody();
+ assertNotNull(resp.getResponse());
+ // Verify the response and state returned by PUT REST call for updating participants
+ assertEquals(participants.get(0).getDefinition(), resp.getResponse().getDefinition());
+ assertEquals(ParticipantState.PASSIVE, resp.getResponse().getParticipantState());
+ }
+
+ @Test
+ void testUpdateControlLoopElement() throws Exception {
+ setUp();
+ ControlLoop controlLoop = TestListenerUtils.createControlLoop();
+ Map<UUID, ControlLoopElement> controlLoopElements = participantIntermediaryApi.getControlLoopElements(
+ controlLoop.getDefinition().getName(), controlLoop.getDefinition().getVersion());
+
+ UUID uuid = controlLoopElements.keySet().iterator().next();
+ ControlLoopElement controlLoopElement = controlLoopElements.get(uuid);
+
+ // Check the initial state on the ControlLoopElement, which is UNINITIALISED
+ assertEquals(ControlLoopOrderedState.UNINITIALISED, controlLoopElement.getOrderedState());
+
+ // Change the state of the ControlLoopElement to PASSIVE from UNINITIALISED
+ controlLoopElement.setOrderedState(ControlLoopOrderedState.PASSIVE);
+
+ // PUT REST call for updating ControlLoopElement
+ ResponseEntity<TypedSimpleResponse<ControlLoopElement>> response = performPut(ELEMENTS_ENDPOINT,
+ controlLoopElement, new ParameterizedTypeReference<TypedSimpleResponse<ControlLoopElement>>() {}, uuid);
+ checkResponseEntity(response, 200, uuid);
+
+ TypedSimpleResponse<ControlLoopElement> resp = response.getBody();
+ assertNotNull(resp.getResponse());
+ // Verify the response and state returned by PUT REST call for updating participants
+ assertEquals(controlLoopElement.getDefinition(), resp.getResponse().getDefinition());
+ assertEquals(ControlLoopOrderedState.PASSIVE, resp.getResponse().getOrderedState());
+ }
+}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/intermediary/TestControlLoopUpdateListener.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/intermediary/TestControlLoopUpdateListener.java
deleted file mode 100644
index a307d3457..000000000
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/intermediary/TestControlLoopUpdateListener.java
+++ /dev/null
@@ -1,91 +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.simulator.main.intermediary;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
-import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener;
-import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.CommonTestData;
-import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.TestListenerUtils;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.utils.coder.CoderException;
-
-/**
- * Class to perform unit test of {@link ControlLoopUpdateListener}.
- */
-public class TestControlLoopUpdateListener {
- private static ControlLoopUpdateListener clUpdateListener;
- private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
- private static final String TOPIC = "my-topic";
- static CommonTestData commonTestData = new CommonTestData();
-
- /**
- * Method for setup.
- *
- * @throws ParticipantException if some error occurs while starting up the participant
- * @throws FileNotFoundException if the file is missing
- * @throws IOException if IO exception occurs
- */
- @BeforeClass
- public static void setUp() throws ControlLoopException, FileNotFoundException, IOException {
- TestListenerUtils.initParticipantHandler();
- clUpdateListener = new ControlLoopUpdateListener(TestListenerUtils.getParticipantHandler());
- }
-
- @Test
- public void testControlLoopUpdateListener_ParticipantIdNoMatch() throws CoderException {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg = prepareMsg("DummyName");
- clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
-
- // Verify the content in participantHandler
- assertNotEquals(participantControlLoopUpdateMsg.getParticipantId().getName(),
- TestListenerUtils.getParticipantHandler().getParticipantId().getName());
- }
-
- @Test
- public void testControlLoopUpdateListener() throws CoderException {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg = prepareMsg("org.onap.PM_CDS_Blueprint");
- clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
-
- // Verify the content in participantHandler
- assertEquals(TestListenerUtils.getParticipantHandler().getParticipantId(),
- participantControlLoopUpdateMsg.getParticipantId());
- assertThat(TestListenerUtils.getParticipantHandler().getControlLoopHandler().getControlLoops()
- .getControlLoopList()).hasSize(1);
- }
-
- private ParticipantControlLoopUpdate prepareMsg(final String participantName) {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg;
- participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
- participantControlLoopUpdateMsg.getParticipantId().setName(participantName);
- participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
- return participantControlLoopUpdateMsg;
- }
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java
index 0a8754256..8ca139bcd 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java
@@ -48,7 +48,7 @@ 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";
+ public static final String REST_SERVER_HOST = "0.0.0.0";
private static final boolean REST_SERVER_HTTPS = true;
private static final boolean REST_SERVER_AAF = false;
@@ -197,8 +197,8 @@ public class CommonTestData {
return coder.decode(getParticipantParameterGroupAsString(port), ParticipantSimulatorParameters.class);
} catch (CoderException e) {
- throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE,
- "cannot read participant parameters", e);
+ throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE, "cannot read participant parameters",
+ e);
}
}
@@ -220,8 +220,8 @@ public class CommonTestData {
return json;
} catch (IOException e) {
- throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE,
- "cannot read participant parameters", e);
+ throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE, "cannot read participant parameters",
+ e);
}
}
@@ -239,6 +239,7 @@ public class CommonTestData {
/**
* Nulls out a field within a JSON string.
+ *
* @param json JSON string
* @param field field to be nulled out
* @return a new JSON string with the field nulled out
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameterHandler.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameterHandler.java
index e94939af8..44b49f355 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameterHandler.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameterHandler.java
@@ -20,101 +20,52 @@
package org.onap.policy.clamp.controlloop.participant.simulator.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.apache.commons.io.DirectoryWalker.CancelException;
-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.simulator.main.startstop.ParticipantSimulatorCommandLineArguments;
import org.onap.policy.common.utils.coder.CoderException;
/**
* Class to perform unit test of {@link ParticipantParameterHandler}.
*/
-public class TestParticipantSimulatorParameterHandler {
+class TestParticipantSimulatorParameterHandler {
@Test
- public void testParameterHandlerNoParameterFile() throws ControlLoopException {
- final String[] emptyArgumentString = { "-c", "src/test/resources/parameters/NoParametersFile.json" };
+ void testParameterHandlerNoParameterFile() throws ControlLoopException {
+ final String path = "src/test/resources/parameters/NoParametersFile.json";
- final ParticipantSimulatorCommandLineArguments emptyArguments = new ParticipantSimulatorCommandLineArguments();
- emptyArguments.parse(emptyArgumentString);
-
- assertThatThrownBy(() -> new ParticipantSimulatorParameterHandler().getParameters(emptyArguments))
+ assertThatThrownBy(() -> new ParticipantSimulatorParameterHandler().toParticipantSimulatorParameters(path))
.hasCauseInstanceOf(CoderException.class)
.hasRootCauseInstanceOf(FileNotFoundException.class);
}
@Test
- public void testParameterHandlerInvalidParameters() throws ControlLoopException {
- final String[] invalidArgumentString = { "-c", "src/test/resources/parameters/InvalidParameters.json" };
-
- final ParticipantSimulatorCommandLineArguments invalidArguments =
- new ParticipantSimulatorCommandLineArguments();
- invalidArguments.parse(invalidArgumentString);
+ void testParameterHandlerInvalidParameters() throws ControlLoopException {
+ final String path = "src/test/resources/parameters/InvalidParameters.json";
- assertThatThrownBy(() -> new ParticipantSimulatorParameterHandler().getParameters(invalidArguments))
+ assertThatThrownBy(() -> new ParticipantSimulatorParameterHandler().toParticipantSimulatorParameters(path))
.hasMessageStartingWith("error reading parameters from")
.hasCauseInstanceOf(CoderException.class);
}
@Test
- public void testParameterHandlerNoParameters() throws CancelException, ControlLoopException {
- final String[] noArgumentString = { "-c", "src/test/resources/parameters/EmptyParameters.json" };
+ void testParameterHandlerNoParameters() throws CancelException, ControlLoopException {
+ final String path = "src/test/resources/parameters/EmptyParameters.json";
- final ParticipantSimulatorCommandLineArguments noArguments = new ParticipantSimulatorCommandLineArguments();
- noArguments.parse(noArgumentString);
-
- assertThatThrownBy(() -> new ParticipantSimulatorParameterHandler().getParameters(noArguments))
+ assertThatThrownBy(() -> new ParticipantSimulatorParameterHandler().toParticipantSimulatorParameters(path))
.hasMessageContaining("no parameters found");
}
@Test
- public void testParticipantParameterGroup() throws ControlLoopException {
- final String[] participantConfigParameters = { "-c", "src/test/resources/parameters/TestParameters.json"};
-
- final ParticipantSimulatorCommandLineArguments arguments = new ParticipantSimulatorCommandLineArguments();
- arguments.parse(participantConfigParameters);
+ void testParticipantParameterGroup() throws ControlLoopException {
+ final String path = "src/test/resources/parameters/TestParameters.json";
final ParticipantSimulatorParameters parGroup = new ParticipantSimulatorParameterHandler()
- .getParameters(arguments);
- assertTrue(arguments.checkSetConfigurationFilePath());
+ .toParticipantSimulatorParameters(path);
assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, parGroup.getName());
}
-
- @Test
- public void testParticipantVersion() throws ControlLoopException {
- final String[] participantConfigParameters = { "-v" };
- final ParticipantSimulatorCommandLineArguments arguments = new ParticipantSimulatorCommandLineArguments();
- assertThat(arguments.parse(participantConfigParameters)).startsWith(
- "ONAP Tosca defined control loop Participant");
- }
-
- @Test
- public void testParticipantHelp() throws ControlLoopException {
- final String[] participantConfigParameters = { "-h" };
- final ParticipantSimulatorCommandLineArguments arguments = new ParticipantSimulatorCommandLineArguments();
- assertThat(arguments.parse(participantConfigParameters)).startsWith("usage:");
- }
-
- @Test
- public void testParticipant_TooManyArguments() throws ControlLoopException {
- final String[] participantConfigParameters = { "-c", "src/test/resources/parameters/TestParameters.json",
- "TooMany"};
- final ParticipantSimulatorCommandLineArguments arguments = new ParticipantSimulatorCommandLineArguments();
- assertThatThrownBy(() -> arguments.parse(participantConfigParameters))
- .hasMessageStartingWith("too many command line arguments specified");
- }
-
- @Test
- public void testParticipantInvalidOption() throws ControlLoopException {
- final String[] participantConfigParameters = { "-d" };
- final ParticipantSimulatorCommandLineArguments arguments = new ParticipantSimulatorCommandLineArguments();
- assertThatThrownBy(() -> arguments.parse(participantConfigParameters))
- .hasMessageStartingWith("invalid command line arguments specified");
- }
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java
index 8027d6f08..41c5b09b0 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java
@@ -26,23 +26,23 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ValidationResult;
/**
* Class to perform unit test of {@link ParticipantParameterGroup}.
*/
-public class TestParticipantSimulatorParameters {
+class TestParticipantSimulatorParameters {
CommonTestData commonTestData = new CommonTestData();
@Test
- public void testParticipantParameterGroup_Named() {
+ void testParticipantParameterGroup_Named() {
final ParticipantSimulatorParameters participantParameters = new ParticipantSimulatorParameters("my-name");
assertEquals("my-name", participantParameters.getName());
}
@Test
- public void testParticipantParameterGroup() {
+ void testParticipantParameterGroup() {
final ParticipantSimulatorParameters participantParameters = commonTestData.toObject(
commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME),
ParticipantSimulatorParameters.class);
@@ -51,7 +51,7 @@ public class TestParticipantSimulatorParameters {
}
@Test
- public void testParticipantParameterGroup_NullName() {
+ void testParticipantParameterGroup_NullName() {
final ParticipantSimulatorParameters participantParameters = commonTestData
.toObject(commonTestData.getParticipantParameterGroupMap(null),
ParticipantSimulatorParameters.class);
@@ -62,7 +62,7 @@ public class TestParticipantSimulatorParameters {
}
@Test
- public void testParticipantParameterGroup_EmptyName() {
+ void testParticipantParameterGroup_EmptyName() {
final ParticipantSimulatorParameters participantParameters = commonTestData
.toObject(commonTestData.getParticipantParameterGroupMap(""),
ParticipantSimulatorParameters.class);
@@ -74,7 +74,7 @@ public class TestParticipantSimulatorParameters {
}
@Test
- public void testParticipantParameterGroup_SetName() {
+ void testParticipantParameterGroup_SetName() {
final ParticipantSimulatorParameters participantParameters = commonTestData.toObject(
commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME),
ParticipantSimulatorParameters.class);
@@ -84,7 +84,7 @@ public class TestParticipantSimulatorParameters {
}
@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));
@@ -95,7 +95,7 @@ public class TestParticipantSimulatorParameters {
}
@Test
- public void testParticipantParameterGroupp_EmptyTopicParameters() {
+ void testParticipantParameterGroupp_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-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/CommonParticipantRestServer.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/CommonParticipantRestServer.java
deleted file mode 100644
index ae004de49..000000000
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/CommonParticipantRestServer.java
+++ /dev/null
@@ -1,227 +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.simulator.main.rest;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
-import org.glassfish.jersey.client.ClientProperties;
-import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
-import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.CommonTestData;
-import org.onap.policy.clamp.controlloop.participant.simulator.main.startstop.Main;
-import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
-import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
-import org.onap.policy.common.gson.GsonMessageBodyHandler;
-import org.onap.policy.common.utils.network.NetworkUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Class to perform Rest unit tests.
- *
- */
-
-public class CommonParticipantRestServer {
-
- private static final String CONFIG_FILE = "src/test/resources/parameters/TestConfigParameters.json";
- private static final Logger LOGGER = LoggerFactory.getLogger(CommonParticipantRestServer.class);
- public static final String SELF = NetworkUtil.getHostname();
- public static final String ENDPOINT_PREFIX = "onap/participantsim/v2/";
- private static int port;
- private static String httpPrefix;
- private static Main main;
-
- /**
- * Allocates a port for the server, writes a config file, and then starts Main.
- *
- * @throws Exception if an error occurs
- */
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- setUpBeforeClass(true);
- }
-
- /**
- * Allocates a port for the server, writes a config file, and then starts Main, if
- * specified.
- *
- * @param shouldStart {@code true} if Main should be started, {@code false} otherwise
- * @throws Exception if an error occurs
- */
- public static void setUpBeforeClass(boolean shouldStart) throws Exception {
- port = NetworkUtil.allocPort();
- httpPrefix = "http://localhost:" + port + "/";
-
- makeConfigFile();
- HttpServletServerFactoryInstance.getServerFactory().destroy();
- TopicEndpointManager.getManager().shutdown();
-
- if (shouldStart) {
- startMain();
- }
- }
-
- /**
- * Stops Main.
- */
- @AfterClass
- public static void teardownAfterClass() {
- try {
- stopMain();
-
- } catch (ControlLoopException exp) {
- LOGGER.error("cannot stop main", exp);
- }
- }
-
- /**
- * Set up.
- *
- * @throws Exception if an error occurs
- */
- @Before
- public void setUp() throws Exception {
- // restart, if not currently running
- if (main == null) {
- startMain();
- }
- }
-
- /**
- * Verifies that an endpoint appears within the swagger response.
- *
- * @param endpoint the endpoint of interest
- * @throws Exception if an error occurs
- */
- protected void testSwagger(final String endpoint) throws Exception {
- final Invocation.Builder invocationBuilder = sendFqeRequest(httpPrefix + "swagger.yaml", true);
- assertThat(invocationBuilder.get(String.class)).contains(ENDPOINT_PREFIX + endpoint + ":");
- }
-
- /**
- * Makes a parameter configuration file.
- *
- * @throws IOException if an error occurs writing the configuration file
- * @throws FileNotFoundException if an error occurs writing the configuration file
- *
- * @throws Exception if an error occurs
- */
- private static void makeConfigFile() throws FileNotFoundException, IOException {
- String json = CommonTestData.getParticipantParameterGroupAsString(port);
- File file = new File(String.format(CONFIG_FILE, port));
- file.deleteOnExit();
- try (FileOutputStream output = new FileOutputStream(file)) {
- output.write(json.getBytes(StandardCharsets.UTF_8));
- }
- }
-
- /**
- * Starts the "Main".
- *
- * @throws InterruptedException
- *
- * @throws Exception if an error occurs
- */
- protected static void startMain() throws InterruptedException {
- // make sure port is available
- if (NetworkUtil.isTcpPortOpen("localhost", port, 1, 1L)) {
- throw new IllegalStateException("port " + port + " is still in use");
- }
-
- final String[] configParameters = { "-c", CONFIG_FILE };
-
- main = new Main(configParameters);
-
- if (!NetworkUtil.isTcpPortOpen("localhost", port, 40, 250L)) {
- throw new IllegalStateException("server is not listening on port " + port);
- }
- }
-
- /**
- * Stops the "Main".
- *
- * @throws ControlLoopException
- *
- * @throws Exception if an error occurs
- */
- private static void stopMain() throws ControlLoopException {
- if (main != null) {
- main.shutdown();
- main = null;
- }
- }
-
- /**
- * Sends a request to an endpoint.
- *
- * @param endpoint the target endpoint
- * @return a request builder
- * @throws Exception if an error occurs
- */
- protected Invocation.Builder sendRequest(final String endpoint) throws Exception {
- return sendFqeRequest(httpPrefix + ENDPOINT_PREFIX + endpoint, true);
- }
-
- /**
- * Sends a request to an endpoint, without any authorization header.
- *
- * @param endpoint the target endpoint
- * @return a request builder
- * @throws Exception if an error occurs
- */
- protected Invocation.Builder sendNoAuthRequest(final String endpoint) throws Exception {
- return sendFqeRequest(httpPrefix + ENDPOINT_PREFIX + endpoint, false);
- }
-
- /**
- * Sends a request to a fully qualified endpoint.
- *
- * @param fullyQualifiedEndpoint the fully qualified target endpoint
- * @param includeAuth if authorization header should be included
- * @return a request builder
- * @throws Exception if an error occurs
- */
- protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth)
- throws Exception {
- final Client client = ClientBuilder.newBuilder().build();
- client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
- client.register(GsonMessageBodyHandler.class);
- if (includeAuth) {
- client.register(HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34"));
- }
- final WebTarget webTarget = client.target(fullyQualifiedEndpoint);
- return webTarget.request(MediaType.APPLICATION_JSON);
- }
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/RestControllerTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/RestControllerTest.java
deleted file mode 100644
index 1311eee35..000000000
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/RestControllerTest.java
+++ /dev/null
@@ -1,95 +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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.controlloop.participant.simulator.main.rest;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.UUID;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.onap.policy.clamp.controlloop.participant.simulator.simulation.SimulationHandler;
-import org.onap.policy.common.utils.services.Registry;
-
-public class RestControllerTest {
-
- private RestController ctlr;
- private ResponseBuilder bldr;
-
- /**
- * Setup before class, instantiate SimulationHandler.
- *
- */
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- Registry.newRegistry();
- Registry.register(SimulationHandler.class.getName(), Mockito.mock(SimulationHandler.class));
- }
-
- @AfterClass
- public static void teardownAfterClass() throws Exception {
- Registry.unregister(SimulationHandler.class.getName());
- }
-
- /**
- * set Up.
- */
- @Before
- public void setUp() {
- ctlr = new RestController();
- bldr = Response.status(Response.Status.OK);
- }
-
- @Test
- public void testProduces() {
- Produces annotation = RestController.class.getAnnotation(Produces.class);
- assertNotNull(annotation);
- assertThat(annotation.value()).contains(MediaType.APPLICATION_JSON)
- .contains(RestController.APPLICATION_YAML);
- }
-
- @Test
- public void testAddVersionControlHeaders() {
- Response resp = ctlr.addVersionControlHeaders(bldr).build();
- assertEquals("0", resp.getHeaderString(RestController.VERSION_MINOR_NAME));
- assertEquals("0", resp.getHeaderString(RestController.VERSION_PATCH_NAME));
- assertEquals("1.0.0", resp.getHeaderString(RestController.VERSION_LATEST_NAME));
- }
-
- @Test
- public void testAddLoggingHeaders_Null() {
- Response resp = ctlr.addLoggingHeaders(bldr, null).build();
- assertNotNull(resp.getHeaderString(RestController.REQUEST_ID_NAME));
- }
-
- @Test
- public void testAddLoggingHeaders_NonNull() {
- UUID uuid = UUID.randomUUID();
- Response resp = ctlr.addLoggingHeaders(bldr, uuid).build();
- assertEquals(uuid.toString(), resp.getHeaderString(RestController.REQUEST_ID_NAME));
- }
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
index 9c20ffe22..8aa40cbd5 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
@@ -25,13 +25,10 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileNotFoundException;
import java.time.Instant;
-import java.util.ArrayList;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
import java.util.Set;
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;
@@ -40,10 +37,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant
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.models.messages.dmaap.participant.ParticipantStateChange;
-import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.CommonTestData;
-import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.ParticipantSimulatorParameters;
-import org.onap.policy.clamp.controlloop.participant.simulator.simulation.SimulationProvider;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -64,24 +58,6 @@ public class TestListenerUtils {
private TestListenerUtils() {}
- @Getter
- private static ParticipantHandler participantHandler;
-
- /**
- * Method to initialize participantHandler.
- */
- public static void initParticipantHandler() {
-
- final ParticipantSimulatorParameters participantParameters = commonTestData.toObject(
- commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME),
- ParticipantSimulatorParameters.class);
-
- SimulationProvider simulationProvider =
- new SimulationProvider(participantParameters.getIntermediaryParameters());
-
- participantHandler = simulationProvider.getIntermediaryApi().getParticipantHandler();
- }
-
/**
* Method to create a controlLoop from a yaml file.
*
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestSimulationRestController.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestSimulationRestController.java
deleted file mode 100644
index 472b4beee..000000000
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestSimulationRestController.java
+++ /dev/null
@@ -1,186 +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.simulator.main.rest;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-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;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
-import org.onap.policy.clamp.controlloop.models.messages.rest.TypedSimpleResponse;
-import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener;
-import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.CommonTestData;
-import org.onap.policy.clamp.controlloop.participant.simulator.simulation.SimulationHandler;
-import org.onap.policy.clamp.controlloop.participant.simulator.simulation.SimulationProvider;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
-
-/**
- * Class to perform unit test of {@link TestSimulationRestController}.
- */
-public class TestSimulationRestController extends CommonParticipantRestServer {
-
- private static ControlLoopUpdateListener clUpdateListener;
- private static final String PARTICIPANTS_ENDPOINT = "participants";
- private static final String ELEMENTS_ENDPOINT = "elements";
- private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
- private static final String TOPIC = "my-topic";
- static CommonTestData commonTestData = new CommonTestData();
-
- /**
- * Setup before class.
- *
- */
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- CommonParticipantRestServer.setUpBeforeClass();
- clUpdateListener = new ControlLoopUpdateListener(
- SimulationHandler.getInstance()
- .getSimulationProvider()
- .getIntermediaryApi()
- .getParticipantHandler());
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg =
- TestListenerUtils.createControlLoopUpdateMsg();
- participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
- clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
- }
-
- @AfterClass
- public static void teardownAfterClass() {
- CommonParticipantRestServer.teardownAfterClass();
- }
-
- @Test
- public void testSwagger() throws Exception {
- super.testSwagger(ELEMENTS_ENDPOINT);
- }
-
- @Test
- public void testQuery_Unauthorized() throws Exception {
- Invocation.Builder invocationBuilder = super.sendNoAuthRequest(ELEMENTS_ENDPOINT);
- Response rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
- }
-
- @Test
- public void testQueryParticipants() throws Exception {
- Participant participant = new Participant();
- ToscaConceptIdentifier participantId = CommonTestData.getParticipantId();
- participant.setDefinition(participantId);
- participant.setName(participantId.getName());
- participant.setVersion(participantId.getVersion());
-
- // GET REST call for querying the participants
- Invocation.Builder invocationBuilder =
- super.sendRequest(PARTICIPANTS_ENDPOINT + "/" + participant.getKey().getName()
- + "/" + participant.getVersion());
-
- Response rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- List<Participant> returnValue = rawresp.readEntity(new GenericType<List<Participant>>() {});
- assertNotNull(returnValue);
- assertThat(returnValue).hasSize(1);
- // Verify the result of GET participants with what is stored
- assertEquals(participant.getDefinition(), returnValue.get(0).getDefinition());
- }
-
- @Test
- public void testQueryControlLoopElements() throws Exception {
- // GET REST call for querying the controlLoop elements
- Invocation.Builder invocationBuilder = super.sendRequest(ELEMENTS_ENDPOINT + "/"
- + "PMSHInstance0" + "/" + "1.0.0");
-
- Response rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- Map<UUID, ControlLoopElement> returnValue =
- rawresp.readEntity(new GenericType<Map<UUID, ControlLoopElement>>() {});
- assertNotNull(returnValue);
- // Verify the result of GET controlloop elements with what is stored
- assertThat(returnValue).hasSize(1);
- returnValue.values().forEach(element -> assertEquals("org.onap.PM_CDS_Blueprint",
- element.getDefinition().getName()));
- }
-
- @Test
- public void testUpdateParticipant() throws Exception {
- SimulationProvider provider = SimulationHandler.getInstance().getSimulationProvider();
- List<Participant> participants = provider.getParticipants(CommonTestData.getParticipantId().getName(),
- CommonTestData.getParticipantId().getVersion());
- assertEquals(ParticipantState.UNKNOWN, participants.get(0).getParticipantState());
- // Change the state of the participant to PASSIVE from UNKNOWN
- participants.get(0).setParticipantState(ParticipantState.PASSIVE);
- Entity<Participant> entParticipant = Entity.entity(participants.get(0), MediaType.APPLICATION_JSON);
-
- // PUT REST call for updating Participant
- Invocation.Builder invocationBuilder = sendRequest(PARTICIPANTS_ENDPOINT);
- Response rawresp = invocationBuilder.put(entParticipant);
- TypedSimpleResponse<Participant> resp = rawresp.readEntity(TypedSimpleResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- assertNotNull(resp.getResponse());
- // Verify the response and state returned by PUT REST call for updating participants
- assertThat(resp.toString()).contains("definition={name=org.onap.PM_CDS_Blueprint, version=1.0.0}");
- assertThat(resp.toString()).contains("participantState=PASSIVE");
- }
-
- @Test
- public void testUpdateControlLoopElement() throws Exception {
- ControlLoop controlLoop = TestListenerUtils.createControlLoop();
- SimulationProvider provider = SimulationHandler.getInstance().getSimulationProvider();
- Map<UUID, ControlLoopElement> controlLoopElements = provider.getControlLoopElements(
- controlLoop.getDefinition().getName(), controlLoop.getDefinition().getVersion());
-
- for (Map.Entry<UUID, ControlLoopElement> clElement : controlLoopElements.entrySet()) {
- // Check the initial state on the ControlLoopElement, which is UNINITIALISED
- assertEquals(ControlLoopOrderedState.UNINITIALISED, clElement.getValue().getOrderedState());
- // Change the state of the ControlLoopElement to PASSIVE from UNINITIALISED
- clElement.getValue().setOrderedState(ControlLoopOrderedState.PASSIVE);
- Entity<ControlLoopElement> entClElement = Entity.entity(clElement.getValue(), MediaType.APPLICATION_JSON);
-
- // PUT REST call for updating ControlLoopElement
- Invocation.Builder invocationBuilder = sendRequest(ELEMENTS_ENDPOINT);
- Response rawresp = invocationBuilder.put(entClElement);
- TypedSimpleResponse<ControlLoopElement> resp = rawresp.readEntity(TypedSimpleResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- assertNotNull(resp.getResponse());
- // Verify the response and state returned by PUT REST call for updating participants
- assertThat(resp.toString()).contains("definition={name=org.onap.PM_CDS_Blueprint, version=1.0.0}");
- assertThat(resp.toString()).contains("orderedState=PASSIVE");
- }
- }
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/startstop/TestMain.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/startstop/TestMain.java
deleted file mode 100644
index 5a5ad8931..000000000
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/startstop/TestMain.java
+++ /dev/null
@@ -1,117 +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.simulator.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.assertTrue;
-
-import org.junit.Test;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
-import org.onap.policy.common.utils.resources.MessageConstants;
-
-/**
- * Class to perform unit test of {@link Main}}.
- */
-public class TestMain {
-
- @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());
-
- 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_FileEmpty() {
- assertThatConfigFileThrownException("src/test/resources/parameters/EmptyParameters.json");
- }
-
- @Test
- public void testParticipant_NoParameters() {
- assertThatConfigFileThrownException("src/test/resources/parameters/NoParameters.json");
- }
-
- @Test
- public void testParticipant_InvalidParameters() {
- assertThatConfigFileThrownException("src/test/resources/parameters/InvalidParameters.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-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/startstop/TestParticipantSimulatorActivator.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/startstop/TestParticipantSimulatorActivator.java
deleted file mode 100644
index c695d5f24..000000000
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/startstop/TestParticipantSimulatorActivator.java
+++ /dev/null
@@ -1,89 +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.simulator.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.simulator.main.parameters.CommonTestData;
-import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.ParticipantSimulatorParameterHandler;
-import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.ParticipantSimulatorParameters;
-
-/**
- * Class to perform unit test of {@link ParticipantActivator}}.
- */
-public class TestParticipantSimulatorActivator {
-
- private static ParticipantSimulatorActivator activator;
-
- /**
- * Initializes an activator.
- *
- * @throws Exception if an error occurs
- */
- @BeforeClass
- public static void setUp() throws Exception {
- final String[] participantConfigParameters = { "-c", "src/test/resources/parameters/TestParameters.json"};
- final ParticipantSimulatorCommandLineArguments arguments =
- new ParticipantSimulatorCommandLineArguments(participantConfigParameters);
- final ParticipantSimulatorParameters parGroup =
- new ParticipantSimulatorParameterHandler().getParameters(arguments);
- activator = new ParticipantSimulatorActivator(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-simulator/src/test/resources/application_test.properties b/participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties
new file mode 100644
index 000000000..c31bb9d6b
--- /dev/null
+++ b/participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties
@@ -0,0 +1,7 @@
+spring.security.user.name=healthcheck
+spring.security.user.password=zb!XztG34
+
+server.servlet.context-path=/onap/participantsim
+server.error.path=/error
+
+participant.file=src/test/resources/parameters/TestParameters.json