aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2020-07-13 11:13:53 +0100
committerwaynedunican <wayne.dunican@est.tech>2020-07-15 14:25:13 +0100
commitaac3c1d70c439910e25a2634f872f497486509ec (patch)
tree8b0f552dc22bfa479bcac96094b67d193c6f49c1 /services
parent871421fb99f7e6221b2c084e43a9388f618f882d (diff)
Replace try/catch with assertj
Replaced try/catch blocks with assertj assertions in apex-pdp. Last batch of changes Issue-ID: POLICY-2451 Change-Id: I39bd02fdbd8389818dcf1b786189c1e344ddcea5 Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'services')
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java76
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java90
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java41
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java300
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java201
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java41
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java275
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java156
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java337
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java306
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java603
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java55
12 files changed, 1006 insertions, 1475 deletions
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java
index d31a9fa37..079be6bd2 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.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.service.engine.engdep;
+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.fail;
import java.net.InetSocketAddress;
import java.util.ArrayList;
@@ -75,13 +76,8 @@ public class EngDepMessageListenerTest {
EngDepMessageListener listener = new EngDepMessageListener(dummyEngineService);
listener.startProcessorThread();
- try {
- listener.onMessage("bad string message");
- fail("test should throw an exception");
- } catch (Exception uoe) {
- assertEquals("String messages are not supported on the EngDep protocol", uoe.getMessage());
- }
-
+ assertThatThrownBy(() -> listener.onMessage("bad string message"))
+ .hasMessage("String messages are not supported on the EngDep protocol");
List<Message> messageList = new ArrayList<>();
messageList.add(new StartEngine(new AxArtifactKey("Start:0.0.1")));
listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
@@ -131,40 +127,36 @@ public class EngDepMessageListenerTest {
await().until(messageQueue::isEmpty);
assertEquals("UpdateModel:0.0.1", dummyEngineService.getUpdateModelKey().getId());
- try {
- messageList.clear();
- messageList.add(new Response(new AxArtifactKey("UpdateModel:0.0.1"), false,
- new GetEngineInfo(new AxArtifactKey("EngineInfo:0.0.1"))));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
- assertEquals("UpdateModel:0.0.1", dummyEngineService.getUpdateModelKey().getId());
-
- messageList.clear();
- Message badMessage0 = new DummyMessage(null, null);
- messageList.add(badMessage0);
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
-
- messageList.clear();
- Message badMessage1 = new DummyMessage(new DummyAction(null), null);
- messageList.add(badMessage1);
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
-
- messageList.clear();
- Message badMessage2 = new DummyMessage(new DummyAction("throw exception"), null);
- messageList.add(badMessage2);
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
-
- messageList.clear();
- Mockito.doReturn(false).when(webSocketMock).isOpen();
- messageList.add(new StartEngine(new AxArtifactKey("Start:0.0.1")));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
- } catch (Exception e) {
- fail("test should not throw exceptions on bad messages");
- }
+ messageList.clear();
+ messageList.add(new Response(new AxArtifactKey("UpdateModel:0.0.1"), false,
+ new GetEngineInfo(new AxArtifactKey("EngineInfo:0.0.1"))));
+ listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
+ await().until(messageQueue::isEmpty);
+ assertEquals("UpdateModel:0.0.1", dummyEngineService.getUpdateModelKey().getId());
+ messageList.clear();
+ Message badMessage0 = new DummyMessage(null, null);
+ messageList.add(badMessage0);
+ listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
+ await().until(messageQueue::isEmpty);
+
+ messageList.clear();
+ Message badMessage1 = new DummyMessage(new DummyAction(null), null);
+ messageList.add(badMessage1);
+ listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
+ await().until(messageQueue::isEmpty);
+
+ messageList.clear();
+ Message badMessage2 = new DummyMessage(new DummyAction("throw exception"), null);
+ messageList.add(badMessage2);
+ listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
+ await().until(messageQueue::isEmpty);
+
+ messageList.clear();
+ Mockito.doReturn(false).when(webSocketMock).isOpen();
+ messageList.add(new StartEngine(new AxArtifactKey("Start:0.0.1")));
+ listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
+ await().until(messageQueue::isEmpty);
+
listener.stopProcessorThreads();
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
index 99b2654ab..ceadc4aae 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
@@ -1,27 +1,27 @@
/*-
* ============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.
* 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.apex.service.engine.event;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.Test;
import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JsonEventConverter;
@@ -37,69 +37,27 @@ public class JsonEventConverterTest {
public void testJsonEventConverter() {
Apex2JsonEventConverter converter = new Apex2JsonEventConverter();
- try {
- converter.init(null);
- fail("test should throw an exception");
- } catch (Exception ie) {
- assertEquals("specified consumer properties are not applicable to the JSON event protocol",
- ie.getMessage());
- }
-
- try {
- converter.init(new EventProtocolParameters() {
- });
- fail("test should throw an exception");
- } catch (Exception ie) {
- assertEquals("specified consumer properties are not applicable to the JSON event protocol",
- ie.getMessage());
- }
-
+ assertThatThrownBy(() -> converter.init(null))
+ .hasMessage("specified consumer properties are not applicable to the JSON event protocol");
+ assertThatThrownBy(() -> converter.init(new EventProtocolParameters() {}))
+ .hasMessage("specified consumer properties are not applicable to the JSON event protocol");
JsonEventProtocolParameters pars = new JsonEventProtocolParameters();
converter.init(pars);
- try {
- converter.toApexEvent(null, null);
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals("event processing failed, event is null", tae.getMessage());
- }
-
- try {
- converter.toApexEvent(null, 1);
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals("error converting event \"1\" to a string", tae.getMessage());
- }
-
- try {
- converter.toApexEvent(null, "[{\"aKey\": 1},{\"aKey\": 2}]");
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals("Failed to unmarshal JSON event: event received without mandatory parameter \"name\" "
- + "on configuration or on event, event=[{\"aKey\": 1},{\"aKey\": 2}]", tae.getMessage());
- }
-
- try {
- converter.toApexEvent(null, "[1,2,3]");
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals("Failed to unmarshal JSON event: incoming event ([1,2,3]) is a JSON object array "
- + "containing an invalid object 1.0, event=[1,2,3]", tae.getMessage());
- }
-
- try {
- converter.fromApexEvent(null);
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals("event processing failed, Apex event is null", tae.getMessage());
- }
-
- try {
- converter.fromApexEvent(new ApexEvent("Event", "0.0.1", "a.name.space", "here", "there"));
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals("Model for org.onap.policy.apex.model.eventmodel.concepts.AxEvents not found in model service",
- tae.getMessage());
- }
+ assertThatThrownBy(() -> converter.toApexEvent(null, null))
+ .hasMessage("event processing failed, event is null");
+ assertThatThrownBy(() -> converter.toApexEvent(null, 1))
+ .hasMessage("error converting event \"1\" to a string");
+ assertThatThrownBy(() -> converter.toApexEvent(null, "[{\"aKey\": 1},{\"aKey\": 2}]"))
+ .hasMessage("Failed to unmarshal JSON event: event received without mandatory parameter \"name\" "
+ + "on configuration or on event, event=[{\"aKey\": 1},{\"aKey\": 2}]");
+ assertThatThrownBy(() -> converter.toApexEvent(null, "[1,2,3]"))
+ .hasMessage("Failed to unmarshal JSON event: incoming event ([1,2,3]) is a JSON object array "
+ + "containing an invalid object 1.0, event=[1,2,3]");
+ assertThatThrownBy(() -> converter.fromApexEvent(null))
+ .hasMessage("event processing failed, Apex event is null");
+ assertThatThrownBy(() -> converter.fromApexEvent(new ApexEvent("Event", "0.0.1", "a.name.space",
+ "here", "there")))
+ .hasMessage("Model for org.onap.policy.apex.model.eventmodel.concepts.AxEvents not found in model service");
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java
index b21f41190..de84acca1 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java
@@ -21,9 +21,9 @@
package org.onap.policy.apex.service.engine.event;
+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.io.ByteArrayInputStream;
import java.io.IOException;
@@ -216,35 +216,16 @@ public class JsonEventHandlerForPojoTest {
logger.debug("input event\n" + apexEventJsonStringIn);
- try {
- jsonEventConverter.toApexEvent("PojoEvent", apexEventJsonStringIn);
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals(
- "Failed to unmarshal JSON event: error parsing PojoEvent:0.0.1 event from Json. "
- + "Field BAD_POJO_PAR not found on POJO event definition.",
- tae.getMessage().substring(0, 133));
- }
-
+ assertThatThrownBy(() -> jsonEventConverter.toApexEvent("PojoEvent", apexEventJsonStringIn))
+ .hasMessageContaining("Failed to unmarshal JSON event: error parsing PojoEvent:0.0.1 event from Json. "
+ + "Field BAD_POJO_PAR not found on POJO event definition.");
pars.setPojoField("POJO_PAR");
- try {
- jsonEventConverter.toApexEvent("PojoNoFieldEvent", apexEventJsonStringIn);
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals(
- "Failed to unmarshal JSON event: error parsing PojoNoFieldEvent:0.0.1 event from Json, "
- + "Field POJO_PAR not found, no fields defined on event.",
- tae.getMessage().substring(0, 139));
- }
-
- try {
- jsonEventConverter.toApexEvent("PojoTooManyFieldsEvent", apexEventJsonStringIn);
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals(
- "Failed to unmarshal JSON event: error parsing PojoTooManyFieldsEvent:0.0.1 event from Json, "
- + "Field POJO_PAR, one and only one field may be defined on a POJO event definition.",
- tae.getMessage().substring(0, 173));
- }
+ assertThatThrownBy(() -> jsonEventConverter.toApexEvent("PojoNoFieldEvent", apexEventJsonStringIn))
+ .hasMessageContaining("Failed to unmarshal JSON event: error parsing PojoNoFieldEvent:0.0.1 "
+ + "event from Json, Field POJO_PAR not found, no fields defined on event.");
+ assertThatThrownBy(() -> jsonEventConverter.toApexEvent("PojoTooManyFieldsEvent", apexEventJsonStringIn))
+ .hasMessageContaining("Failed to unmarshal JSON event: error parsing PojoTooManyFieldsEvent:0.0.1"
+ + " event from Json, Field POJO_PAR, one and only one field may be defined on a "
+ + "POJO event definition.");
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
index b65ebd3dc..241c92978 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
@@ -21,11 +21,11 @@
package org.onap.policy.apex.service.engine.event;
+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.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -103,35 +103,30 @@ public class JsonEventHandlerTest {
*/
@Test
public void testJsontoApexEvent() throws ApexException {
- try {
- final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
- assertNotNull(jsonEventConverter);
- jsonEventConverter.init(new JsonEventProtocolParameters());
+ final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
+ assertNotNull(jsonEventConverter);
+ jsonEventConverter.init(new JsonEventProtocolParameters());
- final String apexEventJsonStringIn = SupportJsonEventGenerator.jsonEvent();
+ final String apexEventJsonStringIn = SupportJsonEventGenerator.jsonEvent();
- logger.debug("input event\n" + apexEventJsonStringIn);
+ logger.debug("input event\n" + apexEventJsonStringIn);
- final List<ApexEvent> apexEventList = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- for (final ApexEvent apexEvent : apexEventList) {
- assertNotNull(apexEvent);
+ final List<ApexEvent> apexEventList = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ for (final ApexEvent apexEvent : apexEventList) {
+ assertNotNull(apexEvent);
- logger.debug(apexEvent.toString());
+ logger.debug(apexEvent.toString());
- assertEquals("BasicEvent", apexEvent.getName());
- assertEquals("0.0.1", apexEvent.getVersion());
- assertEquals("org.onap.policy.apex.events", apexEvent.getNameSpace());
- assertEquals("test", apexEvent.getSource());
- assertEquals("apex", apexEvent.getTarget());
- assertEquals(12345, apexEvent.get("intPar"));
-
- final Object testMatchCaseSelected = apexEvent.get("TestMatchCaseSelected");
- assertNull(testMatchCaseSelected);
- }
- } catch (final Exception e) {
- e.printStackTrace();
- throw new ApexException("Exception reading Apex event JSON file", e);
+ assertEquals("BasicEvent", apexEvent.getName());
+ assertEquals("0.0.1", apexEvent.getVersion());
+ assertEquals("org.onap.policy.apex.events", apexEvent.getNameSpace());
+ assertEquals("test", apexEvent.getSource());
+ assertEquals("apex", apexEvent.getTarget());
+ assertEquals(12345, apexEvent.get("intPar"));
+ final Object testMatchCaseSelected = apexEvent.get("TestMatchCaseSelected");
+ assertNull(testMatchCaseSelected);
}
+
}
/**
@@ -141,142 +136,96 @@ public class JsonEventHandlerTest {
*/
@Test
public void testJsontoApexBadEvent() throws ApexException {
- try {
- final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
- assertNotNull(jsonEventConverter);
- jsonEventConverter.init(new JsonEventProtocolParameters());
+ final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
+ assertNotNull(jsonEventConverter);
+ jsonEventConverter.init(new JsonEventProtocolParameters());
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoName();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: event received without "
+ + "mandatory parameter \"name\" ");
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadName();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: field \"name\" with value \"%%%%\" is invalid");
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoExName();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: an event definition for an event named \"I_DONT_EXI");
+ String apexEventJsonStringIn1 = null;
+ apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventNoVersion();
+ ApexEvent event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
+ assertEquals("0.0.1", event.getVersion());
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadVersion();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: field \"version\" with value \"#####\" is invalid");
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoExVersion();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: an event definition for an event named "
+ + "\"BasicEvent\" with version \"1.2.3\" not found in Apex model");
+ apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventNoNamespace();
+ event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
+ assertEquals("org.onap.policy.apex.events", event.getNameSpace());
+
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadNamespace();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: " + "field \"nameSpace\" with value \"hello.&&&&\" "
+ + "is invalid");
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoExNamespace();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: namespace \"pie.in.the.sky\" "
+ + "on event \"BasicEvent\" does not" + " match namespace \"org.onap.policy.apex.events\" "
+ + "for that event in the Apex model");
+ apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventNoSource();
+ event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
+ assertEquals("source", event.getSource());
+
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadSource();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: field \"source\" with value \"%!@**@!\" is invalid");
+ apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventNoTarget();
+ event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
+ assertEquals("target", event.getTarget());
+
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadTarget();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: field \"target\" with value \"KNIO(*S)A(S)D\" "
+ + "is invalid");
+ assertThatThrownBy(() -> {
String apexEventJsonStringIn = null;
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoName();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: event received without mandatory parameter \"name\" ",
- e.getMessage().substring(0, 82));
- }
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadName();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: field \"name\" with value \"%%%%\" is invalid",
- e.getMessage().substring(0, 73));
- }
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoExName();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: an event definition for an event named \"I_DONT_EXI",
- e.getMessage().substring(0, 82));
- }
-
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoVersion();
- ApexEvent event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn).get(0);
- assertEquals("0.0.1", event.getVersion());
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadVersion();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: field \"version\" with value \"#####\" is invalid",
- e.getMessage().substring(0, 77));
- }
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoExVersion();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals(
- "Failed to unmarshal JSON event: an event definition for an event named "
- + "\"BasicEvent\" with version \"1.2.3\" not found in Apex model",
- e.getMessage().substring(0, 128));
- }
-
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoNamespace();
- event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn).get(0);
- assertEquals("org.onap.policy.apex.events", event.getNameSpace());
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadNamespace();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals(
- "Failed to unmarshal JSON event: " + "field \"nameSpace\" with value \"hello.&&&&\" is invalid",
- e.getMessage().substring(0, 84));
- }
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoExNamespace();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: namespace \"pie.in.the.sky\" "
- + "on event \"BasicEvent\" does not" + " match namespace \"org.onap.policy.apex.events\" "
- + "for that event in the Apex model", e.getMessage().substring(0, 168));
- }
-
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoSource();
- event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn).get(0);
- assertEquals("source", event.getSource());
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadSource();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: field \"source\" with value \"%!@**@!\" is invalid",
- e.getMessage().substring(0, 78));
- }
-
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoTarget();
- event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn).get(0);
- assertEquals("target", event.getTarget());
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadTarget();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: field \"target\" with value \"KNIO(*S)A(S)D\" is invalid",
- e.getMessage().substring(0, 84));
- }
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventMissingFields();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals(
- "Failed to unmarshal JSON event: error parsing BasicEvent:0.0.1 "
- + "event from Json. Field \"intPar\" is missing, but is mandatory.",
- e.getMessage().substring(0, 124));
- }
-
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNullFields();
- event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn).get(0);
- assertEquals(null, event.get("TestSlogan"));
- assertEquals(-1, event.get("intPar"));
-
- // Set the missing fields as optional in the model
- final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get("BasicEvent");
- eventDefinition.getParameterMap().get("intPar").setOptional(true);
-
apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventMissingFields();
- event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn).get(0);
- assertEquals(null, event.get("TestSlogan"));
- assertEquals(null, event.get("intPar"));
- } catch (final Exception e) {
- e.printStackTrace();
- throw new ApexException("Exception reading Apex event JSON file", e);
- }
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: error parsing BasicEvent:0.0.1 "
+ + "event from Json. Field \"intPar\" is missing, but is mandatory.");
+ apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventNullFields();
+ event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
+ assertEquals(null, event.get("TestSlogan"));
+ assertEquals(-1, event.get("intPar"));
+
+ // Set the missing fields as optional in the model
+ final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get("BasicEvent");
+ eventDefinition.getParameterMap().get("intPar").setOptional(true);
+
+ apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventMissingFields();
+ event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
+ assertEquals(null, event.get("TestSlogan"));
+ assertEquals(null, event.get("intPar"));
}
/**
@@ -286,31 +235,26 @@ public class JsonEventHandlerTest {
*/
@Test
public void testApexEventToJson() throws ApexException {
- try {
- final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
- jsonEventConverter.init(new JsonEventProtocolParameters());
- assertNotNull(jsonEventConverter);
+ final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
+ jsonEventConverter.init(new JsonEventProtocolParameters());
+ assertNotNull(jsonEventConverter);
- final Map<String, Object> basicEventMap = new HashMap<String, Object>();
- basicEventMap.put("intPar", 12345);
+ final Map<String, Object> basicEventMap = new HashMap<String, Object>();
+ basicEventMap.put("intPar", 12345);
- final ApexEvent basicEvent =
- new ApexEvent("BasicEvent", "0.0.1", "org.onap.policy.apex.events", "test", "apex");
- basicEvent.putAll(basicEventMap);
+ final ApexEvent basicEvent =
+ new ApexEvent("BasicEvent", "0.0.1", "org.onap.policy.apex.events", "test", "apex");
+ basicEvent.putAll(basicEventMap);
- final String apexEvent0000JsonString = (String) jsonEventConverter.fromApexEvent(basicEvent);
+ final String apexEvent0000JsonString = (String) jsonEventConverter.fromApexEvent(basicEvent);
- logger.debug(apexEvent0000JsonString);
+ logger.debug(apexEvent0000JsonString);
- assertTrue(apexEvent0000JsonString.contains("\"name\": \"BasicEvent\""));
- assertTrue(apexEvent0000JsonString.contains("\"version\": \"0.0.1\""));
- assertTrue(apexEvent0000JsonString.contains("\"nameSpace\": \"org.onap.policy.apex.events\""));
- assertTrue(apexEvent0000JsonString.contains("\"source\": \"test\""));
- assertTrue(apexEvent0000JsonString.contains("\"target\": \"apex\""));
- assertTrue(apexEvent0000JsonString.contains("\"intPar\": 12345"));
- } catch (final Exception e) {
- e.printStackTrace();
- throw new ApexException("Exception reading Apex event JSON file", e);
- }
+ assertTrue(apexEvent0000JsonString.contains("\"name\": \"BasicEvent\""));
+ assertTrue(apexEvent0000JsonString.contains("\"version\": \"0.0.1\""));
+ assertTrue(apexEvent0000JsonString.contains("\"nameSpace\": \"org.onap.policy.apex.events\""));
+ assertTrue(apexEvent0000JsonString.contains("\"source\": \"test\""));
+ assertTrue(apexEvent0000JsonString.contains("\"target\": \"apex\""));
+ assertTrue(apexEvent0000JsonString.contains("\"intPar\": 12345"));
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
index 40375b1f6..09fbe91fe 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
@@ -1,28 +1,28 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-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.
* 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.apex.service.engine.main;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import org.junit.After;
import org.junit.Test;
@@ -30,7 +30,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
/**
* Test Apex Command Line Arguments.
- *
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class ApexCommandLineArgumentsTest {
@@ -40,223 +40,138 @@ public class ApexCommandLineArgumentsTest {
}
@Test
- public void testCommandLineArguments() {
+ public void testCommandLineArguments() throws ApexException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args00 =
{ "" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args00);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("Apex configuration file was not specified as an argument", e.getMessage());
- }
-
+ }).hasMessage("Apex configuration file was not specified as an argument");
final String[] args01 =
{ "-h" };
- try {
- final String result = apexArguments.parse(args01);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+
+ final String result = apexArguments.parse(args01);
+ assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
final String[] args02 =
{ "-v" };
- try {
- final String result = apexArguments.parse(args02);
- assertTrue(result.startsWith("Apex Adaptive Policy Engine"));
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+ final String result02 = apexArguments.parse(args02);
+ assertTrue(result02.startsWith("Apex Adaptive Policy Engine"));
final String[] args03 =
{ "-v", "-h" };
- try {
- final String result = apexArguments.parse(args03);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+
+ final String result03 = apexArguments.parse(args03);
+ assertTrue(result03.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
final String[] args04 =
{ "-h", "-v" };
- try {
- final String result = apexArguments.parse(args04);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+
+ final String result04 = apexArguments.parse(args04);
+ assertTrue(result04.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
final String[] args05 =
{ "-a" };
- try {
- apexArguments.parse(args05);
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Unrecognized option: -a", e.getMessage());
- }
-
+ assertThatThrownBy(() -> apexArguments.parse(args05))
+ .hasMessage("invalid command line arguments specified : Unrecognized option: -a");
final String[] args06 =
{ "-c", "hello", "-m", "goodbye", "-h", "-v" };
- try {
- final String result = apexArguments.parse(args06);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Unrecognized option: -a", e.getMessage());
- }
+ final String result06 = apexArguments.parse(args06);
+ assertTrue(result06.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
final String[] args07 =
{ "-c", "hello", "-m", "goodbye", "-h", "aaa" };
- try {
- final String result = apexArguments.parse(args07);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- assertEquals("too many command line arguments specified : [-c, hello, -m, goodbye, -h, aaa]",
- e.getMessage());
- }
+ assertThatThrownBy(() -> apexArguments.parse(args07))
+ .hasMessage("too many command line arguments specified : [-c, hello, -m, goodbye, -h, aaa]");
}
@Test
- public void testCommandLineFileParameters() {
+ public void testCommandLineFileParameters() throws ApexException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args00 =
{ "-c", "zooby" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args00);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("Apex configuration file \"zooby\" does not exist", e.getMessage());
- }
-
+ }).hasMessage("Apex configuration file \"zooby\" does not exist");
final String[] args01 =
{ "-c" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args01);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Missing argument for option: c", e.getMessage());
- }
-
+ }).hasMessage("invalid command line arguments specified : Missing argument for option: c");
final String[] args02 =
{ "-c", "src/test/resources/parameters/goodParams.json" };
- try {
- apexArguments.parse(args02);
- apexArguments.validate();
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+ apexArguments.parse(args02);
+ apexArguments.validate();
final String[] args03 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-m", "zooby" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args03);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("Apex model file \"zooby\" does not exist", e.getMessage());
- }
-
+ }).hasMessage("Apex model file \"zooby\" does not exist");
final String[] args04 =
{ "-m" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args04);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Missing argument for option: m", e.getMessage());
- }
-
+ }).hasMessage("invalid command line arguments specified : Missing argument for option: m");
final String[] args05 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-m" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args05);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Missing argument for option: m", e.getMessage());
- }
-
+ }).hasMessage("invalid command line arguments specified : Missing argument for option: m");
final String[] args06 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-m",
"src/test/resources/main/DummyModelFile.json" };
- try {
- apexArguments.parse(args06);
- apexArguments.validate();
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+ apexArguments.parse(args06);
+ apexArguments.validate();
final String[] args07 =
{ "-c", "parameters/goodParams.json", "-m", "main/DummyModelFile.json" };
- try {
- apexArguments.parse(args07);
- apexArguments.validate();
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+
+ apexArguments.parse(args07);
+ apexArguments.validate();
}
@Test
- public void testCommandLineRelativeRootParameters() {
+ public void testCommandLineRelativeRootParameters() throws ApexException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args00 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-rfr", "zooby" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args00);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertTrue(e.getMessage().contains("zooby\" does not exist or is not a directory"));
- }
-
+ }).hasMessageContaining("zooby\" does not exist or is not a directory");
final String[] args01 =
{ "-rfr" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args01);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Missing argument for option: rfr", e.getMessage());
- }
-
+ }).hasMessage("invalid command line arguments specified : Missing argument for option: rfr");
final String[] args02 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-rfr", "pom.xml" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args02);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertTrue(e.getMessage().contains("pom.xml\" does not exist or is not a directory"));
- }
-
+ }).hasMessageContaining("pom.xml\" does not exist or is not a directory");
final String[] args03 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-rfr", "target" };
- try {
- apexArguments.parse(args03);
- apexArguments.validate();
- } catch (final ApexException e) {
- fail("Test should not throw an exception here");
- }
+
+ apexArguments.parse(args03);
+ apexArguments.validate();
final String[] args04 =
{ "-c", "src/test/resources/parameters/goodParamsRelative.json", "-rfr", "src/test/resources" };
- try {
- apexArguments.parse(args04);
- apexArguments.validate();
- } catch (final ApexException e) {
- fail("Test should not throw an exception here");
- }
+
+ apexArguments.parse(args04);
+ apexArguments.validate();
+
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java
index ff97eaec2..330de42dd 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.apex.service.engine.parameters;
+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.assertNotNull;
@@ -44,16 +45,13 @@ public class ApexParametersTest {
final String[] args = {"-c", "src/test/resources/parameters/javaPropertiesOK.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertTrue(parameters.checkJavaPropertiesSet());
- assertEquals("property0", parameters.getJavaProperties()[0][0]);
- assertEquals("property0Value", parameters.getJavaProperties()[0][1]);
- assertEquals("property1", parameters.getJavaProperties()[1][0]);
- assertEquals("property1Value", parameters.getJavaProperties()[1][1]);
- } catch (final ParameterException e) {
- fail("This test should not throw an exception");
- }
+ ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertTrue(parameters.checkJavaPropertiesSet());
+ assertEquals("property0", parameters.getJavaProperties()[0][0]);
+ assertEquals("property0Value", parameters.getJavaProperties()[0][1]);
+ assertEquals("property1", parameters.getJavaProperties()[1][0]);
+ assertEquals("property1Value", parameters.getJavaProperties()[1][1]);
+
}
@Test
@@ -61,12 +59,9 @@ public class ApexParametersTest {
final String[] args = {"-c", "src/test/resources/parameters/javaPropertiesEmpty.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertFalse(parameters.checkJavaPropertiesSet());
- } catch (final ParameterException pe) {
- fail("This test should not throw an exception");
- }
+ ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertFalse(parameters.checkJavaPropertiesSet());
+
}
@Test
@@ -74,15 +69,11 @@ public class ApexParametersTest {
final String[] args = {"-c", "src/test/resources/parameters/javaPropertiesBad.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException pe) {
- assertTrue(pe.getMessage().contains("java properties array entries must have one key and one value"));
- assertTrue(pe.getMessage().contains("java properties key is null or blank"));
- assertTrue(pe.getMessage().contains("java properties value is null or blank"));
- assertTrue(pe.getMessage().contains("java properties array entry is null"));
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageContaining("java properties array entries must have one key and one value")
+ .hasMessageContaining("java properties key is null or blank")
+ .hasMessageContaining("java properties value is null or blank")
+ .hasMessageContaining("java properties array entry is null");
}
@Test
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java
index f6d39f029..018fda668 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java
@@ -21,6 +21,7 @@
package org.onap.policy.apex.service.engine.parameters;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -43,14 +44,10 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextNoParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from \"src/test/resources/parameters/serviceContextNoParams.json\"\n"
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from \"src/test/resources/parameters/serviceContextNoParams.json\"\n"
+ "(ParameterRuntimeException):could not find field \"parameterClassName\" in "
- + "\"contextParameters\" entry", e.getMessage());
- }
+ + "\"contextParameters\" entry");
}
@Test
@@ -58,15 +55,11 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from \"src/test/resources/parameters/serviceContextBadParams.json\""
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from \"src/test/resources/parameters/serviceContextBadParams.json\""
+ "\n(ParameterRuntimeException):failed to deserialize the parameters for "
+ "\"contextParameters\" to parameter class "
- + "\"hello\"\njava.lang.ClassNotFoundException: hello", e.getMessage());
- }
+ + "\"hello\"\njava.lang.ClassNotFoundException: hello");
}
@Test
@@ -74,15 +67,11 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadPluginNameParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceContextBadPluginNameParams.json\"\n"
- + "(ParameterRuntimeException):could not find field \"parameterClassName\" in "
- + "\"contextParameters\" entry", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadPluginNameParams.json\"\n"
+ + "(ParameterRuntimeException):could not find field \"parameterClassName\" in "
+ + "\"contextParameters\" entry");
}
@Test
@@ -90,19 +79,13 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadClassParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals(
- "error reading parameters from "
- + "\"src/test/resources/parameters/serviceContextBadClassParams.json\""
- + "\n(ParameterRuntimeException):failed to deserialize "
- + "the parameters for \"contextParameters\""
- + " to parameter class \"java.lang.Integer\"\ncom.google.gson.JsonSyntaxException: "
- + "java.lang.IllegalStateException: Expected NUMBER but was BEGIN_OBJECT at path $",
- e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadClassParams.json\""
+ + "\n(ParameterRuntimeException):failed to deserialize "
+ + "the parameters for \"contextParameters\""
+ + " to parameter class \"java.lang.Integer\"\ncom.google.gson.JsonSyntaxException: "
+ + "java.lang.IllegalStateException: Expected NUMBER but was BEGIN_OBJECT at path $");
}
@Test
@@ -110,126 +93,106 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadPluginClassParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceContextBadPluginClassParams.json\""
- + "\n(ClassCastException):class org.onap.policy.apex.service.engine.parameters."
- + "dummyclasses.SuperDooperExecutorParameters"
- + " cannot be cast to class org.onap.policy.apex.context.parameters.ContextParameters "
- + "(org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperExecutorParameters and "
- + "org.onap.policy.apex.context.parameters.ContextParameters are "
- + "in unnamed module of loader 'app')", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadPluginClassParams.json\""
+ + "\n(ClassCastException):class org.onap.policy.apex.service.engine.parameters."
+ + "dummyclasses.SuperDooperExecutorParameters"
+ + " cannot be cast to class org.onap.policy.apex.context.parameters.ContextParameters "
+ + "(org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperExecutorParameters and "
+ + "org.onap.policy.apex.context.parameters.ContextParameters are "
+ + "in unnamed module of loader 'app')");
}
@Test
- public void testOkFlushParamTest() {
+ public void testOkFlushParamTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextOKFlushParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
- .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
- assertEquals(123456, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters().getFlushPeriod());
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
+ .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
+ assertEquals(123456, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getPersistorParameters().getFlushPeriod());
+
}
@Test
- public void testOkDefaultParamTest() {
+ public void testOkDefaultParamTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextOKDefaultParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
- .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
- assertEquals(300000, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters().getFlushPeriod());
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
+ .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
+ assertEquals(300000, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getPersistorParameters().getFlushPeriod());
+
}
@Test
- public void testOkDistParamTest() {
+ public void testOkDistParamTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextOKDistParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
- .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
- assertEquals("org.onap.policy.apex.context.parameters.DistributorParameters",
- parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getDistributorParameters().getClass().getName());
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
+ .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
+ assertEquals("org.onap.policy.apex.context.parameters.DistributorParameters",
+ parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getDistributorParameters().getClass().getName());
+
}
@Test
- public void testOkFullDefaultParamTest() {
+ public void testOkFullDefaultParamTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/goodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
- .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
- assertEquals("org.onap.policy.apex.context.parameters.DistributorParameters",
- parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getDistributorParameters().getClass().getName());
- assertEquals("org.onap.policy.apex.context.parameters.LockManagerParameters",
- parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getLockManagerParameters().getClass().getName());
- assertEquals("org.onap.policy.apex.context.parameters.PersistorParameters",
- parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters().getClass().getName());
- assertEquals(300000, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters().getFlushPeriod());
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
+ .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
+ assertEquals("org.onap.policy.apex.context.parameters.DistributorParameters",
+ parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getDistributorParameters().getClass().getName());
+ assertEquals("org.onap.policy.apex.context.parameters.LockManagerParameters",
+ parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getLockManagerParameters().getClass().getName());
+ assertEquals("org.onap.policy.apex.context.parameters.PersistorParameters",
+ parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getPersistorParameters().getClass().getName());
+ assertEquals(300000, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getPersistorParameters().getFlushPeriod());
+
}
@Test
- public void testOkFullParamTest() {
+ public void testOkFullParamTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextOKFullParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
- .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
- assertEquals("org.onap.policy.apex.context.parameters.LockManagerParameters",
- parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getLockManagerParameters().getClass().getName());
- assertEquals("org.onap.policy.apex.context.parameters.PersistorParameters",
- parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters().getClass().getName());
- assertEquals(123456, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters().getFlushPeriod());
-
- final SuperDooperDistributorParameters infinispanParameters =
- (SuperDooperDistributorParameters) parameters.getEngineServiceParameters().getEngineParameters()
- .getContextParameters().getDistributorParameters();
- assertEquals("org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperDistributorParameters",
- infinispanParameters.getClass().getName());
- assertEquals("my/lovely/configFile.xml", infinispanParameters.getConfigFile());
- assertEquals("holy/stone.xml", infinispanParameters.getJgroupsFile());
- assertEquals(false, infinispanParameters.isPreferIPv4Stack());
- assertEquals("fatherted", infinispanParameters.getJgroupsBindAddress());
-
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
+ .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
+ assertEquals("org.onap.policy.apex.context.parameters.LockManagerParameters",
+ parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getLockManagerParameters().getClass().getName());
+ assertEquals("org.onap.policy.apex.context.parameters.PersistorParameters",
+ parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getPersistorParameters().getClass().getName());
+ assertEquals(123456, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getPersistorParameters().getFlushPeriod());
+
+ final SuperDooperDistributorParameters infinispanParameters =
+ (SuperDooperDistributorParameters) parameters.getEngineServiceParameters().getEngineParameters()
+ .getContextParameters().getDistributorParameters();
+ assertEquals("org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperDistributorParameters",
+ infinispanParameters.getClass().getName());
+ assertEquals("my/lovely/configFile.xml", infinispanParameters.getConfigFile());
+ assertEquals("holy/stone.xml", infinispanParameters.getJgroupsFile());
+ assertEquals(false, infinispanParameters.isPreferIPv4Stack());
+ assertEquals("fatherted", infinispanParameters.getJgroupsBindAddress());
+
}
@Test
@@ -237,18 +200,14 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadClassDistParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceContextBadClassDistParams.json\"\n"
- + "(ClassCastException):class "
- + "org.onap.policy.apex.context.parameters.ContextParameters cannot be cast to class"
- + " org.onap.policy.apex.context.parameters.DistributorParameters (org.onap.policy.apex.context."
- + "parameters.ContextParameters and org.onap.policy.apex.context.parameters.DistributorParameters "
- + "are in unnamed module of loader 'app')", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadClassDistParams.json\"\n"
+ + "(ClassCastException):class "
+ + "org.onap.policy.apex.context.parameters.ContextParameters cannot be cast to class"
+ + " org.onap.policy.apex.context.parameters.DistributorParameters (org.onap.policy.apex.context."
+ + "parameters.ContextParameters and org.onap.policy.apex.context.parameters.DistributorParameters "
+ + "are in unnamed module of loader 'app')");
}
@Test
@@ -256,18 +215,14 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadClassLockParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceContextBadClassLockParams.json\"\n"
- + "(ClassCastException):class "
- + "org.onap.policy.apex.context.parameters.ContextParameters cannot be cast to class "
- + "org.onap.policy.apex.context.parameters.LockManagerParameters (org.onap.policy.apex.context."
- + "parameters.ContextParameters and org.onap.policy.apex.context.parameters.LockManagerParameters "
- + "are in unnamed module of loader 'app')", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadClassLockParams.json\"\n"
+ + "(ClassCastException):class "
+ + "org.onap.policy.apex.context.parameters.ContextParameters cannot be cast to class "
+ + "org.onap.policy.apex.context.parameters.LockManagerParameters (org.onap.policy.apex.context."
+ + "parameters.ContextParameters and org.onap.policy.apex.context.parameters.LockManagerParameters "
+ + "are in unnamed module of loader 'app')");
}
@Test
@@ -275,17 +230,13 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadClassPersistParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceContextBadClassPersistParams.json\"\n"
- + "(ClassCastException):class "
- + "org.onap.policy.apex.context.parameters.ContextParameters cannot be cast to class "
- + "org.onap.policy.apex.context.parameters.PersistorParameters (org.onap.policy.apex.context."
- + "parameters.ContextParameters and org.onap.policy.apex.context.parameters.PersistorParameters "
- + "are in unnamed module of loader 'app')", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadClassPersistParams.json\"\n"
+ + "(ClassCastException):class "
+ + "org.onap.policy.apex.context.parameters.ContextParameters cannot be cast to class "
+ + "org.onap.policy.apex.context.parameters.PersistorParameters (org.onap.policy.apex.context."
+ + "parameters.ContextParameters and org.onap.policy.apex.context.parameters.PersistorParameters "
+ + "are in unnamed module of loader 'app')");
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java
index 16a892f93..5d1b3f726 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java
@@ -21,9 +21,9 @@
package org.onap.policy.apex.service.engine.parameters;
+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 org.junit.After;
import org.junit.Test;
@@ -44,17 +44,14 @@ public class ExecutorParameterTests {
}
@Test
- public void testNoParamsTest() {
+ public void testNoParamsTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorNoParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals(0,
- parameters.getEngineServiceParameters().getEngineParameters().getExecutorParameterMap().size());
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals(0,
+ parameters.getEngineServiceParameters().getEngineParameters().getExecutorParameterMap().size());
+
}
@Test
@@ -62,15 +59,11 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorBadParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ "\"src/test/resources/parameters/serviceExecutorBadParams.json\"\n"
+ "(ParameterRuntimeException):value of \"executorParameters:ZOOBY\" entry is not "
- + "a parameter JSON object", e.getMessage());
- }
+ + "a parameter JSON object");
}
@Test
@@ -78,15 +71,11 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorNoExecutorParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceExecutorNoExecutorParams.json\"\n"
- + "(ParameterRuntimeException):no \"executorParameters\" entry found in parameters,"
- + " at least one executor parameter entry must be specified", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceExecutorNoExecutorParams.json\"\n"
+ + "(ParameterRuntimeException):no \"executorParameters\" entry found in parameters,"
+ + " at least one executor parameter entry must be specified");
}
@Test
@@ -94,15 +83,11 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorEmptyParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceExecutorEmptyParams.json\"\n"
- + "(ParameterRuntimeException):could not find field \"parameterClassName\" "
- + "in \"executorParameters:ZOOBY\" entry", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceExecutorEmptyParams.json\"\n"
+ + "(ParameterRuntimeException):could not find field \"parameterClassName\" "
+ + "in \"executorParameters:ZOOBY\" entry");
}
@Test
@@ -110,15 +95,11 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorBadPluginNameParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceExecutorBadPluginNameParams.json\"\n"
- + "(ParameterRuntimeException):could not find field \"parameterClassName\" "
- + "in \"executorParameters:ZOOBY\" entry", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceExecutorBadPluginNameParams.json\"\n"
+ + "(ParameterRuntimeException):could not find field \"parameterClassName\" "
+ + "in \"executorParameters:ZOOBY\" entry");
}
@Test
@@ -126,15 +107,11 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorBadPluginValueObjectParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceExecutorBadPluginValueObjectParams.json\"\n"
- + "(ParameterRuntimeException):value for field \"parameterClassName\" "
- + "of \"executorParameters:LOOBY\" entry is not a plain string", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceExecutorBadPluginValueObjectParams.json\"\n"
+ + "(ParameterRuntimeException):value for field \"parameterClassName\" "
+ + "of \"executorParameters:LOOBY\" entry is not a plain string");
}
@Test
@@ -142,15 +119,11 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorBadPluginValueBlankParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceExecutorBadPluginValueBlankParams.json\"\n"
- + "(ParameterRuntimeException):value for field \"parameterClassName\" "
- + "in \"executorParameters:LOOBY\" entry is not specified or is blank", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceExecutorBadPluginValueBlankParams.json\"\n"
+ + "(ParameterRuntimeException):value for field \"parameterClassName\" "
+ + "in \"executorParameters:LOOBY\" entry is not specified or is blank");
}
@Test
@@ -158,38 +131,31 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorBadPluginValueParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from"
- + " \"src/test/resources/parameters/serviceExecutorBadPluginValueParams.json\"\n"
- + "(ParameterRuntimeException):failed to deserialize the parameters "
- + "for \"executorParameters:LOOBY\" to parameter class \"helloworld\"\n"
- + "java.lang.ClassNotFoundException: helloworld", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from"
+ + " \"src/test/resources/parameters/serviceExecutorBadPluginValueParams.json\"\n"
+ + "(ParameterRuntimeException):failed to deserialize the parameters "
+ + "for \"executorParameters:LOOBY\" to parameter class \"helloworld\"\n"
+ + "java.lang.ClassNotFoundException: helloworld");
}
@Test
- public void testGoodParametersTest() {
+ public void testGoodParametersTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/goodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
-
- assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
- assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
- assertEquals(45, parameters.getEngineServiceParameters().getId());
- assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
- assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+
+ assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
+ assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
+ assertEquals(45, parameters.getEngineServiceParameters().getId());
+ assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
+ assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
+
}
@Test
- public void testRelativeParametersTest() {
+ public void testRelativeParametersTest() throws ParameterException {
// @formatter:off
final String[] args = {
"-rfr",
@@ -200,18 +166,14 @@ public class ExecutorParameterTests {
// @formatter:on
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
-
- assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
- assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
- assertEquals(45, parameters.getEngineServiceParameters().getId());
- assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
- assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
- assertTrue(parameters.getEngineServiceParameters().getPolicyModelFileName()
- .endsWith("policymodels/SmallModel.json"));
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+
+ assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
+ assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
+ assertEquals(45, parameters.getEngineServiceParameters().getId());
+ assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
+ assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
+ assertTrue(parameters.getEngineServiceParameters().getPolicyModelFileName()
+ .endsWith("policymodels/SmallModel.json"));
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java
index cbd9ee058..4948ab5f3 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java
@@ -21,10 +21,10 @@
package org.onap.policy.apex.service.engine.parameters;
+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.Arrays;
import org.junit.Test;
@@ -51,13 +51,9 @@ public class ParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/invalidNoFile.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertTrue(e.getMessage().startsWith("error reading parameters from \"src"));
- assertTrue(e.getMessage().contains("FileNotFoundException"));
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageStartingWith("error reading parameters from \"src")
+ .hasMessageContaining("FileNotFoundException");
}
@Test
@@ -65,13 +61,9 @@ public class ParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/empty.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertTrue(e.getMessage()
- .startsWith("validation error(s) on parameters from \"src/test/resources/parameters/empty.json\""));
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageStartingWith("validation error(s) on parameters from \"src/test/resources/parameters/empty"
+ + ".json\"");
}
@Test
@@ -79,20 +71,16 @@ public class ParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/noParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from \"src/test/resources/parameters/noParams.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
- + "engine service parameters are not specified\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "at least one event output must be specified\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "at least one event input must be specified\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/noParams.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
+ + "engine service parameters are not specified\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "at least one event output must be specified\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "at least one event input must be specified\n");
}
@Test
@@ -100,24 +88,19 @@ public class ParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/blankParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
-
- assertEquals("validation error(s) on parameters from \"src/test/resources/parameters/blankParams.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group \"ENGINE_SERVICE_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
- + "INVALID, parameter group has status INVALID\n"
- + " field \"id\" type \"int\" value \"-1\" INVALID, "
- + "id not specified or specified value [-1] invalid, must be specified as id >= 0\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "at least one event output must be specified\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "at least one event input must be specified\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/blankParams.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n" + " parameter group \"ENGINE_SERVICE_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
+ + "INVALID, parameter group has status INVALID\n"
+ + " field \"id\" type \"int\" value \"-1\" INVALID, "
+ + "id not specified or specified value [-1] invalid, must be specified as id >= 0\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "at least one event output must be specified\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "at least one event input must be specified\n");
}
@Test
@@ -125,45 +108,41 @@ public class ParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/badParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from \"src/test/resources/parameters/badParams.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group \"hello there\" type "
- + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
- + "INVALID, parameter group has status INVALID\n"
- + " field \"name\" type \"java.lang.String\" value \"hello there\" INVALID, "
- + "name is invalid, it must match regular expression[A-Za-z0-9\\-_\\.]+\n"
- + " field \"id\" type \"int\" value \"-45\" INVALID, id not specified or "
- + "specified value [-45] invalid, must be specified as id >= 0\n"
- + " field \"instanceCount\" type \"int\" value \"-345\" INVALID, "
- + "instanceCount [-345] invalid, must be specified as instanceCount >= 1\n"
- + " field \"deploymentPort\" type \"int\" value \"65536\" INVALID, "
- + "deploymentPort [65536] invalid, must be specified as 1024 <= port <= 65535\n"
- + " field \"policyModelFileName\" type \"java.lang.String\" "
- + "value \"/some/file/name.xml\" INVALID, not found\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"FirstProducer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
- + "\"org.onap.policy.apex.service.engine.event.impl."
- + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
- + "\"null\" invalid, must be specified as a non-empty string\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"TheFileConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
- + "\"org.onap.policy.apex.service.engine.event.impl."
- + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
- + "\"null\" invalid, must be specified as a non-empty string\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/badParams.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n" + " parameter group \"hello there\" type "
+ + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
+ + "INVALID, parameter group has status INVALID\n"
+ + " field \"name\" type \"java.lang.String\" value \"hello there\" INVALID, "
+ + "name is invalid, it must match regular expression[A-Za-z0-9\\-_\\.]+\n"
+ + " field \"id\" type \"int\" value \"-45\" INVALID, id not specified or "
+ + "specified value [-45] invalid, must be specified as id >= 0\n"
+ + " field \"instanceCount\" type \"int\" value \"-345\" INVALID, "
+ + "instanceCount [-345] invalid, must be specified as instanceCount >= 1\n"
+ + " field \"deploymentPort\" type \"int\" value \"65536\" INVALID, "
+ + "deploymentPort [65536] invalid, must be specified as 1024 <= port <= 65535\n"
+ + " field \"policyModelFileName\" type \"java.lang.String\" "
+ + "value \"/some/file/name.xml\" INVALID, not found\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"FirstProducer\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
+ + "\"org.onap.policy.apex.service.engine.event.impl."
+ + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "\"null\" invalid, must be specified as a non-empty string\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"TheFileConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
+ + "\"org.onap.policy.apex.service.engine.event.impl."
+ + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "\"null\" invalid, must be specified as a non-empty string\n");
}
@Test
@@ -171,125 +150,111 @@ public class ParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/badParamsModelNotFile.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals(
- "validation error(s) on parameters from "
- + "\"src/test/resources/parameters/badParamsModelNotFile.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group \"MyApexEngine\" type "
- + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
- + "INVALID, parameter group has status INVALID\n" + " field \"policyModelFileName\" "
- + "type \"java.lang.String\" value \"src/test\" INVALID, is not a plain file\n",
- e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/badParamsModelNotFile.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n" + " parameter group \"MyApexEngine\" type "
+ + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
+ + "INVALID, parameter group has status INVALID\n" + " field \"policyModelFileName\" "
+ + "type \"java.lang.String\" value \"src/test\" INVALID, is not a plain file\n");
}
@Test
- public void testGoodParametersTest() {
+ public void testGoodParametersTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/goodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
-
- assertEquals(2, parameters.getEventInputParameters().size());
- assertEquals(2, parameters.getEventOutputParameters().size());
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertTrue(parameters.getEventOutputParameters().containsKey("FirstProducer"));
- assertTrue(parameters.getEventOutputParameters().containsKey("MyOtherProducer"));
- assertEquals("FILE", parameters.getEventOutputParameters().get("FirstProducer")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("FILE", parameters.getEventOutputParameters().get("MyOtherProducer")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals(ApexFileEventProducer.class.getName(), parameters.getEventOutputParameters()
- .get("MyOtherProducer").getCarrierTechnologyParameters().getEventProducerPluginClass());
- assertEquals(ApexFileEventConsumer.class.getName(), parameters.getEventOutputParameters()
- .get("MyOtherProducer").getCarrierTechnologyParameters().getEventConsumerPluginClass());
- assertEquals("JSON",
- parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters().getLabel());
- assertEquals("JSON", parameters.getEventOutputParameters().get("MyOtherProducer")
- .getEventProtocolParameters().getLabel());
+ assertEquals(2, parameters.getEventInputParameters().size());
+ assertEquals(2, parameters.getEventOutputParameters().size());
+ assertTrue(parameters.getEventOutputParameters().containsKey("FirstProducer"));
+ assertTrue(parameters.getEventOutputParameters().containsKey("MyOtherProducer"));
+ assertEquals("FILE", parameters.getEventOutputParameters().get("FirstProducer")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("FILE", parameters.getEventOutputParameters().get("MyOtherProducer")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals(ApexFileEventProducer.class.getName(), parameters.getEventOutputParameters()
+ .get("MyOtherProducer").getCarrierTechnologyParameters().getEventProducerPluginClass());
+ assertEquals(ApexFileEventConsumer.class.getName(), parameters.getEventOutputParameters()
+ .get("MyOtherProducer").getCarrierTechnologyParameters().getEventConsumerPluginClass());
+ assertEquals("JSON",
+ parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters().getLabel());
+ assertEquals("JSON", parameters.getEventOutputParameters().get("MyOtherProducer")
+ .getEventProtocolParameters().getLabel());
- assertTrue(parameters.getEventInputParameters().containsKey("TheFileConsumer1"));
- assertTrue(parameters.getEventInputParameters().containsKey("MySuperDooperConsumer1"));
- assertEquals("FILE", parameters.getEventInputParameters().get("TheFileConsumer1")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("SUPER_DOOPER", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("JSON", parameters.getEventInputParameters().get("TheFileConsumer1")
- .getEventProtocolParameters().getLabel());
- assertEquals("SUPER_TOK_DEL", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
- .getEventProtocolParameters().getLabel());
- assertEquals(ApexFileEventProducer.class.getName(), parameters.getEventInputParameters()
- .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
- assertEquals(ApexFileEventConsumer.class.getName(), parameters.getEventInputParameters()
- .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
- assertEquals(SuperDooperEventProducer.class.getName(), parameters.getEventInputParameters()
- .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
- assertEquals(SuperDooperEventSubscriber.class.getName(), parameters.getEventInputParameters()
- .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
- } catch (final ParameterException e) {
- fail("This test should not throw an exception");
- }
+ assertTrue(parameters.getEventInputParameters().containsKey("TheFileConsumer1"));
+ assertTrue(parameters.getEventInputParameters().containsKey("MySuperDooperConsumer1"));
+ assertEquals("FILE", parameters.getEventInputParameters().get("TheFileConsumer1")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("SUPER_DOOPER", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("JSON", parameters.getEventInputParameters().get("TheFileConsumer1")
+ .getEventProtocolParameters().getLabel());
+ assertEquals("SUPER_TOK_DEL", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
+ .getEventProtocolParameters().getLabel());
+ assertEquals(ApexFileEventProducer.class.getName(), parameters.getEventInputParameters()
+ .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
+ assertEquals(ApexFileEventConsumer.class.getName(), parameters.getEventInputParameters()
+ .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
+ assertEquals(SuperDooperEventProducer.class.getName(), parameters.getEventInputParameters()
+ .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
+ assertEquals(SuperDooperEventSubscriber.class.getName(), parameters.getEventInputParameters()
+ .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
}
@Test
- public void testSuperDooperParametersTest() {
+ public void testSuperDooperParametersTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/superDooperParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+
+ assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
+ assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
+ assertEquals(45, parameters.getEngineServiceParameters().getId());
+ assertEquals(345, parameters.getEngineServiceParameters().getInstanceCount());
+ assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
- assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
- assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
- assertEquals(45, parameters.getEngineServiceParameters().getId());
- assertEquals(345, parameters.getEngineServiceParameters().getInstanceCount());
- assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
+ final CarrierTechnologyParameters prodCarrierTech =
+ parameters.getEventOutputParameters().get("FirstProducer").getCarrierTechnologyParameters();
+ final EventProtocolParameters prodEventProt =
+ parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters();
+ final CarrierTechnologyParameters consCarrierTech =
+ parameters.getEventInputParameters().get("MySuperDooperConsumer1").getCarrierTechnologyParameters();
+ final EventProtocolParameters consEventProt =
+ parameters.getEventInputParameters().get("MySuperDooperConsumer1").getEventProtocolParameters();
- final CarrierTechnologyParameters prodCarrierTech =
- parameters.getEventOutputParameters().get("FirstProducer").getCarrierTechnologyParameters();
- final EventProtocolParameters prodEventProt =
- parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters();
- final CarrierTechnologyParameters consCarrierTech =
- parameters.getEventInputParameters().get("MySuperDooperConsumer1").getCarrierTechnologyParameters();
- final EventProtocolParameters consEventProt =
- parameters.getEventInputParameters().get("MySuperDooperConsumer1").getEventProtocolParameters();
+ assertEquals("SUPER_DOOPER", prodCarrierTech.getLabel());
+ assertEquals("SUPER_TOK_DEL", prodEventProt.getLabel());
+ assertEquals("SUPER_DOOPER", consCarrierTech.getLabel());
+ assertEquals("JSON", consEventProt.getLabel());
- assertEquals("SUPER_DOOPER", prodCarrierTech.getLabel());
- assertEquals("SUPER_TOK_DEL", prodEventProt.getLabel());
- assertEquals("SUPER_DOOPER", consCarrierTech.getLabel());
- assertEquals("JSON", consEventProt.getLabel());
+ assertTrue(prodCarrierTech instanceof SuperDooperCarrierTechnologyParameters);
- assertTrue(prodCarrierTech instanceof SuperDooperCarrierTechnologyParameters);
+ final SuperDooperCarrierTechnologyParameters superDooperParameters =
+ (SuperDooperCarrierTechnologyParameters) prodCarrierTech;
+ assertEquals("somehost:12345", superDooperParameters.getBootstrapServers());
+ assertEquals("0", superDooperParameters.getAcks());
+ assertEquals(25, superDooperParameters.getRetries());
+ assertEquals(98765, superDooperParameters.getBatchSize());
+ assertEquals(21, superDooperParameters.getLingerTime());
+ assertEquals(50505050, superDooperParameters.getBufferMemory());
+ assertEquals("first-group-id", superDooperParameters.getGroupId());
+ assertFalse(superDooperParameters.isEnableAutoCommit());
+ assertEquals(441, superDooperParameters.getAutoCommitTime());
+ assertEquals(987, superDooperParameters.getSessionTimeout());
+ assertEquals("producer-out", superDooperParameters.getProducerTopic());
+ assertEquals(101, superDooperParameters.getConsumerPollTime());
+ assertEquals("some.key.serailizer", superDooperParameters.getKeySerializer());
+ assertEquals("some.value.serailizer", superDooperParameters.getValueSerializer());
+ assertEquals("some.key.deserailizer", superDooperParameters.getKeyDeserializer());
+ assertEquals("some.value.deserailizer", superDooperParameters.getValueDeserializer());
- final SuperDooperCarrierTechnologyParameters superDooperParameters =
- (SuperDooperCarrierTechnologyParameters) prodCarrierTech;
- assertEquals("somehost:12345", superDooperParameters.getBootstrapServers());
- assertEquals("0", superDooperParameters.getAcks());
- assertEquals(25, superDooperParameters.getRetries());
- assertEquals(98765, superDooperParameters.getBatchSize());
- assertEquals(21, superDooperParameters.getLingerTime());
- assertEquals(50505050, superDooperParameters.getBufferMemory());
- assertEquals("first-group-id", superDooperParameters.getGroupId());
- assertFalse(superDooperParameters.isEnableAutoCommit());
- assertEquals(441, superDooperParameters.getAutoCommitTime());
- assertEquals(987, superDooperParameters.getSessionTimeout());
- assertEquals("producer-out", superDooperParameters.getProducerTopic());
- assertEquals(101, superDooperParameters.getConsumerPollTime());
- assertEquals("some.key.serailizer", superDooperParameters.getKeySerializer());
- assertEquals("some.value.serailizer", superDooperParameters.getValueSerializer());
- assertEquals("some.key.deserailizer", superDooperParameters.getKeyDeserializer());
- assertEquals("some.value.deserailizer", superDooperParameters.getValueDeserializer());
+ final String[] consumerTopics = {"consumer-out-0", "consumer-out-1", "consumer-out-2"};
+ assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());
- final String[] consumerTopics = {"consumer-out-0", "consumer-out-1", "consumer-out-2"};
- assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());
- } catch (final ParameterException e) {
- fail("This test should not throw an exception");
- }
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java
index df1960aa0..a80aa09c8 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java
@@ -21,6 +21,7 @@
package org.onap.policy.apex.service.engine.parameters;
+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;
@@ -39,37 +40,33 @@ import org.onap.policy.common.parameters.ParameterException;
*/
public class ProducerConsumerTests {
@Test
- public void testGoodParametersTest() {
+ public void testGoodParametersTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/goodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
-
- assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
- assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
- assertEquals(45, parameters.getEngineServiceParameters().getId());
- assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
- assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
- assertEquals("FILE", parameters.getEventOutputParameters().get("FirstProducer")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("JSON",
- parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters().getLabel());
- assertEquals("FILE", parameters.getEventOutputParameters().get("MyOtherProducer")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("JSON", parameters.getEventOutputParameters().get("MyOtherProducer")
- .getEventProtocolParameters().getLabel());
- assertEquals("FILE", parameters.getEventInputParameters().get("TheFileConsumer1")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("JSON", parameters.getEventInputParameters().get("TheFileConsumer1")
- .getEventProtocolParameters().getLabel());
- assertEquals("SUPER_DOOPER", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("SUPER_TOK_DEL", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
- .getEventProtocolParameters().getLabel());
- } catch (final ParameterException e) {
- fail("This test should not throw an exception");
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+
+ assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
+ assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
+ assertEquals(45, parameters.getEngineServiceParameters().getId());
+ assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
+ assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
+ assertEquals("FILE", parameters.getEventOutputParameters().get("FirstProducer")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("JSON",
+ parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters().getLabel());
+ assertEquals("FILE", parameters.getEventOutputParameters().get("MyOtherProducer")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("JSON", parameters.getEventOutputParameters().get("MyOtherProducer")
+ .getEventProtocolParameters().getLabel());
+ assertEquals("FILE", parameters.getEventInputParameters().get("TheFileConsumer1")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("JSON", parameters.getEventInputParameters().get("TheFileConsumer1")
+ .getEventProtocolParameters().getLabel());
+ assertEquals("SUPER_DOOPER", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("SUPER_TOK_DEL", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
+ .getEventProtocolParameters().getLabel());
}
@Test
@@ -77,20 +74,16 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsNoCT.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from \"src/test/resources/parameters/prodConsNoCT.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"aConsumer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
- + "event handler carrierTechnologyParameters not specified or blank\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/prodConsNoCT.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"aConsumer\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
+ + " parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
+ + "event handler carrierTechnologyParameters not specified or blank\n");
}
@Test
@@ -98,29 +91,25 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsNoEP.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from \"src/test/resources/parameters/prodConsNoEP.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
- + "event handler eventProtocolParameters not specified or blank\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"aConsumer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
- + "\"org.onap.policy.apex.service.engine.event.impl."
- + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
- + "\"null\" invalid, must be specified as a non-empty string\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/prodConsNoEP.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
+ + "event handler eventProtocolParameters not specified or blank\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"aConsumer\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
+ + "\"org.onap.policy.apex.service.engine.event.impl."
+ + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "\"null\" invalid, must be specified as a non-empty string\n");
}
@Test
@@ -128,14 +117,10 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsNoCTParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from \"src/test/resources/parameters/prodConsNoCTParClass.json\"\n"
- + "(ParameterRuntimeException):carrier technology \"SUPER_DOOPER\" "
- + "parameter \"parameterClassName\" value \"null\" invalid in JSON file", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from \"src/test/resources/parameters/prodConsNoCTParClass.json\"\n"
+ + "(ParameterRuntimeException):carrier technology \"SUPER_DOOPER\" "
+ + "parameter \"parameterClassName\" value \"null\" invalid in JSON file");
}
@Test
@@ -143,18 +128,14 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsMismatchCTParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/prodConsMismatchCTParClass.json\"\n"
- + "(ParameterRuntimeException):carrier technology \"SUPER_LOOPER\" "
- + "does not match plugin \"SUPER_DOOPER\" in \"" + "org.onap.policy.apex.service.engine."
- + "parameters.dummyclasses.SuperDooperCarrierTechnologyParameters"
- + "\", specify correct carrier technology parameter plugin "
- + "in parameter \"parameterClassName\"", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/prodConsMismatchCTParClass.json\"\n"
+ + "(ParameterRuntimeException):carrier technology \"SUPER_LOOPER\" "
+ + "does not match plugin \"SUPER_DOOPER\" in \"" + "org.onap.policy.apex.service.engine."
+ + "parameters.dummyclasses.SuperDooperCarrierTechnologyParameters"
+ + "\", specify correct carrier technology parameter plugin "
+ + "in parameter \"parameterClassName\"");
}
@Test
@@ -162,38 +143,31 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsWrongTypeCTParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/prodConsWrongTypeCTParClass.json\"\n"
- + "(ParameterRuntimeException):could not create default parameters for carrier technology "
- + "\"SUPER_DOOPER\"\n" + "class org.onap.policy.apex.service.engine.parameters.dummyclasses."
- + "SuperTokenDelimitedEventProtocolParameters cannot be cast to class "
- + "org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters (org.onap."
- + "policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters "
- + "and org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters are in"
- + " unnamed module of loader 'app')", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/prodConsWrongTypeCTParClass.json\"\n"
+ + "(ParameterRuntimeException):could not create default parameters for carrier technology "
+ + "\"SUPER_DOOPER\"\n" + "class org.onap.policy.apex.service.engine.parameters.dummyclasses."
+ + "SuperTokenDelimitedEventProtocolParameters cannot be cast to class "
+ + "org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters (org.onap."
+ + "policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters "
+ + "and org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters are in"
+ + " unnamed module of loader 'app')");
}
@Test
- public void testOkFileNameCarrierTechnology() {
+ public void testOkFileNameCarrierTechnology() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/prodConsOKFileName.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- final FileCarrierTechnologyParameters fileParams = (FileCarrierTechnologyParameters) parameters
- .getEventOutputParameters().get("aProducer").getCarrierTechnologyParameters();
- assertTrue(fileParams.getFileName().endsWith("target/aaa.json"));
- assertEquals(false, fileParams.isStandardError());
- assertEquals(false, fileParams.isStandardIo());
- assertEquals(false, fileParams.isStreamingMode());
- } catch (final ParameterException e) {
- fail("This test should not throw an exception");
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ final FileCarrierTechnologyParameters fileParams = (FileCarrierTechnologyParameters) parameters
+ .getEventOutputParameters().get("aProducer").getCarrierTechnologyParameters();
+ assertTrue(fileParams.getFileName().endsWith("target/aaa.json"));
+ assertEquals(false, fileParams.isStandardError());
+ assertEquals(false, fileParams.isStandardIo());
+ assertEquals(false, fileParams.isStreamingMode());
+
}
@Test
@@ -201,25 +175,21 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsBadFileName.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/prodConsBadFileName.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, parameter group has status INVALID\n" + " parameter group \"FILE\" type "
- + "\"org.onap.policy.apex.service.engine.event.impl."
- + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " field \"fileName\" type "
- + "\"java.lang.String\" value \"null\" INVALID, "
- + "\"null\" invalid, must be specified as a non-empty string\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/prodConsBadFileName.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
+ + "INVALID, parameter group has status INVALID\n" + " parameter group \"FILE\" type "
+ + "\"org.onap.policy.apex.service.engine.event.impl."
+ + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
+ + "parameter group has status INVALID\n" + " field \"fileName\" type "
+ + "\"java.lang.String\" value \"null\" INVALID, "
+ + "\"null\" invalid, must be specified as a non-empty string\n");
}
@Test
@@ -227,18 +197,12 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsBadEPParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals(
- "error reading parameters from \"src/test/resources/parameters/prodConsBadEPParClass.json\"\n"
- + "(ParameterRuntimeException):event protocol \"SUPER_TOK_DEL\" "
- + "does not match plugin \"JSON\" in \"org.onap.policy.apex.service.engine.event.impl"
- + ".jsonprotocolplugin.JsonEventProtocolParameters"
- + "\", specify correct event protocol parameter plugin in parameter \"parameterClassName\"",
- e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from \"src/test/resources/parameters/prodConsBadEPParClass.json\"\n"
+ + "(ParameterRuntimeException):event protocol \"SUPER_TOK_DEL\" "
+ + "does not match plugin \"JSON\" in \"org.onap.policy.apex.service.engine.event.impl"
+ + ".jsonprotocolplugin.JsonEventProtocolParameters"
+ + "\", specify correct event protocol parameter plugin in parameter \"parameterClassName\"");
}
@Test
@@ -246,14 +210,10 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsNoEPParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from \"src/test/resources/parameters/prodConsNoEPParClass.json\"\n"
- + "(ParameterRuntimeException):event protocol \"SUPER_TOK_DEL\" parameter "
- + "\"parameterClassName\" value \"null\" invalid in JSON file", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from \"src/test/resources/parameters/prodConsNoEPParClass.json\"\n"
+ + "(ParameterRuntimeException):event protocol \"SUPER_TOK_DEL\" parameter "
+ + "\"parameterClassName\" value \"null\" invalid in JSON file");
}
@Test
@@ -261,20 +221,14 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsMismatchEPParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals(
- "error reading parameters from "
- + "\"src/test/resources/parameters/prodConsMismatchEPParClass.json\"\n"
- + "(ParameterRuntimeException):event protocol \"SUPER_TOK_BEL\" "
- + "does not match plugin \"SUPER_TOK_DEL\" in "
- + "\"org.onap.policy.apex.service.engine.parameters.dummyclasses."
- + "SuperTokenDelimitedEventProtocolParameters\", "
- + "specify correct event protocol parameter plugin in parameter \"parameterClassName\"",
- e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/prodConsMismatchEPParClass.json\"\n"
+ + "(ParameterRuntimeException):event protocol \"SUPER_TOK_BEL\" "
+ + "does not match plugin \"SUPER_TOK_DEL\" in "
+ + "\"org.onap.policy.apex.service.engine.parameters.dummyclasses."
+ + "SuperTokenDelimitedEventProtocolParameters\", "
+ + "specify correct event protocol parameter plugin in parameter \"parameterClassName\"");
}
@Test
@@ -282,19 +236,15 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsWrongTypeEPParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/prodConsWrongTypeEPParClass.json\"\n"
- + "(ParameterRuntimeException):could not create default parameters for event protocol "
- + "\"SUPER_TOK_DEL\"\n" + "class org.onap.policy.apex.service.engine."
- + "parameters.dummyclasses.SuperDooperCarrierTechnologyParameters "
- + "cannot be cast to class org.onap.policy.apex.service."
- + "parameters.eventprotocol.EventProtocolParameters (org.onap.policy.apex.service.engine.parameters"
- + ".dummyclasses.SuperDooperCarrierTechnologyParameters and org.onap.policy.apex.service.parameters"
- + ".eventprotocol.EventProtocolParameters are in unnamed module of loader 'app')", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/prodConsWrongTypeEPParClass.json\"\n"
+ + "(ParameterRuntimeException):could not create default parameters for event protocol "
+ + "\"SUPER_TOK_DEL\"\n" + "class org.onap.policy.apex.service.engine."
+ + "parameters.dummyclasses.SuperDooperCarrierTechnologyParameters "
+ + "cannot be cast to class org.onap.policy.apex.service."
+ + "parameters.eventprotocol.EventProtocolParameters (org.onap.policy.apex.service.engine.parameters"
+ + ".dummyclasses.SuperDooperCarrierTechnologyParameters and org.onap.policy.apex.service.parameters"
+ + ".eventprotocol.EventProtocolParameters are in unnamed module of loader 'app')");
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java
index be2c22c93..91f8c6699 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java
@@ -21,9 +21,9 @@
package org.onap.policy.apex.service.engine.parameters;
+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.util.Arrays;
import org.junit.Test;
@@ -48,21 +48,17 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncBadParamsNoSyncWithPeer.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsNoSyncWithPeer.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", specified peered mode \"SYNCHRONOUS\" "
- + "peer is illegal on eventOutputParameters \"SyncProducer0\" \n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncBadParamsNoSyncWithPeer.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", specified peered mode \"SYNCHRONOUS\" "
+ + "peer is illegal on eventOutputParameters \"SyncProducer0\" \n");
}
@Test
@@ -70,21 +66,17 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncBadParamsNotSyncWithPeer.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsNotSyncWithPeer.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", specified peered mode \"SYNCHRONOUS\" peer is illegal "
- + "on eventOutputParameters \"SyncProducer0\" \n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncBadParamsNotSyncWithPeer.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", specified peered mode \"SYNCHRONOUS\" peer is illegal "
+ + "on eventOutputParameters \"SyncProducer0\" \n");
}
@Test
@@ -92,32 +84,28 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncBadParamsBadPeers.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsBadPeers.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS does not exist "
- + "or is not defined with the same peered mode\n" + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS does not exist "
- + "or is not defined with the same peered mode\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS does not exist "
- + "or is not defined with the same peered mode\n" + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS does not exist "
- + "or is not defined with the same peered mode\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncBadParamsBadPeers.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS does not exist "
+ + "or is not defined with the same peered mode\n" + " parameter group \"SyncProducer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS does not exist "
+ + "or is not defined with the same peered mode\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS does not exist "
+ + "or is not defined with the same peered mode\n" + " parameter group \"SyncConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS does not exist "
+ + "or is not defined with the same peered mode\n");
}
@Test
@@ -125,34 +113,30 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncBadParamsInvalidTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsInvalidTimeout.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " specified peered mode \"SYNCHRONOUS\" timeout value \"-10\" is illegal, "
- + "specify a non-negative timeout value in milliseconds\n"
- + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, specified peered mode \"SYNCHRONOUS\" timeout value \"-3\" is illegal, "
- + "specify a non-negative timeout value in milliseconds\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, specified peered mode \"SYNCHRONOUS\" timeout value \"-1\" is illegal, "
- + "specify a non-negative timeout value in milliseconds\n"
- + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " specified peered mode \"SYNCHRONOUS\" timeout value \"-99999999\" is illegal, "
- + "specify a non-negative timeout value in milliseconds\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncBadParamsInvalidTimeout.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
+ + " specified peered mode \"SYNCHRONOUS\" timeout value \"-10\" is illegal, "
+ + "specify a non-negative timeout value in milliseconds\n"
+ + " parameter group \"SyncProducer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
+ + "INVALID, specified peered mode \"SYNCHRONOUS\" timeout value \"-3\" is illegal, "
+ + "specify a non-negative timeout value in milliseconds\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
+ + "INVALID, specified peered mode \"SYNCHRONOUS\" timeout value \"-1\" is illegal, "
+ + "specify a non-negative timeout value in milliseconds\n"
+ + " parameter group \"SyncConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
+ + " specified peered mode \"SYNCHRONOUS\" timeout value \"-99999999\" is illegal, "
+ + "specify a non-negative timeout value in milliseconds\n");
}
@Test
@@ -160,21 +144,17 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncBadParamsBadTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsBadTimeout.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" "
- + "INVALID, parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"MyOtherProducer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, specified peered mode \"SYNCHRONOUS\" "
- + "timeout is illegal on eventOutputParameters \"MyOtherProducer\"\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncBadParamsBadTimeout.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" "
+ + "INVALID, parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"MyOtherProducer\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
+ + "INVALID, specified peered mode \"SYNCHRONOUS\" "
+ + "timeout is illegal on eventOutputParameters \"MyOtherProducer\"\n");
}
@Test
@@ -182,36 +162,30 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncBadParamsUnpairedTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals(
- "validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsUnpairedTimeout.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS timeout 10 on event handler "
- + "\"SyncProducer0\" does not equal timeout 1 on event handler \"SyncConsumer0\"\n"
- + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS timeout 3 on event handler "
- + "\"SyncProducer1\" does not equal timeout 99999999 on event handler \"SyncConsumer1\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS timeout 1 on event handler "
- + "\"SyncConsumer0\" does not equal timeout 10 on event handler \"SyncProducer0\"\n"
- + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS timeout 99999999 on event handler "
- + "\"SyncConsumer1\" does not equal timeout 3 on event handler \"SyncProducer1\"\n" + "",
- e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncBadParamsUnpairedTimeout.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS timeout 10 on event handler "
+ + "\"SyncProducer0\" does not equal timeout 1 on event handler \"SyncConsumer0\"\n"
+ + " parameter group \"SyncProducer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS timeout 3 on event handler "
+ + "\"SyncProducer1\" does not equal timeout 99999999 on event handler \"SyncConsumer1\"\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS timeout 1 on event handler "
+ + "\"SyncConsumer0\" does not equal timeout 10 on event handler \"SyncProducer0\"\n"
+ + " parameter group \"SyncConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS timeout 99999999 on event handler "
+ + "\"SyncConsumer1\" does not equal timeout 3 on event handler \"SyncProducer1\"\n" + "");
}
@Test
@@ -219,19 +193,16 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncGoodParamsProducerTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- } catch (final Exception e) {
- fail("This test should not throw an exception");
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+
}
@Test
@@ -239,19 +210,16 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncGoodParamsConsumerTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- } catch (final Exception e) {
- fail("This test should not throw an exception");
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+
}
@Test
@@ -259,19 +227,16 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncGoodParamsBothTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- } catch (final Exception e) {
- fail("This test should not throw an exception");
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+
}
@Test
@@ -279,28 +244,24 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncUnusedConsumerPeers.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncUnusedConsumerPeers.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, peer \"SyncConsumer0 for peered mode SYNCHRONOUS, "
- + "value \"SyncProducer0\" on peer \"SyncConsumer0\" "
- + "does not equal event handler \"SyncProducer1\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, peer \"SyncProducer1 for peered mode SYNCHRONOUS, "
- + "value \"SyncConsumer0\" on peer \"SyncProducer1\" "
- + "does not equal event handler \"SyncConsumer1\"\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncUnusedConsumerPeers.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
+ + "INVALID, peer \"SyncConsumer0 for peered mode SYNCHRONOUS, "
+ + "value \"SyncProducer0\" on peer \"SyncConsumer0\" "
+ + "does not equal event handler \"SyncProducer1\"\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
+ + "INVALID, peer \"SyncProducer1 for peered mode SYNCHRONOUS, "
+ + "value \"SyncConsumer0\" on peer \"SyncProducer1\" "
+ + "does not equal event handler \"SyncConsumer1\"\n");
}
@Test
@@ -308,36 +269,30 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncMismatchedPeers.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals(
- "validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncMismatchedPeers.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS, value \"SyncProducer1\" "
- + "on peer \"SyncConsumer1\" does not equal event handler \"SyncProducer0\"\n"
- + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS, value \"SyncProducer0\" "
- + "on peer \"SyncConsumer0\" does not equal event handler \"SyncProducer1\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS, value \"SyncConsumer1\" "
- + "on peer \"SyncProducer0\" does not equal event handler \"SyncConsumer0\"\n"
- + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS, value \"SyncConsumer0\" "
- + "on peer \"SyncProducer1\" does not equal event handler \"SyncConsumer1\"\n",
- e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncMismatchedPeers.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS, value \"SyncProducer1\" "
+ + "on peer \"SyncConsumer1\" does not equal event handler \"SyncProducer0\"\n"
+ + " parameter group \"SyncProducer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS, value \"SyncProducer0\" "
+ + "on peer \"SyncConsumer0\" does not equal event handler \"SyncProducer1\"\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS, value \"SyncConsumer1\" "
+ + "on peer \"SyncProducer0\" does not equal event handler \"SyncConsumer0\"\n"
+ + " parameter group \"SyncConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS, value \"SyncConsumer0\" "
+ + "on peer \"SyncProducer1\" does not equal event handler \"SyncConsumer1\"\n");
}
@Test
@@ -345,26 +300,22 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncUnusedProducerPeers.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncUnusedProducerPeers.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS, value \"SyncProducer1\" on peer "
- + "\"SyncConsumer0\" does not equal event handler \"SyncProducer0\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, parameter group map has status "
- + "INVALID\n parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS, value \"SyncConsumer1\" on peer "
- + "\"SyncProducer1\" does not equal event handler \"SyncConsumer0\"\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncUnusedProducerPeers.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS, value \"SyncProducer1\" on peer "
+ + "\"SyncConsumer0\" does not equal event handler \"SyncProducer0\"\n"
+ + " parameter group map \"eventInputParameters\" INVALID, parameter group map has status "
+ + "INVALID\n parameter group \"SyncConsumer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS, value \"SyncConsumer1\" on peer "
+ + "\"SyncProducer1\" does not equal event handler \"SyncConsumer0\"\n");
}
@Test
@@ -372,100 +323,92 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncMismatchedTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncMismatchedTimeout.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group map \"eventOutputParameters\" "
- + "INVALID, parameter group map has status INVALID\n"
- + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " peer \"SyncConsumer1 for peered mode SYNCHRONOUS timeout 456 "
- + "on event handler \"SyncProducer1\" does not equal timeout 123 "
- + "on event handler \"SyncConsumer1\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " peer \"SyncProducer1 for peered mode SYNCHRONOUS timeout 123 "
- + "on event handler \"SyncConsumer1\" does not equal timeout 456 "
- + "on event handler \"SyncProducer1\"\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncMismatchedTimeout.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n" + " parameter group map \"eventOutputParameters\" "
+ + "INVALID, parameter group map has status INVALID\n"
+ + " parameter group \"SyncProducer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
+ + " peer \"SyncConsumer1 for peered mode SYNCHRONOUS timeout 456 "
+ + "on event handler \"SyncProducer1\" does not equal timeout 123 "
+ + "on event handler \"SyncConsumer1\"\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
+ + " peer \"SyncProducer1 for peered mode SYNCHRONOUS timeout 123 "
+ + "on event handler \"SyncConsumer1\" does not equal timeout 456 "
+ + "on event handler \"SyncProducer1\"\n");
}
@Test
- public void testSyncGoodParametersTest() {
+ public void testSyncGoodParametersTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/syncGoodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
-
- assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
- assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
- assertEquals(45, parameters.getEngineServiceParameters().getId());
- assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
- assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
-
- final CarrierTechnologyParameters prodCT0 =
- parameters.getEventOutputParameters().get("SyncProducer0").getCarrierTechnologyParameters();
- final EventProtocolParameters prodEP0 =
- parameters.getEventOutputParameters().get("SyncProducer0").getEventProtocolParameters();
- final CarrierTechnologyParameters consCT0 =
- parameters.getEventInputParameters().get("SyncConsumer0").getCarrierTechnologyParameters();
- final EventProtocolParameters consEP0 =
- parameters.getEventInputParameters().get("SyncConsumer0").getEventProtocolParameters();
- final CarrierTechnologyParameters prodCT1 =
- parameters.getEventOutputParameters().get("SyncProducer1").getCarrierTechnologyParameters();
- final EventProtocolParameters prodEP1 =
- parameters.getEventOutputParameters().get("SyncProducer1").getEventProtocolParameters();
- final CarrierTechnologyParameters consCT1 =
- parameters.getEventInputParameters().get("SyncConsumer1").getCarrierTechnologyParameters();
- final EventProtocolParameters consEP1 =
- parameters.getEventInputParameters().get("SyncConsumer1").getEventProtocolParameters();
-
- assertEquals("FILE", prodCT0.getLabel());
- assertEquals("JSON", prodEP0.getLabel());
- assertEquals("FILE", consCT0.getLabel());
- assertEquals("JSON", consEP0.getLabel());
- assertEquals("FILE", prodCT1.getLabel());
- assertEquals("JSON", prodEP1.getLabel());
- assertEquals("SUPER_DOOPER", consCT1.getLabel());
- assertEquals("SUPER_TOK_DEL", consEP1.getLabel());
-
- assertTrue(consCT1 instanceof SuperDooperCarrierTechnologyParameters);
- assertTrue(consEP1 instanceof SuperTokenDelimitedEventProtocolParameters);
-
- final SuperDooperCarrierTechnologyParameters superDooperParameters =
- (SuperDooperCarrierTechnologyParameters) consCT1;
- assertEquals("localhost:9092", superDooperParameters.getBootstrapServers());
- assertEquals("all", superDooperParameters.getAcks());
- assertEquals(0, superDooperParameters.getRetries());
- assertEquals(16384, superDooperParameters.getBatchSize());
- assertEquals(1, superDooperParameters.getLingerTime());
- assertEquals(33554432, superDooperParameters.getBufferMemory());
- assertEquals("default-group-id", superDooperParameters.getGroupId());
- assertTrue(superDooperParameters.isEnableAutoCommit());
- assertEquals(1000, superDooperParameters.getAutoCommitTime());
- assertEquals(30000, superDooperParameters.getSessionTimeout());
- assertEquals("apex-out", superDooperParameters.getProducerTopic());
- assertEquals(100, superDooperParameters.getConsumerPollTime());
- assertEquals("org.apache.superDooper.common.serialization.StringSerializer",
- superDooperParameters.getKeySerializer());
- assertEquals("org.apache.superDooper.common.serialization.StringSerializer",
- superDooperParameters.getValueSerializer());
- assertEquals("org.apache.superDooper.common.serialization.StringDeserializer",
- superDooperParameters.getKeyDeserializer());
- assertEquals("org.apache.superDooper.common.serialization.StringDeserializer",
- superDooperParameters.getValueDeserializer());
-
- final String[] consumerTopics = {"apex-in"};
- assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());
- } catch (final ParameterException e) {
- fail("This test should not throw an exception");
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+
+ assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
+ assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
+ assertEquals(45, parameters.getEngineServiceParameters().getId());
+ assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
+ assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
+
+ final CarrierTechnologyParameters prodCT0 =
+ parameters.getEventOutputParameters().get("SyncProducer0").getCarrierTechnologyParameters();
+ final EventProtocolParameters prodEP0 =
+ parameters.getEventOutputParameters().get("SyncProducer0").getEventProtocolParameters();
+ final CarrierTechnologyParameters consCT0 =
+ parameters.getEventInputParameters().get("SyncConsumer0").getCarrierTechnologyParameters();
+ final EventProtocolParameters consEP0 =
+ parameters.getEventInputParameters().get("SyncConsumer0").getEventProtocolParameters();
+ final CarrierTechnologyParameters prodCT1 =
+ parameters.getEventOutputParameters().get("SyncProducer1").getCarrierTechnologyParameters();
+ final EventProtocolParameters prodEP1 =
+ parameters.getEventOutputParameters().get("SyncProducer1").getEventProtocolParameters();
+ final CarrierTechnologyParameters consCT1 =
+ parameters.getEventInputParameters().get("SyncConsumer1").getCarrierTechnologyParameters();
+ final EventProtocolParameters consEP1 =
+ parameters.getEventInputParameters().get("SyncConsumer1").getEventProtocolParameters();
+
+ assertEquals("FILE", prodCT0.getLabel());
+ assertEquals("JSON", prodEP0.getLabel());
+ assertEquals("FILE", consCT0.getLabel());
+ assertEquals("JSON", consEP0.getLabel());
+ assertEquals("FILE", prodCT1.getLabel());
+ assertEquals("JSON", prodEP1.getLabel());
+ assertEquals("SUPER_DOOPER", consCT1.getLabel());
+ assertEquals("SUPER_TOK_DEL", consEP1.getLabel());
+
+ assertTrue(consCT1 instanceof SuperDooperCarrierTechnologyParameters);
+ assertTrue(consEP1 instanceof SuperTokenDelimitedEventProtocolParameters);
+
+ final SuperDooperCarrierTechnologyParameters superDooperParameters =
+ (SuperDooperCarrierTechnologyParameters) consCT1;
+ assertEquals("localhost:9092", superDooperParameters.getBootstrapServers());
+ assertEquals("all", superDooperParameters.getAcks());
+ assertEquals(0, superDooperParameters.getRetries());
+ assertEquals(16384, superDooperParameters.getBatchSize());
+ assertEquals(1, superDooperParameters.getLingerTime());
+ assertEquals(33554432, superDooperParameters.getBufferMemory());
+ assertEquals("default-group-id", superDooperParameters.getGroupId());
+ assertTrue(superDooperParameters.isEnableAutoCommit());
+ assertEquals(1000, superDooperParameters.getAutoCommitTime());
+ assertEquals(30000, superDooperParameters.getSessionTimeout());
+ assertEquals("apex-out", superDooperParameters.getProducerTopic());
+ assertEquals(100, superDooperParameters.getConsumerPollTime());
+ assertEquals("org.apache.superDooper.common.serialization.StringSerializer",
+ superDooperParameters.getKeySerializer());
+ assertEquals("org.apache.superDooper.common.serialization.StringSerializer",
+ superDooperParameters.getValueSerializer());
+ assertEquals("org.apache.superDooper.common.serialization.StringDeserializer",
+ superDooperParameters.getKeyDeserializer());
+ assertEquals("org.apache.superDooper.common.serialization.StringDeserializer",
+ superDooperParameters.getValueDeserializer());
+
+ final String[] consumerTopics = {"apex-in"};
+ assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());
}
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
index 4b79dc589..d39cbecf0 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * 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.services.onappf.parameters;
+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.FileNotFoundException;
import org.junit.Test;
@@ -44,13 +45,9 @@ public class TestApexStarterParameterHandler {
final ApexStarterCommandLineArguments emptyArguments = new ApexStarterCommandLineArguments();
emptyArguments.parse(emptyArgumentString);
- try {
- new ApexStarterParameterHandler().getParameters(emptyArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getCause() instanceof CoderException);
- assertTrue(e.getCause().getCause() instanceof FileNotFoundException);
- }
+ assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(emptyArguments))
+ .hasCauseInstanceOf(CoderException.class)
+ .hasRootCauseInstanceOf(FileNotFoundException.class);
}
@Test
@@ -60,12 +57,8 @@ public class TestApexStarterParameterHandler {
final ApexStarterCommandLineArguments noArguments = new ApexStarterCommandLineArguments();
noArguments.parse(noArgumentString);
- try {
- new ApexStarterParameterHandler().getParameters(noArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("no parameters found"));
- }
+ assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(noArguments))
+ .hasMessageContaining("no parameters found");
}
@Test
@@ -75,13 +68,9 @@ public class TestApexStarterParameterHandler {
final ApexStarterCommandLineArguments invalidArguments = new ApexStarterCommandLineArguments();
invalidArguments.parse(invalidArgumentString);
- try {
- new ApexStarterParameterHandler().getParameters(invalidArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().startsWith("error reading parameters from"));
- assertTrue(e.getCause() instanceof CoderException);
- }
+ assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(invalidArguments))
+ .hasMessageStartingWith("error reading parameters from")
+ .hasCauseInstanceOf(CoderException.class);
}
@Test
@@ -91,11 +80,8 @@ public class TestApexStarterParameterHandler {
final ApexStarterCommandLineArguments noArguments = new ApexStarterCommandLineArguments();
noArguments.parse(noArgumentString);
- try {
- new ApexStarterParameterHandler().getParameters(noArguments);
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("is null"));
- }
+ assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(noArguments))
+ .hasMessageContaining("is null");
}
@Test
@@ -118,13 +104,9 @@ public class TestApexStarterParameterHandler {
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
arguments.parse(apexStarterConfigParameters);
- try {
- new ApexStarterParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains(
- "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string"));
- }
+ assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(arguments))
+ .hasMessageContaining("field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a "
+ + "non-blank string");
}
@Test
@@ -147,10 +129,7 @@ public class TestApexStarterParameterHandler {
public void testApexStarterInvalidOption() throws ApexStarterException {
final String[] apexStarterConfigParameters = { "-d" };
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
- try {
- arguments.parse(apexStarterConfigParameters);
- } catch (final Exception exp) {
- assertTrue(exp.getMessage().startsWith("invalid command line arguments specified"));
- }
+ assertThatThrownBy(() -> arguments.parse(apexStarterConfigParameters))
+ .hasMessageStartingWith("invalid command line arguments specified");
}
}