summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2020-07-24 09:46:36 +0100
committerwaynedunican <wayne.dunican@est.tech>2020-07-27 13:28:30 +0100
commitb2e2d5f8daeefb08873d11de44cb4cfe7cfab03a (patch)
treebe45f7f5bf18fe4a1a1b1b430a4089a1d1a316c2 /plugins/plugins-event
parentba58c5bad6075f7bc902de80190cc6770a209bb6 (diff)
SONAR assertions apex-pdp
Ensure assertions are present in test cases Issue-ID: POLICY-2706 Change-Id: I3673a7668564401d2136450b0bdd7a013605dd7c Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'plugins/plugins-event')
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java30
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java28
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java4
3 files changed, 37 insertions, 25 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java
index a032af650..8591d0470 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@
package org.onap.policy.apex.plugins.event.carrier.jms;
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -58,22 +60,24 @@ public class ApexJmsConsumerTest {
apexJmsProducer = new ApexJmsProducer();
}
- @Test(expected = ApexEventException.class)
+ @Test
public void testInitWithNonJmsCarrierTechnologyParameters() throws ApexEventException {
consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {});
- apexJmsConsumer.init("TestApexJmsConsumer", consumerParameters, incomingEventReceiver);
+ assertThatThrownBy(() -> apexJmsConsumer.init("TestApexJmsConsumer", consumerParameters, incomingEventReceiver))
+ .isInstanceOf(ApexEventException.class);
}
- @Test(expected = ApexEventException.class)
+ @Test
public void testInitWithJmsCarrierTechnologyParameters() throws ApexEventException {
jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
- apexJmsConsumer.init("TestApexJmsConsumer", consumerParameters, incomingEventReceiver);
+ assertThatThrownBy(() -> apexJmsConsumer.init("TestApexJmsConsumer", consumerParameters, incomingEventReceiver))
+ .isInstanceOf(ApexEventException.class);
}
@Test
public void testStart() {
- apexJmsConsumer.start();
+ assertThatCode(apexJmsConsumer::start).doesNotThrowAnyException();
}
@Test
@@ -94,20 +98,20 @@ public class ApexJmsConsumerTest {
assertNotNull(apexJmsConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
}
- @Test(expected = ApexEventRuntimeException.class)
+ @Test
public void testRun() {
- apexJmsConsumer.run();
-
+ assertThatThrownBy(apexJmsConsumer::run).isInstanceOf(ApexEventRuntimeException.class);
}
- @Test(expected = ApexEventRuntimeException.class)
+ @Test
public void testOnMessage() {
Message jmsMessage = null;
- apexJmsConsumer.onMessage(jmsMessage);
+ assertThatThrownBy(() -> apexJmsConsumer.onMessage(jmsMessage))
+ .isInstanceOf(ApexEventRuntimeException.class);
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testStop() {
- apexJmsConsumer.stop();
+ assertThatThrownBy(apexJmsConsumer::stop).isInstanceOf(NullPointerException.class);
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java
index 34ffc4c75..3783c1ba3 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@
package org.onap.policy.apex.plugins.event.carrier.jms;
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -61,17 +63,19 @@ public class ApexJmsProducerTest {
apexJmsProducer = new ApexJmsProducer();
}
- @Test(expected = ApexEventException.class)
- public void testInitWithNonJmsCarrierTechnologyParameters() throws ApexEventException {
+ @Test
+ public void testInitWithNonJmsCarrierTechnologyParameters() {
producerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {});
- apexJmsProducer.init("TestApexJmsProducer", producerParameters);
+ assertThatThrownBy(() -> apexJmsProducer.init("TestApexJmsProducer", producerParameters))
+ .isInstanceOf(ApexEventException.class);
}
- @Test(expected = ApexEventException.class)
+ @Test
public void testInitWithJmsCarrierTechnologyParameters() throws ApexEventException {
jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
producerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
- apexJmsProducer.init("TestApexJmsProducer", producerParameters);
+ assertThatThrownBy(() -> apexJmsProducer.init("TestApexJmsProducer", producerParameters))
+ .isInstanceOf(ApexEventException.class);
}
@Test
@@ -92,7 +96,7 @@ public class ApexJmsProducerTest {
assertNotNull(apexJmsProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testSendEvent() throws ApexEventException {
producerParameters.setCarrierTechnologyParameters(new JmsCarrierTechnologyParameters() {});
synchronousEventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS,
@@ -101,21 +105,23 @@ public class ApexJmsProducerTest {
synchronousEventCache);
ApexEvent apexEvent = new ApexEvent("testEvent", "testVersion", "testNameSpace",
"testSource", "testTarget");
- apexJmsProducer.sendEvent(1000L, null, "TestApexJmsProducer", apexEvent);
+ assertThatThrownBy(() -> apexJmsProducer.sendEvent(1000L, null, "TestApexJmsProducer", apexEvent))
+ .isInstanceOf(NullPointerException.class);
}
- @Test(expected = ApexEventRuntimeException.class)
+ @Test
public void testSendEventWithNonSerializableObject() throws ApexEventException {
producerParameters.setCarrierTechnologyParameters(new JmsCarrierTechnologyParameters() {});
synchronousEventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS,
apexJmsConsumer, apexJmsProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT);
apexJmsProducer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS,
synchronousEventCache);
- apexJmsProducer.sendEvent(-1L, null, "TestApexJmsProducer", new ApexJmsProducerTest());
+ assertThatThrownBy(() -> apexJmsProducer.sendEvent(-1L, null, "TestApexJmsProducer", new ApexJmsProducerTest()))
+ .isInstanceOf(ApexEventRuntimeException.class);
}
@Test
public void testStop() {
- apexJmsProducer.stop();
+ assertThatCode(apexJmsProducer::stop).doesNotThrowAnyException();
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java
index bbebbc3b8..edb4a1a7b 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +21,7 @@
package org.onap.policy.apex.plugins.event.carrier.kafka;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -57,7 +59,7 @@ public class ApexKafkaConsumerTest {
@Test
public void testStart() {
- apexKafkaConsumer.start();
+ assertThatCode(apexKafkaConsumer::start).doesNotThrowAnyException();
}
@Test