@Test public void testOnNotification() throws InterruptedException { List<TSDRLogRecord> storedRecords = Collections.synchronizedList(new ArrayList<>()); doAnswer(invocation -> { storedRecords.addAll(((InsertTSDRLogRecordInput) invocation.getArguments()[0]).getTSDRLogRecord()); return RpcResultBuilder.success(new InsertTSDRLogRecordOutputBuilder().build()).buildFuture(); }).when(mockSpiService).insertTSDRLogRecord(any()); YangNotificationCollectorLogger logger = new YangNotificationCollectorLogger(mockSpiService, schedulerService, domSchemaService, domNotificationRouter, new NotificationSubscriptionBuilder().setNotifications( Arrays.asList(new NotificationsBuilder().setNotification( OutOfPixieDustNotification.QNAME.toString()).build())).build()); String reason = "lost it"; Integer daysTillNewDust = 5; final ContainerNode notificationBody = bindingToNormalized.toNormalizedNodeNotification( new OutOfPixieDustNotificationBuilder().setReason(reason).setDaysTillNewDust(daysTillNewDust).build()); DOMNotification mockNotification = mock(DOMNotification.class); doReturn(NOTIFICATION_SCHEMA_PATH).when(mockNotification).getType(); doReturn(notificationBody).when(mockNotification).getBody(); domNotificationRouter.putNotification(mockNotification); Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> { return storedRecords.size() == 1; }); String recordText = storedRecords.get(0).getRecordFullText(); JsonParser parser = new JsonParser(); JsonElement rootElement = parser.parse(new InputStreamReader(new ByteArrayInputStream(recordText.getBytes()))); Set<Entry<String, JsonElement>> entries = rootElement.getAsJsonObject().entrySet(); assertEquals(1, entries.size()); Entry<String, JsonElement> entry = entries.iterator().next(); assertEquals("opendaylight-test-notification:out-of-pixie-dust-notification", entry.getKey()); Set<Entry<String, JsonElement>> childEntries = entry.getValue().getAsJsonObject().entrySet(); assertEquals(reason, childEntries.stream().filter(e -> e.getKey().equals("reason")).findFirst() .orElseThrow(() -> new AssertionError("reason element not found")).getValue().getAsString()); assertEquals(daysTillNewDust, Integer.valueOf(childEntries.stream() .filter(e -> e.getKey().equals("days-till-new-dust")).findFirst() .orElseThrow(() -> new AssertionError("days-till-new-dust element not found")).getValue().getAsInt())); }
@Override public void onNotification(DOMNotification notification) { final String jsonNotification = writeNotificationBodyToJson(notification); LOG.debug("onNotification - dom: {} converted to JSON: {}", notification, jsonNotification); super.insertLog(notification.getType().getLastComponent().getLocalName(), System.currentTimeMillis(), jsonNotification, DataCategory.YANGNOTIFICATION); }
YangNotificationCollectorLogger extends BatchingLogCollector implements DOMNotificationListener { @Override public void onNotification(DOMNotification notification) { final String jsonNotification = writeNotificationBodyToJson(notification); LOG.debug("onNotification - dom: {} converted to JSON: {}", notification, jsonNotification); super.insertLog(notification.getType().getLastComponent().getLocalName(), System.currentTimeMillis(), jsonNotification, DataCategory.YANGNOTIFICATION); } }
YangNotificationCollectorLogger extends BatchingLogCollector implements DOMNotificationListener { @Override public void onNotification(DOMNotification notification) { final String jsonNotification = writeNotificationBodyToJson(notification); LOG.debug("onNotification - dom: {} converted to JSON: {}", notification, jsonNotification); super.insertLog(notification.getType().getLastComponent().getLocalName(), System.currentTimeMillis(), jsonNotification, DataCategory.YANGNOTIFICATION); } @Inject  YangNotificationCollectorLogger(final TsdrCollectorSpiService collectorSPIService,
            final SchedulerService schedulerService, final DOMSchemaService domSchemaService,
            final DOMNotificationService notificationService, final NotificationSubscription configuration); }
YangNotificationCollectorLogger extends BatchingLogCollector implements DOMNotificationListener { @Override public void onNotification(DOMNotification notification) { final String jsonNotification = writeNotificationBodyToJson(notification); LOG.debug("onNotification - dom: {} converted to JSON: {}", notification, jsonNotification); super.insertLog(notification.getType().getLastComponent().getLocalName(), System.currentTimeMillis(), jsonNotification, DataCategory.YANGNOTIFICATION); } @Inject  YangNotificationCollectorLogger(final TsdrCollectorSpiService collectorSPIService,
            final SchedulerService schedulerService, final DOMSchemaService domSchemaService,
            final DOMNotificationService notificationService, final NotificationSubscription configuration); @Override void close(); @Override void onNotification(DOMNotification notification); }
YangNotificationCollectorLogger extends BatchingLogCollector implements DOMNotificationListener { @Override public void onNotification(DOMNotification notification) { final String jsonNotification = writeNotificationBodyToJson(notification); LOG.debug("onNotification - dom: {} converted to JSON: {}", notification, jsonNotification); super.insertLog(notification.getType().getLastComponent().getLocalName(), System.currentTimeMillis(), jsonNotification, DataCategory.YANGNOTIFICATION); } @Inject  YangNotificationCollectorLogger(final TsdrCollectorSpiService collectorSPIService,
            final SchedulerService schedulerService, final DOMSchemaService domSchemaService,
            final DOMNotificationService notificationService, final NotificationSubscription configuration); @Override void close(); @Override void onNotification(DOMNotification notification);  }