summaryrefslogtreecommitdiffstats
path: root/services/services-engine/src/test
diff options
context:
space:
mode:
authorarkadiusz.adamski <aadamski@est.tech>2021-04-01 12:43:14 +0100
committerAjith Sreekumar <ajith.sreekumar@bell.ca>2021-04-15 15:46:06 +0000
commit5e3ab868b8e1d34147a4895983a24d45090bdddd (patch)
tree1bee763455b4f22d9c090dd0cb4801e526eba9c9 /services/services-engine/src/test
parentbb9e0b8decf9cc6e6c5ce3eca0bf62e5ddcf68fe (diff)
Code coverage for service engine event package
- Increase code coverage for service engine event package Issue-ID: POLICY-3092 Signed-off-by: arkadiusz.adamski <aadamski@est.tech> Change-Id: Iaed5fc31f242a47dd1dc46f5d5c74c43c720e9ee
Diffstat (limited to 'services/services-engine/src/test')
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PeeredReferenceTest.java57
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactoryTest.java83
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactoryTest.java83
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactoryTest.java70
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java180
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/ApexEventProtocolParametersTest.java50
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java100
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java43
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumerTest.java86
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorProducerTest.java161
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockReaderFactoryTest.java79
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockTest.java57
12 files changed, 1049 insertions, 0 deletions
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PeeredReferenceTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PeeredReferenceTest.java
new file mode 100644
index 000000000..cadb5c8a1
--- /dev/null
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PeeredReferenceTest.java
@@ -0,0 +1,57 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.ApexFileEventConsumer;
+import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.producer.ApexFileEventProducer;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+public class PeeredReferenceTest {
+
+ @Test
+ public void getPeeredConsumer() {
+ final ApexFileEventConsumer eventConsumer = new ApexFileEventConsumer();
+ final ApexFileEventProducer eventProducer = new ApexFileEventProducer();
+ final EventHandlerPeeredMode peeredMode = EventHandlerPeeredMode.REQUESTOR;
+ final PeeredReference peeredReference =
+ new PeeredReference(peeredMode, eventConsumer, eventProducer);
+
+ final ApexEventConsumer actual = peeredReference.getPeeredConsumer();
+ assertNotNull(actual);
+ assertEquals(peeredReference, actual.getPeeredReference(peeredMode));
+ }
+
+ @Test
+ public void getPeeredProducer() {
+ final ApexEventConsumer eventConsumer = new ApexFileEventConsumer();
+ final ApexEventProducer eventProducer = new ApexFileEventProducer();
+ final EventHandlerPeeredMode peeredMode = EventHandlerPeeredMode.SYNCHRONOUS;
+ final PeeredReference reference =
+ new PeeredReference(peeredMode, eventConsumer, eventProducer);
+
+ final ApexEventProducer actual = reference.getPeeredProducer();
+ assertNotNull(actual);
+ assertEquals(reference, actual.getPeeredReference(peeredMode));
+ }
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactoryTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactoryTest.java
new file mode 100644
index 000000000..976376e5a
--- /dev/null
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactoryTest.java
@@ -0,0 +1,83 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.impl;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEventConsumer;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperCarrierTechnologyParameters;
+import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+
+public class EventConsumerFactoryTest {
+ private EventConsumerFactory factory;
+
+ @Before
+ public void setUp() throws Exception {
+ factory = new EventConsumerFactory();
+ }
+
+ @Test
+ public void createConsumerNoTechnologyParameter() {
+ final String name = RandomStringUtils.randomAlphabetic(6);
+ final EventHandlerParameters parameters = new EventHandlerParameters();
+
+ assertThatThrownBy(() -> factory.createConsumer(name, parameters))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ public void createConsumerNoConsumerPlugin() {
+ final String name = RandomStringUtils.randomAlphabetic(6);
+ final EventHandlerParameters parameters = new EventHandlerParameters();
+ parameters.setCarrierTechnologyParameters(new RestPluginCarrierTechnologyParameters());
+
+ assertThatThrownBy(() -> factory.createConsumer(name, parameters))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void createConsumerWrongPluginClassName() {
+ final String name = RandomStringUtils.randomAlphabetic(6);
+ final EventHandlerParameters parameters = new EventHandlerParameters();
+ final RestPluginCarrierTechnologyParameters technologyParameters =
+ new RestPluginCarrierTechnologyParameters();
+ technologyParameters.setEventConsumerPluginClass("java.lang.Object");
+ parameters.setCarrierTechnologyParameters(technologyParameters);
+
+ assertThatThrownBy(() -> factory.createConsumer(name, parameters))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void createConsumer() throws ApexEventException {
+ final String name = RandomStringUtils.randomAlphabetic(6);
+ final EventHandlerParameters parameters = new EventHandlerParameters();
+ parameters.setCarrierTechnologyParameters(new SuperDooperCarrierTechnologyParameters());
+
+ final ApexEventConsumer actual = factory.createConsumer(name, parameters);
+ assertNotNull(actual);
+ }
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactoryTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactoryTest.java
new file mode 100644
index 000000000..7e3cb5478
--- /dev/null
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactoryTest.java
@@ -0,0 +1,83 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.impl;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventProducer;
+import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperCarrierTechnologyParameters;
+import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+
+public class EventProducerFactoryTest {
+ private EventProducerFactory factory;
+
+ @Before
+ public void setUp() throws Exception {
+ factory = new EventProducerFactory();
+ }
+
+ @Test
+ public void createConsumerNoTechnologyParameter() {
+ final EventHandlerParameters parameters = new EventHandlerParameters();
+ final String name = RandomStringUtils.randomAlphabetic(4);
+
+ assertThatThrownBy(() -> factory.createProducer(name, parameters))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ public void createConsumerNoConsumerPlugin() {
+ final EventHandlerParameters parameters = new EventHandlerParameters();
+ final String name = RandomStringUtils.randomAlphabetic(4);
+ parameters.setCarrierTechnologyParameters(new RestPluginCarrierTechnologyParameters());
+
+ assertThatThrownBy(() -> factory.createProducer(name, parameters))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void createConsumerWrongProducerPluginName() {
+ final EventHandlerParameters parameters = new EventHandlerParameters();
+ final RestPluginCarrierTechnologyParameters technologyParameters =
+ new RestPluginCarrierTechnologyParameters();
+ final String name = RandomStringUtils.randomAlphabetic(4);
+ technologyParameters.setEventProducerPluginClass("java.lang.Object");
+ parameters.setCarrierTechnologyParameters(technologyParameters);
+
+ assertThatThrownBy(() -> factory.createProducer(name, parameters))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void createConsumer() throws ApexEventException {
+ final EventHandlerParameters parameters = new EventHandlerParameters();
+ parameters.setCarrierTechnologyParameters(new SuperDooperCarrierTechnologyParameters());
+ final String name = RandomStringUtils.randomAlphabetic(4);
+
+ final ApexEventProducer actual = factory.createProducer(name, parameters);
+ assertNotNull(actual);
+ }
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactoryTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactoryTest.java
new file mode 100644
index 000000000..8ed3a9fec
--- /dev/null
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactoryTest.java
@@ -0,0 +1,70 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.impl;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEventProtocolConverter;
+import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+import org.onap.policy.apex.service.engine.event.impl.apexprotocolplugin.ApexEventProtocolParameters;
+import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters;
+import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters;
+
+public class EventProtocolFactoryTest {
+ private EventProtocolFactory factory;
+
+ @Before
+ public void setUp() throws Exception {
+ factory = new EventProtocolFactory();
+ }
+
+ @Test
+ public void createConsumerNoConsumerPlugin() {
+ final EventProtocolParameters parameters = new ApexEventProtocolParameters();
+ parameters.setEventProtocolPluginClass("");
+ final String name = RandomStringUtils.randomAlphabetic(9);
+
+ assertThatThrownBy(() -> factory.createConverter(name, parameters))
+ .isInstanceOf(ApexEventRuntimeException.class);
+ }
+
+ @Test
+ public void createConsumer2() {
+ final EventProtocolParameters parameters = new ApexEventProtocolParameters();
+ final String name = RandomStringUtils.randomAlphabetic(9);
+ parameters.setEventProtocolPluginClass("java.lang.Object");
+
+ assertThatThrownBy(() -> factory.createConverter(name, parameters))
+ .isInstanceOf(ApexEventRuntimeException.class);
+ }
+
+ @Test
+ public void createConsumer() {
+ final EventProtocolParameters parameters = new JsonEventProtocolParameters();
+ final String name = RandomStringUtils.randomAlphabetic(9);
+
+ final ApexEventProtocolConverter actual = factory.createConverter(name, parameters);
+ assertNotNull(actual);
+ }
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java
new file mode 100644
index 000000000..04e87ee42
--- /dev/null
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java
@@ -0,0 +1,180 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.impl.apexprotocolplugin;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatNoException;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertSame;
+
+import java.util.List;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEvent;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventList;
+import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+
+public class Apex2ApexEventConverterTest {
+ private Apex2ApexEventConverter converter;
+
+ @Before
+ public void setUp() throws Exception {
+ converter = new Apex2ApexEventConverter();
+ }
+
+ @Test
+ public void initWithNull() {
+ assertThatThrownBy(() -> converter.init(null))
+ .isInstanceOf(ApexEventRuntimeException.class);
+ }
+
+ @Test
+ public void init() {
+ assertThatNoException()
+ .isThrownBy(() -> converter.init(new ApexEventProtocolParameters()));
+ }
+
+ @Test
+ public void toApexEventWithNull() {
+ final String eventName = RandomStringUtils.randomAlphanumeric(5);
+ assertThatThrownBy(() -> converter.toApexEvent(eventName, null))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void toApexEventWithNonApexEvent() {
+ final String eventName = RandomStringUtils.randomAlphanumeric(5);
+ assertThatThrownBy(() -> converter.toApexEvent(eventName, new Object()))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void toApexEmptyEvent() throws ApexEventException {
+ final String eventName = RandomStringUtils.randomAlphanumeric(4);
+ final String name = RandomStringUtils.randomAlphanumeric(5);
+ final String version = RandomStringUtils.randomAlphanumeric(6);
+ final String nameSpace = "a" + RandomStringUtils.randomAlphanumeric(7);
+ final String source = RandomStringUtils.randomAlphanumeric(8);
+ final String target = RandomStringUtils.randomAlphanumeric(9);
+
+ final ApexEvent event = new ApexEvent(name, version, nameSpace, source, target);
+ final List<ApexEvent> result = converter.toApexEvent(eventName, event);
+ assertThat(result).isEmpty();
+ }
+
+ @Test
+ public void toApexEventWithApexAndOtherFields() throws ApexEventException {
+ final String eventName = RandomStringUtils.randomAlphanumeric(4);
+ final String name1 = RandomStringUtils.randomAlphanumeric(5);
+ final String version1 = RandomStringUtils.randomAlphanumeric(6);
+ final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
+ final String source1 = RandomStringUtils.randomAlphanumeric(8);
+ final String target1 = RandomStringUtils.randomAlphanumeric(9);
+
+ final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1);
+
+ final String key = RandomStringUtils.randomAlphabetic(3);
+ event.put(key, new Object());
+ final List<ApexEvent> result = converter.toApexEvent(eventName, event);
+ Object[] expected = {event};
+ assertArrayEquals(expected, result.toArray());
+ }
+
+ @Test
+ public void toApexEventWithApexAndList() throws ApexEventException {
+ final String eventName = RandomStringUtils.randomAlphanumeric(4);
+ final String name1 = RandomStringUtils.randomAlphanumeric(5);
+ final String version1 = RandomStringUtils.randomAlphanumeric(6);
+ final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
+ final String source1 = RandomStringUtils.randomAlphanumeric(8);
+ final String target1 = RandomStringUtils.randomAlphanumeric(9);
+
+ final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1);
+
+ final ApexEventList eventList = new ApexEventList();
+ eventList.add(event);
+
+ final String name2 = RandomStringUtils.randomAlphanumeric(15);
+ final String version2 = RandomStringUtils.randomAlphanumeric(16);
+ final String nameSpace2 = "b" + RandomStringUtils.randomAlphanumeric(17);
+ final String source2 = RandomStringUtils.randomAlphanumeric(18);
+ final String target2 = RandomStringUtils.randomAlphanumeric(19);
+
+ final ApexEvent parentEvent = new ApexEvent(name2, version2, nameSpace2, source2, target2);
+ final String key = RandomStringUtils.randomAlphabetic(3);
+ parentEvent.put(key, eventList);
+ final List<ApexEvent> result = converter.toApexEvent(eventName, parentEvent);
+ Object[] expected = {event};
+ assertArrayEquals(expected, result.toArray());
+ }
+
+ @Test
+ public void toApexEventWithApexAndListAndOtherFields() throws ApexEventException {
+ final String eventName = RandomStringUtils.randomAlphanumeric(4);
+ final String name1 = RandomStringUtils.randomAlphanumeric(5);
+ final String version1 = RandomStringUtils.randomAlphanumeric(6);
+ final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
+ final String source1 = RandomStringUtils.randomAlphanumeric(8);
+ final String target1 = RandomStringUtils.randomAlphanumeric(9);
+
+ final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1);
+
+ final ApexEventList eventList = new ApexEventList();
+ eventList.add(event);
+
+ final String name2 = RandomStringUtils.randomAlphanumeric(15);
+ final String version2 = RandomStringUtils.randomAlphanumeric(16);
+ final String nameSpace2 = "b" + RandomStringUtils.randomAlphanumeric(17);
+ final String source2 = RandomStringUtils.randomAlphanumeric(18);
+ final String target2 = RandomStringUtils.randomAlphanumeric(19);
+
+ final ApexEvent parentEvent = new ApexEvent(name2, version2, nameSpace2, source2, target2);
+ final String key1 = RandomStringUtils.randomAlphabetic(3);
+ final String key2 = RandomStringUtils.randomAlphabetic(2);
+ parentEvent.put(key1, eventList);
+ parentEvent.put(key2, new Object());
+ assertThatThrownBy(() -> converter.toApexEvent(eventName, parentEvent))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void fromApexEventNull() {
+ assertThatThrownBy(() -> converter.fromApexEvent(null))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void fromApexEvent() throws ApexEventException {
+ final String name1 = RandomStringUtils.randomAlphanumeric(5);
+ final String version1 = RandomStringUtils.randomAlphanumeric(6);
+ final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
+ final String source1 = RandomStringUtils.randomAlphanumeric(8);
+ final String target1 = RandomStringUtils.randomAlphanumeric(9);
+
+ final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1);
+
+ final Object actual = converter.fromApexEvent(event);
+ assertSame(event, actual);
+ }
+
+}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/ApexEventProtocolParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/ApexEventProtocolParametersTest.java
new file mode 100644
index 000000000..8b39b0a74
--- /dev/null
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/ApexEventProtocolParametersTest.java
@@ -0,0 +1,50 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.impl.apexprotocolplugin;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Test;
+
+public class ApexEventProtocolParametersTest {
+
+ @Test
+ public void testNoArgConstructor() {
+ final ApexEventProtocolParameters apexEventProtocolParameters = new ApexEventProtocolParameters();
+ final String actual = apexEventProtocolParameters.getLabel();
+ final String pluginClass = apexEventProtocolParameters.getEventProtocolPluginClass();
+
+ assertEquals(ApexEventProtocolParameters.APEX_EVENT_PROTOCOL_LABEL, actual);
+ assertEquals(Apex2ApexEventConverter.class.getName(), pluginClass);
+ }
+
+ @Test
+ public void testConstructor() {
+ final String expected = RandomStringUtils.randomAlphabetic(6);
+ final ApexEventProtocolParameters apexEventProtocolParameters = new ApexEventProtocolParameters(expected);
+ final String actual = apexEventProtocolParameters.getLabel();
+ final String pluginClass = apexEventProtocolParameters.getEventProtocolPluginClass();
+
+ assertEquals(expected, actual);
+ assertEquals(Apex2ApexEventConverter.class.getName(), pluginClass);
+ }
+
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java
new file mode 100644
index 000000000..562760f69
--- /dev/null
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java
@@ -0,0 +1,100 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.impl.enevent;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertArrayEquals;
+
+import java.util.List;
+import java.util.Random;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.core.engine.event.EnEvent;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
+import org.onap.policy.apex.service.engine.event.ApexEvent;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+
+public class ApexEvent2EnEventConverterTest {
+ private ApexEvent2EnEventConverter converter;
+ private final Random random = new Random();
+
+ @Before
+ public void setUp() throws Exception {
+ converter = new ApexEvent2EnEventConverter(null);
+ }
+
+ @Test
+ public void toApexEventNull() {
+ final String eventName = RandomStringUtils.randomAlphabetic(3);
+ assertThatThrownBy(() -> converter.toApexEvent(eventName, null))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void toApexEventWrongClass() throws ApexException {
+ final String eventName = RandomStringUtils.randomAlphabetic(3);
+ final String name = RandomStringUtils.randomAlphanumeric(5);
+ final String version = RandomStringUtils.randomAlphanumeric(6);
+ final String nameSpace = "a" + RandomStringUtils.randomAlphanumeric(7);
+ final String source = RandomStringUtils.randomAlphanumeric(8);
+ final String target = RandomStringUtils.randomAlphanumeric(9);
+
+ final ApexEvent event = new ApexEvent(name, version, nameSpace, source, target);
+
+ assertThatThrownBy(() -> converter.toApexEvent(eventName, event))
+ .isInstanceOf(ApexEventRuntimeException.class);
+ }
+
+ @Test
+ public void toApex() throws ApexException {
+ // prepare String values for events
+ final String name = RandomStringUtils.randomAlphabetic(5);
+ final String version = RandomStringUtils.randomAlphabetic(6);
+ final String nameSpace = "b" + RandomStringUtils.randomAlphabetic(7);
+ final String source = RandomStringUtils.randomAlphabetic(8);
+ final String target = RandomStringUtils.randomAlphabetic(9);
+ final int executionId = random.nextInt(1000);
+ final String exceptionMessage = RandomStringUtils.randomAlphabetic(11);
+
+ // prepare events
+ final AxEvent axEvent = new AxEvent();
+ axEvent.getKey().setName(name);
+ axEvent.getKey().setVersion(version);
+ axEvent.setNameSpace(nameSpace);
+ axEvent.setSource(source);
+ axEvent.setTarget(target);
+ final EnEvent enEvent = new EnEvent(axEvent);
+ enEvent.setExecutionId(executionId);
+ enEvent.setExceptionMessage(exceptionMessage);
+
+ // prepare expected event
+ final ApexEvent apexEvent = new ApexEvent(name, version, nameSpace, source, target);
+ apexEvent.setExecutionId(executionId);
+ apexEvent.setExceptionMessage(exceptionMessage);
+ final Object[] expected = {apexEvent};
+
+ // Test
+ final List<ApexEvent> actual = converter.toApexEvent(RandomStringUtils.randomAlphabetic(3), enEvent);
+ assertArrayEquals(expected, actual.toArray());
+ }
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java
new file mode 100644
index 000000000..c0da81625
--- /dev/null
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java
@@ -0,0 +1,43 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.impl.eventrequestor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+public class EventRequestorCarrierTechnologyParametersTest {
+
+ @Test
+ public void getName() {
+ final EventRequestorCarrierTechnologyParameters parameters = new EventRequestorCarrierTechnologyParameters();
+ final String actual = parameters.getName();
+ assertEquals(EventRequestorCarrierTechnologyParameters.EVENT_REQUESTOR_CARRIER_TECHNOLOGY_LABEL, actual);
+ }
+
+ @Test
+ public void validate() {
+ final EventRequestorCarrierTechnologyParameters parameters = new EventRequestorCarrierTechnologyParameters();
+ final GroupValidationResult actual = parameters.validate();
+ assertNotNull(actual);
+ }
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumerTest.java
new file mode 100644
index 000000000..dd44da7dd
--- /dev/null
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumerTest.java
@@ -0,0 +1,86 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.impl.eventrequestor;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.PeeredReference;
+import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.ApexFileEventConsumer;
+import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.producer.ApexFileEventProducer;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+public class EventRequestorConsumerTest {
+ private EventRequestorConsumer consumer;
+
+ @Before
+ public void setUp() throws Exception {
+ consumer = new EventRequestorConsumer();
+ }
+
+ @Test
+ public void initNoCarrierTechnologyParameters() {
+ final String consumerName = RandomStringUtils.randomAlphabetic(6);
+ final EventHandlerParameters eventHandlerParameters = new EventHandlerParameters();
+
+ assertThatThrownBy(() -> consumer.init(consumerName, eventHandlerParameters, null))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void initNoPeered() {
+ final String consumerName = RandomStringUtils.randomAlphabetic(6);
+ final EventHandlerParameters eventHandlerParameters = new EventHandlerParameters();
+ eventHandlerParameters.setCarrierTechnologyParameters(new EventRequestorCarrierTechnologyParameters());
+
+ assertThatThrownBy(() -> consumer.init(consumerName, eventHandlerParameters, null))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void getName() throws ApexEventException {
+ final String consumerName = RandomStringUtils.randomAlphabetic(6);
+ final EventHandlerParameters eventHandlerParameters = new EventHandlerParameters();
+ eventHandlerParameters.setCarrierTechnologyParameters(new EventRequestorCarrierTechnologyParameters());
+ eventHandlerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true);
+
+ consumer.init(consumerName, eventHandlerParameters, null);
+ final String actual = consumer.getName();
+
+ assertEquals(consumerName, actual);
+ }
+
+ @Test
+ public void getSetPeeeredReference() {
+ final PeeredReference peeredReference =
+ new PeeredReference(EventHandlerPeeredMode.REQUESTOR, new ApexFileEventConsumer(),
+ new ApexFileEventProducer());
+ consumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference);
+
+ final PeeredReference actual = consumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR);
+
+ assertEquals(peeredReference, actual);
+ }
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorProducerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorProducerTest.java
new file mode 100644
index 000000000..2f4764fb5
--- /dev/null
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorProducerTest.java
@@ -0,0 +1,161 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.impl.eventrequestor;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Random;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventProducer;
+import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+import org.onap.policy.apex.service.engine.event.PeeredReference;
+import org.onap.policy.apex.service.engine.event.SynchronousEventCache;
+import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.ApexFileEventConsumer;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+public class EventRequestorProducerTest {
+ private final Random random = new Random();
+ private EventRequestorProducer producer;
+
+ @Mock
+ private ApexEventProducer apexProducer;
+ @Mock
+ private EventRequestorConsumer apexConsumer;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ producer = new EventRequestorProducer();
+ }
+
+ @Test
+ public void initWithEmptyParams() {
+ final String producerName = RandomStringUtils.random(4);
+ final EventHandlerParameters eventHandlerParameters = new EventHandlerParameters();
+
+ assertThatThrownBy(() -> producer.init(producerName, eventHandlerParameters))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void initNotPeered() {
+ final String producerName = RandomStringUtils.random(4);
+ final EventHandlerParameters eventHandlerParameters = new EventHandlerParameters();
+ eventHandlerParameters.setCarrierTechnologyParameters(new EventRequestorCarrierTechnologyParameters());
+
+ assertThatThrownBy(() -> producer.init(producerName, eventHandlerParameters))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
+ public void getName() throws ApexEventException {
+ final String expected = RandomStringUtils.random(4);
+ final EventHandlerParameters eventHandlerParameters = new EventHandlerParameters();
+ eventHandlerParameters.setCarrierTechnologyParameters(new EventRequestorCarrierTechnologyParameters());
+ eventHandlerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true);
+
+ producer.init(expected, eventHandlerParameters);
+ final String actual = producer.getName();
+
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getSetPeeredReference() {
+ final PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, apexConsumer,
+ apexProducer);
+ producer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, peeredReference);
+
+ final PeeredReference actual = this.producer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS);
+ assertEquals(peeredReference, actual);
+ }
+
+ @Test
+ public void sendEventNoRequestor() {
+ final int id = random.nextInt(1000);
+
+ assertThatThrownBy(() -> producer.sendEvent(id, null, null, null))
+ .isInstanceOf(ApexEventRuntimeException.class);
+ }
+
+ @Test
+ public void sendEventNoEventRequestorConsumer() {
+ final int id = random.nextInt(1000);
+
+ final ApexFileEventConsumer fileEventConsumer = Mockito.mock(ApexFileEventConsumer.class);
+
+ final PeeredReference reference =
+ new PeeredReference(EventHandlerPeeredMode.REQUESTOR, fileEventConsumer, apexProducer);
+
+ producer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, reference);
+
+ assertThatThrownBy(() -> producer.sendEvent(id, null, null, null))
+ .isInstanceOf(ApexEventRuntimeException.class);
+ }
+
+ @Test
+ public void sendEvent() {
+ final int id = random.nextInt(1000);
+ // Prepare mocks
+ final PeeredReference peeredReference = Mockito.mock(PeeredReference.class);
+
+ Mockito.when(apexConsumer.getPeeredReference(Matchers.any())).thenReturn(peeredReference);
+ Mockito.when(peeredReference.getPeeredConsumer()).thenReturn(apexConsumer);
+
+ final PeeredReference reference =
+ new PeeredReference(EventHandlerPeeredMode.REQUESTOR, apexConsumer, apexProducer);
+ producer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, reference);
+
+ producer.sendEvent(id, null, null, null);
+ Mockito.verify(apexConsumer, Mockito.times(1)).processEvent(Matchers.any());
+ }
+
+ @Test
+ public void sendEventCached() {
+ final int id = random.nextInt(1000);
+
+ // Set event cache
+ final SynchronousEventCache eventCache = Mockito.mock(SynchronousEventCache.class);
+ producer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, eventCache);
+
+ // Prepare other mocks
+ final PeeredReference peeredReference = Mockito.mock(PeeredReference.class);
+
+ Mockito.when(peeredReference.getPeeredConsumer()).thenReturn(apexConsumer);
+ Mockito.when(apexConsumer.getPeeredReference(Matchers.any())).thenReturn(peeredReference);
+
+ final PeeredReference reference =
+ new PeeredReference(EventHandlerPeeredMode.REQUESTOR, apexConsumer, apexProducer);
+ producer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, reference);
+
+ producer.sendEvent(id, null, null, null);
+ Mockito.verify(apexConsumer, Mockito.times(1)).processEvent(Matchers.any());
+ Mockito.verify(eventCache, Mockito.times(1)).removeCachedEventToApexIfExists(id);
+ }
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockReaderFactoryTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockReaderFactoryTest.java
new file mode 100644
index 000000000..4fa42a727
--- /dev/null
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockReaderFactoryTest.java
@@ -0,0 +1,79 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.impl.filecarrierplugin.consumer;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.impl.apexprotocolplugin.ApexEventProtocolParameters;
+import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters;
+import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters;
+import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters;
+
+public class TextBlockReaderFactoryTest {
+ private TextBlockReaderFactory factory;
+
+ @Before
+ public void setUp() throws Exception {
+ factory = new TextBlockReaderFactory();
+ }
+
+ @Test
+ public void getTaggedReaderTextCharDelimitedParametersParams() throws ApexEventException {
+ final String text = RandomStringUtils.randomAlphanumeric(22);
+ final InputStream inputStream = prepareInputStream(text);
+ final EventProtocolParameters parameters = new JsonEventProtocolParameters();
+
+ final TextBlockReader actual = factory.getTaggedReader(inputStream, parameters);
+ assertThat(actual).isNotInstanceOf(HeaderDelimitedTextBlockReader.class);
+ }
+
+ @Test
+ public void getTaggedReaderTextTokenDelimitedParams() throws ApexEventException {
+ final String text = RandomStringUtils.randomAlphanumeric(22);
+ final InputStream inputStream = prepareInputStream(text);
+ new ApexEventProtocolParameters();
+ final EventProtocolParameters parameters = new SuperTokenDelimitedEventProtocolParameters();
+
+ final TextBlockReader actual = factory.getTaggedReader(inputStream, parameters);
+ assertThat(actual).isInstanceOf(HeaderDelimitedTextBlockReader.class);
+ }
+
+ @Test
+ public void getTaggedReaderNotSupportedParams() {
+ final String text = RandomStringUtils.randomAlphanumeric(22);
+ final InputStream inputStream = prepareInputStream(text);
+ final EventProtocolParameters parameters = new ApexEventProtocolParameters();
+ assertThatThrownBy(() -> factory.getTaggedReader(inputStream, parameters))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+
+ private InputStream prepareInputStream(String text) {
+ return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
+ }
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockTest.java
new file mode 100644
index 000000000..4390c3f3a
--- /dev/null
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockTest.java
@@ -0,0 +1,57 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.impl.filecarrierplugin.consumer;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Random;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Test;
+
+public class TextBlockTest {
+ private final Random random = new Random();
+
+ @Test
+ public void isEndOfText() {
+ final boolean endOfText = random.nextBoolean();
+ final TextBlock textBlock = new TextBlock(endOfText, null);
+
+ assertEquals(endOfText, textBlock.isEndOfText());
+ }
+
+ @Test
+ public void getText() {
+ final boolean endOfText = random.nextBoolean();
+ final String text = RandomStringUtils.randomAlphanumeric(8);
+ final TextBlock textBlock = new TextBlock(endOfText, text);
+
+ assertEquals(text, textBlock.getText());
+ }
+
+ @Test
+ public void setText() {
+ final boolean endOfText = random.nextBoolean();
+ final String text = RandomStringUtils.randomAlphanumeric(8);
+ final TextBlock textBlock = new TextBlock(endOfText, null);
+
+ textBlock.setText(text);
+ assertEquals(text, textBlock.getText());
+ }
+} \ No newline at end of file