X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=nbinotifications%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fnbinotifications%2Fproducer%2FPublisherTest.java;h=0e07aff231382b9e25252ff41d30eae7b5ffa9b5;hb=72726c942bab51f2d1081e83e2b9ac8aa6481122;hp=b3a5b2edbeb5b5a858eb377f012b8c3f70c3c669;hpb=56ad6406faba3227e19a6f609325c8b9dbaca3fb;p=transportpce.git diff --git a/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/producer/PublisherTest.java b/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/producer/PublisherTest.java index b3a5b2edb..0e07aff23 100644 --- a/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/producer/PublisherTest.java +++ b/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/producer/PublisherTest.java @@ -9,47 +9,127 @@ package org.opendaylight.transportpce.nbinotifications.producer; import static org.junit.Assert.assertEquals; +import com.google.common.util.concurrent.ListenableFuture; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutionException; import org.apache.kafka.clients.producer.MockProducer; import org.apache.kafka.common.serialization.StringSerializer; import org.junit.Before; import org.junit.Test; +import org.mockito.MockitoAnnotations; import org.opendaylight.transportpce.common.converter.JsonStringConverter; +import org.opendaylight.transportpce.common.network.NetworkTransactionImpl; +import org.opendaylight.transportpce.common.network.NetworkTransactionService; +import org.opendaylight.transportpce.common.network.RequestProcessor; +import org.opendaylight.transportpce.nbinotifications.impl.NbiNotificationsImpl; import org.opendaylight.transportpce.nbinotifications.serialization.ConfigConstants; +import org.opendaylight.transportpce.nbinotifications.serialization.NotificationAlarmServiceSerializer; import org.opendaylight.transportpce.nbinotifications.serialization.NotificationServiceSerializer; +import org.opendaylight.transportpce.nbinotifications.serialization.TapiNotificationSerializer; +import org.opendaylight.transportpce.nbinotifications.utils.NotificationServiceDataUtils; +import org.opendaylight.transportpce.nbinotifications.utils.TopicManager; import org.opendaylight.transportpce.test.AbstractTest; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.NotificationService; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiService; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceInputBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceOutput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.create.notification.subscription.service.input.SubscriptionFilter; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.create.notification.subscription.service.input.SubscriptionFilterBuilder; +import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier; public class PublisherTest extends AbstractTest { - private JsonStringConverter converter; - private Publisher publisher; - private MockProducer mockProducer; + private JsonStringConverter converterService; + private JsonStringConverter converterAlarm; + private JsonStringConverter converterTapiService; + private Publisher publisherService; + private Publisher publisherAlarm; + private Publisher publisherTapiService; + private MockProducer mockProducer; + private MockProducer mockAlarmProducer; + private MockProducer mockTapiProducer; + private NbiNotificationsImpl nbiNotificationsImpl; + private TopicManager topicManager; + + public static NetworkTransactionService networkTransactionService; @Before - public void setUp() { - NotificationServiceSerializer serializer = new NotificationServiceSerializer(); - Map properties = Map.of(ConfigConstants.CONVERTER , serializer); - serializer.configure(properties, false); - mockProducer = new MockProducer<>(true, new StringSerializer(), serializer); - converter = new JsonStringConverter( - getDataStoreContextUtil().getBindingDOMCodecServices()); - publisher = new Publisher("test",mockProducer); + public void setUp() throws ExecutionException, InterruptedException { + topicManager = TopicManager.getInstance(); + converterService = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices()); + converterAlarm = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices()); + converterTapiService = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices()); + NotificationServiceSerializer serializerService = new NotificationServiceSerializer(); + NotificationAlarmServiceSerializer serializerAlarm = new NotificationAlarmServiceSerializer(); + TapiNotificationSerializer serializerTapi = new TapiNotificationSerializer(); + Map properties = Map.of(ConfigConstants.CONVERTER, converterService); + Map propertiesAlarm = Map.of(ConfigConstants.CONVERTER, converterAlarm); + Map propertiesTapi = Map.of(ConfigConstants.CONVERTER, converterTapiService); + serializerService.configure(properties, false); + serializerAlarm.configure(propertiesAlarm, false); + serializerTapi.configure(propertiesTapi, false); + mockProducer = new MockProducer<>(true, new StringSerializer(), serializerService); + mockAlarmProducer = new MockProducer<>(true, new StringSerializer(), serializerAlarm); + mockTapiProducer = new MockProducer<>(true, new StringSerializer(), serializerTapi); + publisherService = new Publisher<>("test", mockProducer); + publisherAlarm = new Publisher<>("test", mockAlarmProducer); + publisherTapiService = new Publisher<>("test", mockTapiProducer); + MockitoAnnotations.openMocks(this); + networkTransactionService = new NetworkTransactionImpl( + new RequestProcessor(getDataStoreContextUtil().getDataBroker())); + topicManager.setTapiConverter(converterTapiService); + NotificationServiceDataUtils.createTapiContext(networkTransactionService); + nbiNotificationsImpl = new NbiNotificationsImpl(converterService, converterAlarm, converterTapiService, + "localhost:8080", networkTransactionService, topicManager); } @Test - public void sendEventShouldBeSuccessful() throws IOException { + public void sendEventServiceShouldBeSuccessful() throws IOException { String json = Files.readString(Paths.get("src/test/resources/event.json")); - NotificationService notificationService = converter - .createDataObjectFromJsonString(YangInstanceIdentifier.of(NotificationService.QNAME), + NotificationProcessService notificationProcessService = converterService + .createDataObjectFromJsonString(YangInstanceIdentifier.of(NotificationProcessService.QNAME), json, JSONCodecFactorySupplier.RFC7951); - publisher.sendEvent(notificationService); + publisherService.sendEvent(notificationProcessService, notificationProcessService.getConnectionType().name()); assertEquals("We should have one message", 1, mockProducer.history().size()); - assertEquals("Key should be test", "test",mockProducer.history().get(0).key()); + assertEquals("Key should be test", "test", mockProducer.history().get(0).key()); } + @Test + public void sendEventAlarmShouldBeSuccessful() throws IOException { + String json = Files.readString(Paths.get("src/test/resources/event_alarm_service.json")); + NotificationAlarmService notificationAlarmService = converterAlarm + .createDataObjectFromJsonString(YangInstanceIdentifier.of(NotificationAlarmService.QNAME), + json, JSONCodecFactorySupplier.RFC7951); + publisherAlarm.sendEvent(notificationAlarmService, "alarm" + + notificationAlarmService.getConnectionType().getName()); + assertEquals("We should have one message", 1, mockAlarmProducer.history().size()); + assertEquals("Key should be test", "test", mockAlarmProducer.history().get(0).key()); + } + + @Test + public void sendTapiEventShouldBeSuccessful() throws IOException { + CreateNotificationSubscriptionServiceInputBuilder builder + = NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder(); + SubscriptionFilter subscriptionFilter = new SubscriptionFilterBuilder(builder.getSubscriptionFilter()) + .setRequestedObjectIdentifier(new HashSet<>(List.of(new Uuid("76d8f07b-ead5-4132-8eb8-cf3fdef7e079")))) + .build(); + builder.setSubscriptionFilter(subscriptionFilter); + ListenableFuture> result = + nbiNotificationsImpl.createNotificationSubscriptionService(builder.build()); + String json = Files.readString(Paths.get("src/test/resources/tapi_event.json")); + NotificationTapiService notificationTapiService = converterTapiService + .createDataObjectFromJsonString(YangInstanceIdentifier.of(NotificationTapiService.QNAME), + json, JSONCodecFactorySupplier.RFC7951); + publisherTapiService.sendEvent(notificationTapiService, ""); + assertEquals("We should have one message", 1, mockTapiProducer.history().size()); + assertEquals("Key should be test", "test", mockTapiProducer.history().get(0).key()); + } }