summaryrefslogtreecommitdiffstats
path: root/participant
diff options
context:
space:
mode:
Diffstat (limited to 'participant')
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java3
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java2
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java5
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java75
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/RequestResponseLoggingFilter.java69
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java92
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java100
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java102
-rw-r--r--participant/participant-intermediary/src/test/resources/providers/TestControlLoops.json142
9 files changed, 405 insertions, 185 deletions
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
index 580bffa80..5e72d9479 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
@@ -34,7 +34,8 @@ import org.springframework.context.annotation.ComponentScan;
@ConfigurationPropertiesScan("org.onap.policy.clamp.controlloop.participant.simulator.main.parameters")
@ComponentScan({
"org.onap.policy.clamp.controlloop.participant.simulator",
- "org.onap.policy.clamp.controlloop.participant.intermediary"
+ "org.onap.policy.clamp.controlloop.participant.intermediary",
+ "org.onap.policy.clamp.controlloop.common.rest"
})
//@formatter:on
public class ParticipantSimulatorApplication {
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java
index d28ddf9dc..f2079edf5 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java
@@ -20,9 +20,9 @@
package org.onap.policy.clamp.controlloop.participant.simulator.config;
+import org.onap.policy.clamp.controlloop.common.rest.RequestResponseLoggingFilter;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.controlloop.participant.simulator.main.handler.ControlLoopElementHandler;
-import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.RequestResponseLoggingFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java
index 16da5cf7f..28dd2f9bc 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.controlloop.participant.simulator.config;
import java.util.List;
+import org.onap.policy.clamp.controlloop.common.rest.CoderHttpMesageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
@@ -32,8 +33,8 @@ public class YamlConfiguration implements WebMvcConfigurer {
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
- converters.add(new YamlHttpMessageConverter<>("yaml"));
- converters.add(new YamlHttpMessageConverter<>("json"));
+ converters.add(new CoderHttpMesageConverter<>("yaml"));
+ converters.add(new CoderHttpMesageConverter<>("json"));
StringHttpMessageConverter converter = new StringHttpMessageConverter();
converter.setSupportedMediaTypes(List.of(MediaType.TEXT_PLAIN));
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java
deleted file mode 100644
index d9a72ce10..000000000
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
- * ================================================================================
- * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.controlloop.participant.simulator.config;
-
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.nio.charset.StandardCharsets;
-import javax.ws.rs.core.Response;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
-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.coder.StandardYamlCoder;
-import org.springframework.http.HttpInputMessage;
-import org.springframework.http.HttpOutputMessage;
-import org.springframework.http.MediaType;
-import org.springframework.http.converter.AbstractHttpMessageConverter;
-import org.springframework.http.converter.HttpMessageNotReadableException;
-import org.springframework.http.converter.HttpMessageNotWritableException;
-
-public class YamlHttpMessageConverter<T> extends AbstractHttpMessageConverter<T> {
-
- private Coder coder;
-
- public YamlHttpMessageConverter(String type) {
- super(new MediaType("application", type, StandardCharsets.UTF_8));
- this.coder = "json".equals(type) ? new StandardCoder() : new StandardYamlCoder();
- }
-
- @Override
- protected boolean supports(Class<?> clazz) {
- return true;
- }
-
- @Override
- protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
- throws IOException, HttpMessageNotReadableException {
- try (var is = new InputStreamReader(inputMessage.getBody(), StandardCharsets.UTF_8)) {
- return coder.decode(is, clazz);
- } catch (CoderException e) {
- throw new ControlLoopRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e);
- }
- }
-
- @Override
- protected void writeInternal(T t, HttpOutputMessage outputMessage)
- throws IOException, HttpMessageNotWritableException {
- try (var writer = new OutputStreamWriter(outputMessage.getBody(), StandardCharsets.UTF_8)) {
- coder.encode(writer, t);
- } catch (CoderException e) {
- throw new ControlLoopRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e);
- }
- }
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/RequestResponseLoggingFilter.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/RequestResponseLoggingFilter.java
deleted file mode 100644
index 9626421e8..000000000
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/RequestResponseLoggingFilter.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
- * ================================================================================
- * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.controlloop.participant.simulator.main.rest;
-
-import java.io.IOException;
-import java.util.UUID;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Component;
-
-@Component
-@Order(2)
-public class RequestResponseLoggingFilter implements Filter {
-
- private static final String VERSION_MINOR_NAME = "X-MinorVersion";
- private static final String VERSION_PATCH_NAME = "X-PatchVersion";
- private static final String VERSION_LATEST_NAME = "X-LatestVersion";
- public static final String API_VERSION = "1.0.0";
- public static final String REQUEST_ID_NAME = "X-ONAP-RequestID";
-
- @Override
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
- throws IOException, ServletException {
-
-
- HttpServletResponse res = (HttpServletResponse) response;
- HttpServletRequest req = (HttpServletRequest) request;
-
- /*
- * Disabling sonar because of ONAP requires the request ID to be copied from the request
- * to the response, and just a simulator used during testing.
- */
- String requestId = req.getHeader(REQUEST_ID_NAME);
- res.addHeader(REQUEST_ID_NAME, requestId != null ? requestId : UUID.randomUUID().toString()); // NOSONAR
-
- res.addHeader(VERSION_MINOR_NAME, "0");
- res.addHeader(VERSION_PATCH_NAME, "0");
- res.addHeader(VERSION_LATEST_NAME, API_VERSION);
-
- chain.doFilter(request, response);
- }
-
-}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java
index 29387959b..e77dd69ee 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java
@@ -21,20 +21,29 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.Mockito.mock;
import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
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.ClElementStatistics;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.main.parameters.CommonTestData;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -45,14 +54,14 @@ class ControlLoopHandlerTest {
@Test
void controlLoopHandlerTest() {
- ControlLoopHandler clh = commonTestData.getMockControlLoopHandler();
+ var clh = commonTestData.getMockControlLoopHandler();
assertNotNull(clh.getControlLoops());
assertNotNull(clh.getControlLoopMap());
assertNotNull(clh.getElementsOnThisParticipant());
- UUID elementId1 = UUID.randomUUID();
- ControlLoopElement element = new ControlLoopElement();
+ var elementId1 = UUID.randomUUID();
+ var element = new ControlLoopElement();
element.setId(elementId1);
element.setDefinition(new ToscaConceptIdentifier(
"org.onap.policy.controlloop.PolicyControlLoopParticipant", "1.0.1"));
@@ -62,22 +71,21 @@ class ControlLoopHandlerTest {
ControlLoopElementListener listener = mock(ControlLoopElementListener.class);
clh.registerControlLoopElementListener(listener);
assertThat(clh.getListeners()).contains(listener);
-
}
@Test
void updateNullControlLoopHandlerTest() {
- UUID id = UUID.randomUUID();
+ var id = UUID.randomUUID();
- ControlLoopHandler clh = commonTestData.getMockControlLoopHandler();
+ var clh = commonTestData.getMockControlLoopHandler();
assertNull(clh.updateControlLoopElementState(null, null, ControlLoopOrderedState.UNINITIALISED,
ControlLoopState.PASSIVE));
assertNull(clh.updateControlLoopElementState(null, id, ControlLoopOrderedState.UNINITIALISED,
ControlLoopState.PASSIVE));
- ClElementStatistics clElementStatistics = new ClElementStatistics();
- ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier("defName", "0.0.1");
+ var clElementStatistics = new ClElementStatistics();
+ var controlLoopId = new ToscaConceptIdentifier("defName", "0.0.1");
clElementStatistics.setParticipantId(controlLoopId);
clElementStatistics.setControlLoopState(ControlLoopState.RUNNING);
clElementStatistics.setTimeStamp(Instant.now());
@@ -85,9 +93,77 @@ class ControlLoopHandlerTest {
clh.updateControlLoopElementStatistics(id, clElementStatistics);
assertNull(clh.updateControlLoopElementState(controlLoopId, id, ControlLoopOrderedState.UNINITIALISED,
ControlLoopState.PASSIVE));
+ }
+
+ @Test
+ void updateControlLoopHandlerTest() throws CoderException {
+ var uuid = UUID.randomUUID();
+ var id = CommonTestData.getParticipantId();
+
+ var clh = setTestControlLoopHandler(id, uuid);
+ var key = clh.getElementsOnThisParticipant().keySet().iterator().next();
+ var value = clh.getElementsOnThisParticipant().get(key);
+ assertEquals(ControlLoopState.UNINITIALISED, value.getState());
+ clh.updateControlLoopElementState(id, uuid, ControlLoopOrderedState.UNINITIALISED,
+ ControlLoopState.PASSIVE);
+ assertEquals(ControlLoopState.PASSIVE, value.getState());
+
+ var clElementStatistics = new ClElementStatistics();
+ clElementStatistics.setParticipantId(id);
+ clElementStatistics.setControlLoopState(ControlLoopState.RUNNING);
+ clElementStatistics.setTimeStamp(Instant.now());
+
+ assertNotEquals(uuid, value.getClElementStatistics().getId());
+ clh.updateControlLoopElementStatistics(uuid, clElementStatistics);
+ assertEquals(uuid, value.getClElementStatistics().getId());
+ }
+
+ @Test
+ void handleControlLoopUpdateExceptionTest() throws CoderException {
+ var uuid = UUID.randomUUID();
+ var id = CommonTestData.getParticipantId();
+
+ var stateChange = new ControlLoopStateChange();
+ stateChange.setControlLoopId(id);
+ stateChange.setParticipantId(id);
+ stateChange.setMessageId(uuid);
+ stateChange.setOrderedState(ControlLoopOrderedState.RUNNING);
+ stateChange.setCurrentState(ControlLoopState.UNINITIALISED);
+ stateChange.setTimestamp(Instant.ofEpochMilli(3000));
+
+ var clh = setTestControlLoopHandler(id, uuid);
+ clh.handleControlLoopStateChange(stateChange);
+ var newid = new ToscaConceptIdentifier("id", "1.2.3");
+ stateChange.setControlLoopId(newid);
+ stateChange.setParticipantId(newid);
+ assertDoesNotThrow(() -> clh.handleControlLoopStateChange(stateChange));
+
+ List<ControlLoopElementDefinition> clElementDefinitions = new ArrayList<>();
+ var cld = new ControlLoopElementDefinition();
+ cld.setClElementDefinitionId(id);
+ clElementDefinitions.add(cld);
+ var updateMsg = new ControlLoopUpdate();
+ updateMsg.setControlLoopId(id);
+ updateMsg.setMessageId(uuid);
+ updateMsg.setParticipantId(id);
+ updateMsg.setStartPhase(0);
+ assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, clElementDefinitions));
+ updateMsg.setStartPhase(1);
+ assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, clElementDefinitions));
+ }
+
+ private ControlLoopHandler setTestControlLoopHandler(ToscaConceptIdentifier id, UUID uuid) throws CoderException {
+ var clh = commonTestData.getMockControlLoopHandler();
+ var key = commonTestData.getTestControlLoopMap().keySet().iterator().next();
+ var value = commonTestData.getTestControlLoopMap().get(key);
+ clh.getControlLoopMap().put(key, value);
+ var keyElem = commonTestData.setControlLoopElementTest(uuid, id).keySet().iterator().next();
+ var valueElem = commonTestData.setControlLoopElementTest(uuid, id).get(keyElem);
+ clh.getElementsOnThisParticipant().put(keyElem, valueElem);
+ return clh;
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java
index 63db364ca..d00697521 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java
@@ -23,23 +23,28 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
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.assertFalse;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantAckMessage;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessage;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegisterAck;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.controlloop.participant.intermediary.main.parameters.CommonTestData;
-import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-
class ParticipantHandlerTest {
private CommonTestData commonTestData = new CommonTestData();
@@ -48,11 +53,11 @@ class ParticipantHandlerTest {
@Test
void mockParticipantHandlerTest() {
- ParticipantHandler participantHandler = commonTestData.getMockParticipantHandler();
+ var participantHandler = commonTestData.getMockParticipantHandler();
assertNull(participantHandler.getParticipant(null, null));
assertEquals("org.onap.PM_CDS_Blueprint 1.0.1", participantHandler.getParticipantId().toString());
- ToscaConceptIdentifier id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
assertEquals(id, participantHandler.getParticipantId());
assertEquals(id, participantHandler.getParticipantType());
assertThat(participantHandler.getClElementDefinitionCommonProperties(id)).isEmpty();
@@ -61,27 +66,27 @@ class ParticipantHandlerTest {
@Test
void handleUpdateTest() {
- ParticipantParameters parameters = CommonTestData.getParticipantParameters();
- ControlLoopHandler controlLoopHander = commonTestData.getMockControlLoopHandler();
- ParticipantMessagePublisher publisher = new ParticipantMessagePublisher();
- ParticipantHandler emptyParticipantHandler =
+ var parameters = CommonTestData.getParticipantParameters();
+ var controlLoopHander = commonTestData.getMockControlLoopHandler();
+ var publisher = new ParticipantMessagePublisher();
+ var emptyParticipantHandler =
new ParticipantHandler(parameters, publisher, controlLoopHander);
- ParticipantUpdate participantUpdateMsg = new ParticipantUpdate();
+ var participantUpdateMsg = new ParticipantUpdate();
assertThatThrownBy(() ->
emptyParticipantHandler.handleParticipantUpdate(participantUpdateMsg))
.isInstanceOf(RuntimeException.class);
- ParticipantHandler participantHandler = commonTestData.getMockParticipantHandler();
- ToscaConceptIdentifier id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var participantHandler = commonTestData.getMockParticipantHandler();
+
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
participantUpdateMsg.setControlLoopId(id);
participantUpdateMsg.setParticipantId(id);
participantUpdateMsg.setParticipantType(id);
participantUpdateMsg.setMessageId(UUID.randomUUID());
participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000));
-
- ParticipantStatus heartbeatF = participantHandler.makeHeartbeat(false);
+ var heartbeatF = participantHandler.makeHeartbeat(false);
assertEquals(id, heartbeatF.getParticipantId());
assertEquals(ParticipantState.UNKNOWN, heartbeatF.getParticipantStatistics().getState());
assertThat(heartbeatF.getControlLoopInfoList()).isEmpty();
@@ -89,30 +94,83 @@ class ParticipantHandlerTest {
participantHandler.handleParticipantUpdate(participantUpdateMsg);
assertThat(participantHandler.getClElementDefinitionCommonProperties(id)).isEmpty();
- ParticipantStatus heartbeatT = participantHandler.makeHeartbeat(true);
+ var heartbeatT = participantHandler.makeHeartbeat(true);
assertEquals(id, heartbeatT.getParticipantId());
assertEquals(ParticipantState.TERMINATED, heartbeatT.getParticipantStatistics().getState());
assertThat(heartbeatT.getParticipantDefinitionUpdates()).isNotEmpty();
assertEquals(id, heartbeatT.getParticipantDefinitionUpdates().get(0).getParticipantId());
+ var pum = setListParticipantDefinition(participantUpdateMsg);
+ participantHandler.handleParticipantUpdate(pum);
+ var heartbeatTAfterUpdate = participantHandler.makeHeartbeat(true);
+ assertEquals(id, heartbeatTAfterUpdate.getParticipantId());
+ assertEquals(ParticipantState.PASSIVE, heartbeatTAfterUpdate.getParticipantStatistics().getState());
+
+ }
+
+ private ParticipantUpdate setListParticipantDefinition(ParticipantUpdate participantUpdateMsg) {
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
+ var def = new ParticipantDefinition();
+ def.setParticipantId(id);
+ def.setParticipantType(id);
+ participantDefinitionUpdates.add(def);
+ participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates);
+ return participantUpdateMsg;
}
@Test
void handleParticipantTest() {
- ParticipantHandler participantHandler = commonTestData.getMockParticipantHandler();
- ToscaConceptIdentifier id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
- Participant p = participantHandler.getParticipant(id.getName(), id.getVersion());
+ var participantHandler = commonTestData.getMockParticipantHandler();
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var p = participantHandler.getParticipant(id.getName(), id.getVersion());
assertEquals(ParticipantState.UNKNOWN, p.getParticipantState());
participantHandler.updateParticipantState(id, ParticipantState.PASSIVE);
- Participant p2 = participantHandler.getParticipant(id.getName(), id.getVersion());
+ var p2 = participantHandler.getParticipant(id.getName(), id.getVersion());
assertEquals(ParticipantState.PASSIVE, p2.getParticipantState());
- ParticipantRegisterAck participantRegisterAckMsg = new ParticipantRegisterAck();
+ var participantRegisterAckMsg = new ParticipantRegisterAck();
participantRegisterAckMsg.setState(ParticipantState.TERMINATED);
participantHandler.handleParticipantRegisterAck(participantRegisterAckMsg);
assertEquals(ParticipantHealthStatus.HEALTHY, participantHandler.makeHeartbeat(false).getHealthStatus());
+ var emptyid = new ToscaConceptIdentifier("", ID_VERSION);
+ assertNull(participantHandler.updateParticipantState(emptyid, ParticipantState.PASSIVE));
+
+ var sameid = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var participant = participantHandler.updateParticipantState(sameid, ParticipantState.PASSIVE);
+ assertEquals(participant.getDefinition(), sameid);
+
+ }
+
+ @Test
+ void checkAppliesTo() {
+ var participantHandler = commonTestData.getMockParticipantHandler();
+ var participantAckMsg =
+ new ParticipantAckMessage(ParticipantMessageType.CONTROL_LOOP_UPDATE);
+ assertTrue(participantHandler.appliesTo(participantAckMsg));
+
+ var participantMsg =
+ new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATUS);
+ assertTrue(participantHandler.appliesTo(participantMsg));
+
+ var emptyid = new ToscaConceptIdentifier("", ID_VERSION);
+ participantMsg.setParticipantType(emptyid);
+ assertFalse(participantHandler.appliesTo(participantMsg));
+
+ }
+
+ @Test
+ void getControlLoopInfoListTest() throws CoderException {
+ var participantHandler = commonTestData.getParticipantHandlerControlLoops();
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ participantHandler.sendHeartbeat();
+ assertEquals(id, participantHandler.makeHeartbeat(false)
+ .getControlLoopInfoList()
+ .get(0)
+ .getControlLoopId());
+
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
index af88b5a8a..43f3c8e2b 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
@@ -20,18 +20,28 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.main.parameters;
+import java.io.File;
+import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import java.util.UUID;
import org.mockito.Mockito;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
+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.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregisterAck;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ControlLoopHandler;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.DummyParticipantParameters;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
-import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.utils.coder.Coder;
@@ -129,7 +139,7 @@ public class CommonTestData {
* @return topic parameters
*/
public static TopicParameters getTopicParams() {
- final TopicParameters topicParams = new TopicParameters();
+ final var topicParams = new TopicParameters();
topicParams.setTopic("POLICY-CLRUNTIME-PARTICIPANT");
topicParams.setTopicCommInfrastructure("dmaap");
topicParams.setServers(Arrays.asList("localhost"));
@@ -152,8 +162,7 @@ public class CommonTestData {
*/
private ParticipantMessagePublisher getParticipantMessagePublisher() {
synchronized (lockit) {
- ParticipantMessagePublisher participantMessagePublisher =
- new ParticipantMessagePublisher();
+ var participantMessagePublisher = new ParticipantMessagePublisher();
participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
return participantMessagePublisher;
}
@@ -176,12 +185,89 @@ public class CommonTestData {
* @return participant Handler
*/
public ParticipantHandler getMockParticipantHandler() {
- ParticipantParameters parameters = getParticipantParameters();
- ControlLoopHandler controlLoopHander = getMockControlLoopHandler();
- ParticipantMessagePublisher publisher = new ParticipantMessagePublisher();
+ var parameters = getParticipantParameters();
+ var controlLoopHandler = getMockControlLoopHandler();
+ var publisher = new ParticipantMessagePublisher();
publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
- ParticipantHandler participantHandler = new ParticipantHandler(parameters, publisher, controlLoopHander);
+ var participantHandler = new ParticipantHandler(parameters, publisher, controlLoopHandler);
return participantHandler;
}
+ /**
+ * Returns a mocked ParticipantHandler for test cases.
+ *
+ * @return participant Handler
+ *
+ * @throws CoderException if there is an error with .json file.
+ */
+ public ParticipantHandler getParticipantHandlerControlLoops() throws CoderException {
+ var controlLoopHandler = Mockito.mock(ControlLoopHandler.class);
+ Mockito.doReturn(getTestControlLoops()).when(controlLoopHandler).getControlLoops();
+ Mockito.doReturn(getTestControlLoopMap()).when(controlLoopHandler).getControlLoopMap();
+ var publisher = new ParticipantMessagePublisher();
+ publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
+ var parameters = getParticipantParameters();
+ var participantHandler = new ParticipantHandler(parameters, publisher, controlLoopHandler);
+ participantHandler.sendParticipantRegister();
+ participantHandler.handleParticipantStatusReq(null);
+ participantHandler.sendParticipantDeregister();
+ var participantDeregisterAckMsg = new ParticipantDeregisterAck();
+ participantDeregisterAckMsg.setResponseTo(UUID.randomUUID());
+ participantHandler.handleParticipantDeregisterAck(participantDeregisterAckMsg);
+ return participantHandler;
+ }
+
+ /**
+ * Returns a Map of ToscaConceptIdentifier and ControlLoop for test cases.
+ *
+ * @return controlLoopMap
+ *
+ * @throws CoderException if there is an error with .json file.
+ */
+ public Map<ToscaConceptIdentifier, ControlLoop> getTestControlLoopMap() throws CoderException {
+ var controlLoops = getTestControlLoops();
+ var controlLoop = controlLoops.getControlLoopList().get(1);
+ var id = getParticipantId();
+ Map<ToscaConceptIdentifier, ControlLoop> controlLoopMap = new LinkedHashMap<>();
+ controlLoopMap.put(id, controlLoop);
+ return controlLoopMap;
+ }
+
+ /**
+ * Returns List of ControlLoop for test cases.
+ *
+ * @return ControlLoops
+ *
+ * @throws CoderException if there is an error with .json file.
+ */
+ public ControlLoops getTestControlLoops() throws CoderException {
+ return new StandardCoder()
+ .decode(new File("src/test/resources/providers/TestControlLoops.json"), ControlLoops.class);
+ }
+
+ /**
+ * Returns a map for a elementsOnThisParticipant for test cases.
+ *
+ * @param uuid UUID and id ToscaConceptIdentifier
+ * @return a map suitable for elementsOnThisParticipant
+ */
+ public Map<UUID, ControlLoopElement> setControlLoopElementTest(UUID uuid, ToscaConceptIdentifier id) {
+ var clElement = new ControlLoopElement();
+ clElement.setId(uuid);
+ clElement.setParticipantId(id);
+ clElement.setDefinition(id);
+ clElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+
+ var clElementStatistics = new ClElementStatistics();
+ clElementStatistics.setParticipantId(id);
+ clElementStatistics.setControlLoopState(ControlLoopState.UNINITIALISED);
+ clElementStatistics.setTimeStamp(Instant.now());
+
+ clElement.setClElementStatistics(clElementStatistics);
+
+ Map<UUID, ControlLoopElement> elementsOnThisParticipant = new LinkedHashMap<>();
+ elementsOnThisParticipant.put(uuid, clElement);
+ return elementsOnThisParticipant;
+ }
+
}
diff --git a/participant/participant-intermediary/src/test/resources/providers/TestControlLoops.json b/participant/participant-intermediary/src/test/resources/providers/TestControlLoops.json
new file mode 100644
index 000000000..fedda9600
--- /dev/null
+++ b/participant/participant-intermediary/src/test/resources/providers/TestControlLoops.json
@@ -0,0 +1,142 @@
+{
+ "controlLoopList": [
+ {
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.0.0"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "elements": {
+ "709c62b3-8918-41b9-a747-e21eb79c6c20": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c20",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant",
+ "version": "2.3.4"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "DCAE Control Loop Element for the PMSH instance 0 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c21": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c21",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "Monitoring Policy Control Loop Element for the PMSH instance 0 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c22": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c22",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "Operational Policy Control Loop Element for the PMSH instance 0 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c23": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c23",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant",
+ "version": "2.2.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "CDS Control Loop Element for the PMSH instance 0 control loop"
+ }
+ },
+ "name": "PMSHInstance0",
+ "version": "1.0.1",
+ "description": "PMSH control loop instance 0"
+ },
+ {
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.0.0"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "elements": {
+ "709c62b3-8918-41b9-a747-e21eb79c6c24": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c24",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant",
+ "version": "2.3.4"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "DCAE Control Loop Element for the PMSH instance 1 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c25": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c25",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "Monitoring Policy Control Loop Element for the PMSH instance 1 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c26": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c26",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "Operational Policy Control Loop Element for the PMSH instance 1 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c27": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c27",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant",
+ "version": "2.2.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "CDS Control Loop Element for the PMSH instance 1 control loop"
+ }
+ },
+ "name": "PMSHInstance1",
+ "version": "1.0.1",
+ "description": "PMSH control loop instance 1"
+ }
+ ]
+}