diff options
author | Singh <soumya.e.singh@accenture.com> | 2024-04-09 17:38:07 +0530 |
---|---|---|
committer | Singh <soumya.e.singh@accenture.com> | 2024-04-10 15:36:25 +0530 |
commit | dff80ed76c8e0e6416e0688541f3094db3ca260a (patch) | |
tree | 72b5210b43ddc9d41c4aa7e4fcb8cfef040db067 /aai-core/src/test/java | |
parent | dd7e9878066b0de0d8c0acddf58aec5702e83115 (diff) |
Remove DMaaP dependency from AAI-Common
- Remove Dmaap dependency in AAI-Common and replace it with Kafka.
Issue-ID: AAI-3792
Change-Id: If3fd5c3bdc2448f7e260a26000b02a510c80d7fb
Signed-off-by: Singh <soumya.e.singh@accenture.com>
Diffstat (limited to 'aai-core/src/test/java')
-rw-r--r-- | aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventJMSConsumerTest.java | 89 | ||||
-rw-r--r-- | aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java | 8 |
2 files changed, 93 insertions, 4 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventJMSConsumerTest.java b/aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventJMSConsumerTest.java new file mode 100644 index 00000000..c72499c4 --- /dev/null +++ b/aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventJMSConsumerTest.java @@ -0,0 +1,89 @@ +package org.onap.aai.kafka; + +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import javax.jms.TextMessage; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.aai.PayloadUtil; +import org.springframework.core.env.Environment; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.test.context.EmbeddedKafka; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +@EmbeddedKafka(partitions = 1, brokerProperties = { "listeners=PLAINTEXT://localhost:9092", "port=9092" }) +public class AAIKafkaEventJMSConsumerTest { + + @Mock + private Environment environment; + + @Mock + private KafkaTemplate<String,String> kafkaTemplate; + + private AAIKafkaEventJMSConsumer aaiKafkaEventJMSConsumer; + + @Before + public void setUp(){ + aaiKafkaEventJMSConsumer = new AAIKafkaEventJMSConsumer(environment,kafkaTemplate); + } + + @Test + public void onMessage_shouldSendMessageToKafkaTopic_whenAAIEventReceived() + throws Exception + { + TextMessage mockTextMessage = mock(TextMessage.class); + String payload = PayloadUtil.getResourcePayload("aai-event.json"); + + when(mockTextMessage.getText()).thenReturn(payload); + aaiKafkaEventJMSConsumer.onMessage(mockTextMessage); + verify(kafkaTemplate, times(1)).send(eq("AAI-EVENT"), anyString()); + } + + @Test + public void onMessage_shouldNotSendMessageToKafkaTopic_whenInvalidEventReceived() throws Exception{ + TextMessage mockTextMessage = mock(TextMessage.class); + String payload = PayloadUtil.getResourcePayload("aai-invalid-event.json"); + when(mockTextMessage.getText()).thenReturn(payload); + aaiKafkaEventJMSConsumer.onMessage(mockTextMessage); + } + + + @Test + public void onMessage_shouldHandleJSONException() throws Exception { + // Arrange + AAIKafkaEventJMSConsumer consumer = new AAIKafkaEventJMSConsumer(null, kafkaTemplate); + TextMessage mockTextMessage = mock(TextMessage.class); + ReflectionTestUtils.setField(consumer, "kafkaTemplate", null); // Simulate null kafkaTemplate + + // Act + consumer.onMessage(mockTextMessage); + + // Assert + // Verify that exception is logged + } + + @Test + public void onMessage_shouldHandleGenericException() throws Exception { + // Arrange + AAIKafkaEventJMSConsumer consumer = new AAIKafkaEventJMSConsumer(null, kafkaTemplate); + TextMessage mockTextMessage = mock(TextMessage.class); + when(mockTextMessage.getText()).thenReturn("{\"event-topic\":\"AAI-EVENT\",\"aaiEventPayload\":{}}"); // Valid JSON but missing required fields + + // Act + consumer.onMessage(mockTextMessage); + + // Assert + // Verify that exception is logged + } + +} diff --git a/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java b/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java index b4b8810e..a0c3f639 100644 --- a/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java +++ b/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java @@ -39,27 +39,27 @@ import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; import org.onap.aai.AAISetup; -import org.onap.aai.dmaap.AAIDmaapEventJMSProducer; import org.onap.aai.domain.notificationEvent.NotificationEvent.EventHeader; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Introspector; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.ModelType; +import org.onap.aai.kafka.AAIKafkaEventJMSProducer; public class StoreNotificationEventTest extends AAISetup { - private static AAIDmaapEventJMSProducer producer; + private static AAIKafkaEventJMSProducer producer; private static StoreNotificationEvent sne; @BeforeClass public static void setUp() { - producer = Mockito.mock(AAIDmaapEventJMSProducer.class); + producer = Mockito.mock(AAIKafkaEventJMSProducer.class); // sne = new StoreNotificationEvent(producer, "transiationId", "sourceOfTruth"); } @Before public void setUpBefore() { - producer = Mockito.mock(AAIDmaapEventJMSProducer.class); + producer = Mockito.mock(AAIKafkaEventJMSProducer.class); sne = new StoreNotificationEvent(producer, "transiationId", "sourceOfTruth"); } |