summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2020-07-10 08:25:22 +0100
committerwaynedunican <wayne.dunican@est.tech>2020-07-15 13:42:21 +0100
commitb8e3df6f43e46159c210ac7d1ec6983871d52ea5 (patch)
tree4992a599861db084882ad6d881ed011dd9569aaa /plugins/plugins-event
parent592e04f6301dd38ae48d38501cc251fc3d5ad2fb (diff)
Replaced try/catch blocks with assertj - apex-pdp
Removed try/catch blocks in apex-pdp with assertj assertions Part IV Issue-ID: POLICY-2451 Change-Id: I4b6accb9f944195db9ccf8a5de165b169301ac7f 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-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java52
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java50
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java33
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java11
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java122
5 files changed, 75 insertions, 193 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
index ea5e80161..e506513a8 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.apex.plugins.event.carrier.restclient;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -76,27 +77,19 @@ public class ApexRestClientConusmerTest {
EventHandlerParameters consumerParameters = new EventHandlerParameters();
SupportApexEventReceiver incomingEventReceiver = new SupportApexEventReceiver();
- try {
- arcc.init("RestClientConsumer", consumerParameters, incomingEventReceiver);
- fail("test should throw an exception here");
- } catch (ApexEventException e) {
- assertEquals(
- "specified consumer properties are not applicable to REST client consumer (RestClientConsumer)",
- e.getMessage());
- }
+ assertThatThrownBy(() -> arcc.init("RestClientConsumer", consumerParameters, incomingEventReceiver))
+ .hasMessageContaining("specified consumer properties are not applicable to REST client"
+ + " consumer (RestClientConsumer)");
RestClientCarrierTechnologyParameters rcctp = new RestClientCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(rcctp);
rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.DELETE);
- try {
+ assertThatThrownBy(() -> {
arcc.init("RestClientConsumer", consumerParameters, incomingEventReceiver);
- assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.GET, rcctp.getHttpMethod());
- fail("test should throw an exception here");
- } catch (ApexEventException e) {
- assertEquals("specified HTTP method of \"DELETE\" is invalid, only HTTP method \"GET\" is supported "
- + "for event reception on REST client consumer (RestClientConsumer)", e.getMessage());
- }
+ }).hasMessageContaining("specified HTTP method of \"DELETE\" is invalid, only HTTP method \"GET\" is "
+ + "supported for event reception on REST client consumer (RestClientConsumer)");
+ assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.DELETE, rcctp.getHttpMethod());
rcctp.setHttpMethod(null);
rcctp.setHttpCodeFilter("zzz");
@@ -174,7 +167,7 @@ public class ApexRestClientConusmerTest {
}
@Test
- public void testApexRestClientConsumerJsonError() {
+ public void testApexRestClientConsumerJsonError() throws ApexEventException {
MockitoAnnotations.initMocks(this);
ApexRestClientConsumer arcc = new ApexRestClientConsumer();
@@ -186,18 +179,13 @@ public class ApexRestClientConusmerTest {
consumerParameters.setCarrierTechnologyParameters(rcctp);
rcctp.setHttpCodeFilter("[1-5][0][0-5]");
- try {
- arcc.init("RestClientConsumer", consumerParameters, incomingEventReceiver);
- assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.GET, rcctp.getHttpMethod());
-
- assertEquals("RestClientConsumer", arcc.getName());
+ arcc.init("RestClientConsumer", consumerParameters, incomingEventReceiver);
+ assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.GET, rcctp.getHttpMethod());
+ assertEquals("RestClientConsumer", arcc.getName());
- arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
+ arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
- assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
- } catch (ApexEventException e) {
- fail("test should not throw an exception");
- }
+ assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
rcctp.setUrl("http://some.place.that.does.not/exist");
Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus();
@@ -341,14 +329,8 @@ public class ApexRestClientConusmerTest {
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
- try {
- // We have not set the URL, this test should not receive any events
- arcc.start();
- await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
- arcc.stop();
- } catch (Exception e) {
- // test invalid status code
- assertEquals("received an invalid status code \"200\"", e.getMessage());
- }
+ arcc.start();
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
+ arcc.stop();
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
index 0ee8fe6ad..a4ef6e38e 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
@@ -21,9 +21,9 @@
package org.onap.policy.apex.plugins.event.carrier.restclient;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
import java.util.Properties;
import javax.ws.rs.client.Client;
@@ -64,29 +64,18 @@ public class ApexRestClientProducerTest {
assertNotNull(arcp);
EventHandlerParameters producerParameters = new EventHandlerParameters();
- try {
- arcp.init("RestClientProducer", producerParameters);
- fail("test should throw an exception here");
- } catch (ApexEventException e) {
- assertEquals(
- "specified producer properties are not applicable to REST client producer (RestClientProducer)",
- e.getMessage());
- }
+ assertThatThrownBy(() -> arcp.init("RestClientProducer", producerParameters))
+ .hasMessage("specified producer properties are not applicable to REST client producer"
+ + " (RestClientProducer)");
RestClientCarrierTechnologyParameters rcctp = new RestClientCarrierTechnologyParameters();
producerParameters.setCarrierTechnologyParameters(rcctp);
rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.DELETE);
- try {
- arcp.init("RestClientConsumer", producerParameters);
- assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.GET, rcctp.getHttpMethod());
- fail("test should throw an exception here");
- } catch (ApexEventException e) {
- assertEquals(
- "specified HTTP method of \"DELETE\" is invalid, only HTTP methods \"POST\" and \"PUT\" "
- + "are supported for event sending on REST client producer (RestClientConsumer)",
- e.getMessage());
- }
+ assertThatThrownBy(() -> arcp.init("RestClientConsumer", producerParameters))
+ .hasMessage("specified HTTP method of \"DELETE\" is invalid, only HTTP methods \"POST\""
+ + " and \"PUT\" are supported for event sending on REST client producer (RestClientConsumer)");
+ assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.DELETE, rcctp.getHttpMethod());
rcctp.setHttpMethod(null);
arcp.init("RestClientConsumer", producerParameters);
assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.POST, rcctp.getHttpMethod());
@@ -168,15 +157,12 @@ public class ApexRestClientProducerTest {
rcctp.setUrl("http://some.place2.that.{key}.not/{tag}and.again.{tag}");
Properties properties = new Properties();
properties.put("tag", "exist");
- try {
+ assertThatThrownBy(() -> {
arcp.sendEvent(123, properties, "EventName", "This is an Event");
arcp.stop();
- fail("test should throw an exception");
- } catch (Exception e) {
- assertEquals("key \"key\" specified on url "
- + "\"http://some.place2.that.{key}.not/{tag}and.again.{tag}\" not found "
- + "in execution properties passed by the current policy", e.getMessage());
- }
+ }).hasMessageContaining("key \"key\" specified on url "
+ + "\"http://some.place2.that.{key}.not/{tag}and.again.{tag}\" not found "
+ + "in execution properties passed by the current policy");
}
@Test
@@ -303,14 +289,8 @@ public class ApexRestClientProducerTest {
Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl());
arcp.setClient(httpClientMock);
- try {
- arcp.sendEvent(123, null, "EventName", "This is an Event");
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals(
- "send of event to URL \"http://some.place.that.does.not/exist\" using HTTP \"POST\" "
- + "failed with status code 400 and message \"null\", event:\n" + "This is an Event",
- e.getMessage());
- }
+ assertThatThrownBy(() -> arcp.sendEvent(123, null, "EventName", "This is an Event"))
+ .hasMessageContaining("send of event to URL \"http://some.place.that.does.not/exist\" using HTTP \"POST\" "
+ + "failed with status code 400 and message \"null\", event:\n" + "This is an Event");
}
} \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java
index 42a9c0f73..f704ad3ec 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java
@@ -22,10 +22,10 @@
package org.onap.policy.apex.plugins.event.carrier.restclient;
import static org.assertj.core.api.Assertions.assertThatCode;
+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.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Set;
import org.junit.Test;
@@ -45,13 +45,8 @@ public class RestClientCarrierTechnologyParametersTest {
arguments.setConfigurationFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderBadList.json");
arguments.setRelativeFileRoot(".");
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (ParameterException pe) {
- assertTrue(pe.getMessage().contains("HTTP header array entry is null\n parameter"));
- assertTrue(pe.getMessage().trim().endsWith("HTTP header array entry is null"));
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageContaining("HTTP header array entry is null\n parameter");
}
@Test
@@ -60,15 +55,9 @@ public class RestClientCarrierTechnologyParametersTest {
arguments.setConfigurationFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderNotKvPairs.json");
arguments.setRelativeFileRoot(".");
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (ParameterException pe) {
- assertTrue(pe.getMessage()
- .contains("HTTP header array entries must have one key and one value: [aaa, bbb, ccc]"));
- assertTrue(pe.getMessage().trim()
- .endsWith("HTTP header array entries must have one key and one value: [aaa]"));
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageContaining("HTTP header array entries must have one key and one value: [aaa, bbb, ccc]")
+ .hasMessageEndingWith("HTTP header array entries must have one key and one value: [aaa]\n");
}
@Test
@@ -77,13 +66,9 @@ public class RestClientCarrierTechnologyParametersTest {
arguments.setConfigurationFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderNulls.json");
arguments.setRelativeFileRoot(".");
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (ParameterException pe) {
- assertTrue(pe.getMessage().contains("HTTP header key is null or blank: [null, bbb]"));
- assertTrue(pe.getMessage().trim().endsWith("HTTP header value is null or blank: [ccc, null]"));
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageContaining("HTTP header key is null or blank: [null, bbb]")
+ .hasMessageEndingWith("HTTP header value is null or blank: [ccc, null]\n");
}
@Test
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java
index 3d620ebf4..2fbae65e4 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java
@@ -21,8 +21,8 @@
package org.onap.policy.apex.plugins.event.protocol.yaml;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
@@ -215,13 +215,8 @@ public class YamlEventProtocolTest {
*/
@Test
public void testYamlProcessing() throws ApexEventException, IOException {
- try {
- testYamlDecodeEncode("TestEvent0", 1, 0, "Empty0");
- fail("test should fail here");
- } catch (ApexEventException e) {
- assertEquals("event processing failed, event is null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> testYamlDecodeEncode("TestEvent0", 1, 0, "Empty0"))
+ .hasMessage("event processing failed, event is null");
testYamlDecodeEncode("TestEvent0", 1, 0, "Empty1");
testYamlDecodeEncode("TestEvent1", 1, 1, "Collection0");
testYamlDecodeEncode("TestEvent2", 1, 3, "Collection1");
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java
index 6f82c7dfd..398bddb16 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. 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,9 +21,9 @@
package org.onap.policy.apex.plugins.event.protocol.yaml;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.List;
@@ -41,7 +42,6 @@ import org.onap.policy.apex.model.eventmodel.concepts.AxEvents;
import org.onap.policy.apex.model.eventmodel.concepts.AxField;
import org.onap.policy.apex.service.engine.event.ApexEvent;
import org.onap.policy.apex.service.engine.event.ApexEventException;
-import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
import org.onap.policy.common.parameters.ParameterService;
/**
@@ -112,52 +112,22 @@ public class YamlPluginStabilityTest {
public void testStability() throws ApexEventException {
Apex2YamlEventConverter converter = new Apex2YamlEventConverter();
- try {
- converter.init(null);
- fail("this test should throw an exception");
- } catch (ApexEventRuntimeException e) {
- assertEquals("specified consumer properties are not applicable to the YAML event protocol", e.getMessage());
- }
-
+ assertThatThrownBy(() -> converter.init(null))
+ .hasMessage("specified consumer properties are not applicable to the YAML event protocol");
YamlEventProtocolParameters pars = new YamlEventProtocolParameters();
converter.init(pars);
- try {
- converter.toApexEvent("NonExistantEvent", "");
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("Failed to unmarshal YAML event: an event definition for an event named \"NonExistantEvent\"",
- e.getMessage().substring(0, 89));
- }
-
- try {
- converter.toApexEvent("TestEvent", null);
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("event processing failed, event is null", e.getMessage());
- }
-
- try {
- converter.toApexEvent("TestEvent", 1);
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("error converting event \"1\" to a string", e.getMessage());
- }
-
- try {
- converter.toApexEvent("TestEvent", "");
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertTrue(e.getMessage().contains("Field \"doubleValue\" is missing"));
- }
-
- try {
- converter.fromApexEvent(null);
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("event processing failed, Apex event is null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> converter.toApexEvent("NonExistantEvent", ""))
+ .hasMessageContaining("Failed to unmarshal YAML event: an event definition for an event named "
+ + "\"NonExistantEvent\"");
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", null))
+ .hasMessage("event processing failed, event is null");
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", 1))
+ .hasMessage("error converting event \"1\" to a string");
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", ""))
+ .hasMessageContaining("Field \"doubleValue\" is missing");
+ assertThatThrownBy(() -> converter.fromApexEvent(null))
+ .hasMessage("event processing failed, Apex event is null");
ApexEvent apexEvent = new ApexEvent(testEvent.getKey().getName(), testEvent.getKey().getVersion(),
testEvent.getNameSpace(), testEvent.getSource(), testEvent.getTarget());
apexEvent.put("doubleValue", 123.45);
@@ -169,31 +139,15 @@ public class YamlPluginStabilityTest {
assertTrue(yamlString.contains("my wonderful exception message"));
apexEvent.remove("intValue");
- try {
- yamlString = (String) converter.fromApexEvent(apexEvent);
- fail("this test should throw an exception");
- } catch (ApexEventRuntimeException e) {
- assertEquals("error parsing TestEvent:0.0.1 event to Json. Field \"intValue\" is missing",
- e.getMessage().substring(0, 72));
- }
-
- try {
- converter.toApexEvent(null, "");
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("Failed to unmarshal YAML event: event received without mandatory parameter \"name\"",
- e.getMessage().substring(0, 81));
- }
-
+ assertThatThrownBy(() -> converter.fromApexEvent(apexEvent))
+ .hasMessageContaining("error parsing TestEvent:0.0.1 event to Json. Field \"intValue\" is missing");
+ assertThatThrownBy(() -> converter.toApexEvent(null, ""))
+ .hasMessageContaining("Failed to unmarshal YAML event: event received without mandatory parameter"
+ + " \"name\"");
pars.setNameAlias("TheNameField");
- try {
- converter.toApexEvent(null, "");
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("Failed to unmarshal YAML event: event received without mandatory parameter \"name\"",
- e.getMessage().substring(0, 81));
- }
-
+ assertThatThrownBy(() -> converter.toApexEvent(null, ""))
+ .hasMessageContaining("Failed to unmarshal YAML event: event received without mandatory parameter"
+ + " \"name\"");
apexEvent.put("intValue", 123);
apexEvent.remove("stringValue");
@@ -228,14 +182,9 @@ public class YamlPluginStabilityTest {
yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: org.some.other.namespace";
pars.setVersionAlias(null);
pars.setNameSpaceAlias("stringValue");
- try {
- converter.toApexEvent("TestEvent", yamlInputString);
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("Failed to unmarshal YAML event: namespace \"org.some.other.namespace\" on event",
- e.getMessage().substring(0, 77));
- }
-
+ final String yamlInputStringCopy = yamlInputString;
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", yamlInputStringCopy))
+ .hasMessageContaining("Failed to unmarshal YAML event: namespace \"org.some.other.namespace\" on event");
yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n"
+ "stringValue: org.onap.policy.apex.plugins.event.protocol.yaml";
eventList = converter.toApexEvent("TestEvent", yamlInputString);
@@ -257,21 +206,12 @@ public class YamlPluginStabilityTest {
yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: MyString";
pars.setSourceAlias(null);
pars.setTargetAlias("intValue");
- try {
- converter.toApexEvent("TestEvent", yamlInputString);
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("Failed to unmarshal YAML event: field \"target\" with type \"java.lang.Integer\"",
- e.getMessage().substring(0, 76));
- }
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", yamlInputStringCopy))
+ .hasMessageContaining("Failed to unmarshal YAML event: field \"target\" with type \"java.lang.Integer\"");
pars.setTargetAlias(null);
- yamlInputString = "doubleValue: 123.45\n" + "intValue: ~\n" + "stringValue: MyString";
- try {
- converter.toApexEvent("TestEvent", yamlInputString);
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertTrue(e.getMessage().contains("mandatory field \"intValue\" is missing"));
- }
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", "doubleValue: 123.45\n" + "intValue: ~\n"
+ + "stringValue: MyString"))
+ .hasMessageContaining("mandatory field \"intValue\" is missing");
}
}