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=86e33307bda1b2366405c2557a3f47219481f334;hb=32dca3cd3f1894f783980b982ea4aaf527a274e2;hp=f738fd71d83569790b5260e8f624795d7564632b;hpb=1c4b0ba3a2ca77a6acfcd41453b7c9c0f2f2480d;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 f738fd71d..86e33307b 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 @@ -19,37 +19,58 @@ import org.junit.Before; import org.junit.Test; import org.opendaylight.transportpce.common.converter.JsonStringConverter; 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.test.AbstractTest; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationService; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmService; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationProcessService; 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 Publisher publisherService; + private Publisher publisherAlarm; + private MockProducer mockProducer; + private MockProducer mockAlarmProducer; @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); + NotificationServiceSerializer serializerService = new NotificationServiceSerializer(); + NotificationAlarmServiceSerializer serializerAlarm = new NotificationAlarmServiceSerializer(); + Map properties = Map.of(ConfigConstants.CONVERTER, serializerService); + Map propertiesAlarm = Map.of(ConfigConstants.CONVERTER, serializerAlarm); + serializerService.configure(properties, false); + serializerAlarm.configure(propertiesAlarm, false); + mockProducer = new MockProducer<>(true, new StringSerializer(), serializerService); + mockAlarmProducer = new MockProducer<>(true, new StringSerializer(), serializerAlarm); + converterService = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices()); + converterAlarm = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices()); + publisherService = new Publisher<>("test", mockProducer); + publisherAlarm = new Publisher<>("test", mockAlarmProducer); } @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()); + } }