summaryrefslogtreecommitdiffstats
path: root/participant
diff options
context:
space:
mode:
Diffstat (limited to 'participant')
-rw-r--r--participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java35
-rw-r--r--participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/service/BridgeServiceTest.java14
-rw-r--r--participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/service/StarterServiceTest.java11
3 files changed, 56 insertions, 4 deletions
diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java
index 37d378b7a..dd651decc 100644
--- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java
+++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.acm.element.handler;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -29,6 +30,7 @@ import java.util.List;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.element.main.parameters.AcElement;
import org.onap.policy.clamp.acm.element.service.ElementService;
+import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
import org.onap.policy.clamp.models.acm.messages.dmaap.element.ElementStatus;
import org.onap.policy.clamp.models.acm.messages.rest.element.ElementConfig;
import org.onap.policy.clamp.models.acm.messages.rest.element.ElementType;
@@ -38,6 +40,7 @@ class MessageHandlerTest {
private static final String NAME = "name";
private static final String VERSION = "1.0.0";
+ private static final String TOPIC = "topic";
@Test
void testAppliesTo() {
@@ -49,6 +52,30 @@ class MessageHandlerTest {
}
@Test
+ void testWrongConf() {
+ var starter = createMockElementService(ElementType.STARTER);
+ var bridge = createMockElementService(ElementType.BRIDGE);
+ var messageHandler = createMessageHandler(List.of(starter, bridge));
+
+ assertThatThrownBy(() -> messageHandler.getActiveService())
+ .isInstanceOf(AutomationCompositionRuntimeException.class);
+
+ var elementConfig = new ElementConfig();
+ elementConfig.setElementType(ElementType.STARTER);
+
+ assertThatThrownBy(() -> messageHandler.update(elementConfig))
+ .isInstanceOf(AutomationCompositionRuntimeException.class);
+
+ messageHandler.active(elementConfig);
+
+ var newElementConfig = new ElementConfig();
+ newElementConfig.setElementType(ElementType.BRIDGE);
+
+ assertThatThrownBy(() -> messageHandler.update(newElementConfig))
+ .isInstanceOf(AutomationCompositionRuntimeException.class);
+ }
+
+ @Test
void testStarter() {
var starter = createMockElementService(ElementType.STARTER);
var bridge = createMockElementService(ElementType.BRIDGE);
@@ -81,7 +108,9 @@ class MessageHandlerTest {
verify(bridge).update(elementConfig);
var message = new ElementStatus();
- messageHandler.handleMessage(message);
+ message.setElementId(new ToscaConceptIdentifier(NAME, VERSION));
+ var listener = new MessageListener(messageHandler);
+ listener.onTopicEvent(null, TOPIC, null, message);
verify(bridge).handleMessage(message);
messageHandler.deactivateElement();
}
@@ -100,7 +129,9 @@ class MessageHandlerTest {
assertThat(messageHandler.getActiveService()).isEqualTo(sink);
var message = new ElementStatus();
- messageHandler.handleMessage(message);
+ message.setElementId(new ToscaConceptIdentifier(NAME, VERSION));
+ var listener = new MessageListener(messageHandler);
+ listener.onTopicEvent(null, TOPIC, null, message);
verify(sink).handleMessage(message);
messageHandler.deactivateElement();
}
diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/service/BridgeServiceTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/service/BridgeServiceTest.java
index aae8d5893..0180cbba9 100644
--- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/service/BridgeServiceTest.java
+++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/service/BridgeServiceTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.acm.element.service;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -28,6 +29,7 @@ import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.element.handler.MessagePublisher;
import org.onap.policy.clamp.acm.element.main.parameters.AcElement;
+import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
import org.onap.policy.clamp.models.acm.messages.dmaap.element.ElementMessage;
import org.onap.policy.clamp.models.acm.messages.dmaap.element.ElementStatus;
import org.onap.policy.clamp.models.acm.messages.rest.element.ElementConfig;
@@ -53,4 +55,16 @@ class BridgeServiceTest {
bridgeService.handleMessage(new ElementStatus());
verify(messagePublisher).publishMsg(any(ElementMessage.class));
}
+
+ @Test
+ void testWrongConf() {
+ var acElement = new AcElement();
+ acElement.setElementId(new ToscaConceptIdentifier("onap.policy.clamp.ac.element1", "1.0.0"));
+
+ var messagePublisher = new MessagePublisher();
+ var bridgeService = new BridgeService(messagePublisher, acElement);
+ var elementStatus = new ElementStatus();
+ assertThatThrownBy(() -> bridgeService.handleMessage(elementStatus))
+ .isInstanceOf(AutomationCompositionRuntimeException.class);
+ }
}
diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/service/StarterServiceTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/service/StarterServiceTest.java
index 28af70de7..97d808830 100644
--- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/service/StarterServiceTest.java
+++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/service/StarterServiceTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.acm.element.service;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
@@ -32,6 +33,7 @@ import org.onap.policy.clamp.acm.element.main.parameters.AcElement;
import org.onap.policy.clamp.models.acm.messages.dmaap.element.ElementMessage;
import org.onap.policy.clamp.models.acm.messages.rest.element.ElementConfig;
import org.onap.policy.clamp.models.acm.messages.rest.element.ElementType;
+import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class StarterServiceTest {
@@ -49,10 +51,15 @@ class StarterServiceTest {
var elementConfig = new ElementConfig();
elementConfig.setTimerMs(100);
elementConfig.setReceiverId(new ToscaConceptIdentifier("onap.policy.clamp.ac.element2", "1.0.0"));
+
+ assertThatThrownBy(() -> starterService.update(elementConfig)).isInstanceOf(PfModelRuntimeException.class);
+
starterService.active(elementConfig);
- verify(messagePublisher, timeout(200).atLeastOnce()).publishMsg(any(ElementMessage.class));
+ verify(messagePublisher, timeout(500).atLeastOnce()).publishMsg(any(ElementMessage.class));
+
+ assertThatThrownBy(() -> starterService.active(elementConfig)).isInstanceOf(PfModelRuntimeException.class);
+
starterService.deactivate();
}
}
-
}