Increase test coverage for apex-pdp/plugins 97/78797/1
authorParshad Patel <pars.patel@samsung.com>
Wed, 20 Feb 2019 02:38:16 +0000 (11:38 +0900)
committerParshad Patel <pars.patel@samsung.com>
Wed, 20 Feb 2019 02:42:27 +0000 (11:42 +0900)
Add basic JUnit test cases for plugins-event-carrier-kafka

Issue-ID: POLICY-1513
Change-Id: I009547115705496a850a9609416cdf71f52fb936
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java [new file with mode: 0644]
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java [new file with mode: 0644]
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java [new file with mode: 0644]

diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java
new file mode 100644 (file)
index 0000000..6c9cb66
--- /dev/null
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Samsung. All rights reserved.
+ * ================================================================================
+ * 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.plugins.event.carrier.kafka;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+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.event.ApexEventReceiver;
+import org.onap.policy.apex.service.engine.event.PeeredReference;
+import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+public class ApexKafkaConsumerTest {
+    ApexKafkaConsumer apexKafkaConsumer = null;
+    EventHandlerParameters consumerParameters = null;
+    ApexEventReceiver incomingEventReceiver = null;
+    ApexEventProducer apexKafkaProducer = null;
+
+    @Before
+    public void setUp() throws ApexEventException {
+        apexKafkaConsumer = new ApexKafkaConsumer();
+        consumerParameters = new EventHandlerParameters();
+        apexKafkaProducer = new ApexKafkaProducer();
+        consumerParameters
+                .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() {});
+        apexKafkaConsumer.init("TestApexKafkaConsumer", consumerParameters, incomingEventReceiver);
+    }
+
+    @Test
+    public void testStart() {
+        apexKafkaConsumer.start();
+    }
+
+    @Test
+    public void testGetName() {
+        assertEquals("TestApexKafkaConsumer", apexKafkaConsumer.getName());
+    }
+
+    @Test
+    public void testGetPeeredReference() {
+        assertNull(apexKafkaConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+    }
+
+    @Test
+    public void testSetPeeredReference() {
+        PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
+                apexKafkaConsumer, apexKafkaProducer);
+        apexKafkaConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference);
+        assertNotNull(apexKafkaConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+    }
+
+    @Test(expected = java.lang.NullPointerException.class)
+    public void testRun() {
+        apexKafkaConsumer.run();
+    }
+
+    @Test(expected = java.lang.NullPointerException.class)
+    public void testStop() {
+        apexKafkaConsumer.stop();
+    }
+
+    @Test(expected = ApexEventException.class)
+    public void testInitWithNonKafkaCarrierTechnologyParameters() throws ApexEventException {
+        consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {});
+        apexKafkaConsumer.init("TestApexKafkaConsumer", consumerParameters, incomingEventReceiver);
+    }
+
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java
new file mode 100644 (file)
index 0000000..3c70d0b
--- /dev/null
@@ -0,0 +1,79 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Samsung. All rights reserved.
+ * ================================================================================
+ * 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.plugins.event.carrier.kafka;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+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.SynchronousEventCache;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+public class ApexKafkaProducerTest {
+    ApexKafkaProducer apexKafkaProducer = null;
+    ApexKafkaConsumer apexKafkaConsumer = null;
+    EventHandlerParameters producerParameters = null;
+    PeeredReference peeredReference = null;
+    SynchronousEventCache synchronousEventCache = null;
+    private static final long DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT = 1000;
+
+    @Before
+    public void setUp() throws Exception {
+        apexKafkaProducer = new ApexKafkaProducer();
+        apexKafkaConsumer = new ApexKafkaConsumer();
+        producerParameters = new EventHandlerParameters();
+
+    }
+
+    @Test(expected = ApexEventException.class)
+    public void testInit() throws ApexEventException {
+        apexKafkaProducer.init("TestApexKafkaProducer", producerParameters);
+    }
+
+    @Test
+    public void testGetName() {
+        assertNull(apexKafkaProducer.getName());
+    }
+
+    @Test
+    public void testGetPeeredReference() {
+        assertNull(apexKafkaProducer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
+    }
+
+    @Test
+    public void testWithProperValues() throws ApexEventException {
+        producerParameters
+                .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() {});
+        synchronousEventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS,
+                apexKafkaConsumer, apexKafkaProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT);
+        apexKafkaProducer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS,
+                synchronousEventCache);
+        apexKafkaProducer.init("TestApexKafkaProducer", producerParameters);
+        assertEquals("TestApexKafkaProducer", apexKafkaProducer.getName());
+        assertNotNull(apexKafkaProducer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
+        apexKafkaProducer.stop();
+    }
+
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java
new file mode 100644 (file)
index 0000000..e26a64b
--- /dev/null
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Samsung. All rights reserved.
+ * ================================================================================
+ * 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.plugins.event.carrier.kafka;
+
+import static org.junit.Assert.assertNotNull;
+import java.util.Properties;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+public class KafkaCarrierTechnologyParametersTest {
+
+    KafkaCarrierTechnologyParameters kafkaCarrierTechnologyParameters = null;
+    Properties kafkaProducerProperties = null;
+    Properties kafkaConsumerProperties = null;
+    GroupValidationResult result = null;
+
+    @Before
+    public void setUp() throws Exception {
+        kafkaCarrierTechnologyParameters = new KafkaCarrierTechnologyParameters();
+        kafkaProducerProperties = kafkaCarrierTechnologyParameters.getKafkaProducerProperties();
+        kafkaConsumerProperties = kafkaCarrierTechnologyParameters.getKafkaConsumerProperties();
+    }
+
+    @Test
+    public void testKafkaCarrierTechnologyParameters() {
+        assertNotNull(kafkaCarrierTechnologyParameters);
+    }
+
+    @Test
+    public void testGetKafkaProducerProperties() {
+        assertNotNull(kafkaProducerProperties);
+    }
+
+    @Test
+    public void testGetKafkaConsumerProperties() {
+        assertNotNull(kafkaConsumerProperties);
+    }
+
+    @Test
+    public void testValidate() {
+        result = kafkaCarrierTechnologyParameters.validate();
+        assertNotNull(result);
+    }
+}