diff options
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src')
3 files changed, 233 insertions, 0 deletions
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 index 000000000..6c9cb6609 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java @@ -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 index 000000000..3c70d0b60 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java @@ -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 index 000000000..e26a64bb6 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java @@ -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); + } +} |