DeviceNotificationListener implements NotificationListener { @Override public void notificationReceived(final Notification notification) { LOGGER.info(String.format("Received device notification from device: %s with notification: %s", m_device.getDeviceName(), notification.notificationToString())); Notification normalizedNotification = m_adapterContext.getDeviceInterface().normalizeNotification(notification); if (normalizedNotification != null) { RequestScope.withScope(new RequestScope.RsTemplate<Void>() { @Override protected Void execute() throws RequestScopeExecutionException { try { NotificationContext context = new NotificationContext(); context.put(Device.class.getSimpleName(), m_device); context.put(DeviceAdapterId.class.getSimpleName(), m_deviceAdapterId); QName onuStateChangeNotification = QName.create(ONU_STATE_CHANGE_NS, "onu-state-change"); if (onuStateChangeNotification.equals(normalizedNotification.getType())) { getDeviceSlotAndPort(m_device.getDeviceName(), normalizedNotification); } m_notificationService.executeCallBack(normalizedNotification, context); } catch (Exception e) { LOGGER.error("Error while processing notification", e); } return null; } }); } else { LOGGER.debug("The normalized notification received from the adapter is null"); } } DeviceNotificationListener(Device device, DeviceAdapterId deviceAdapterId, NotificationService notificationService,
                                      AdapterContext adapterContext, PmaRegistry pmaRegistry); @Override void notificationReceived(final Notification notification);  }
@Test public void testNotificationReceivedNoNormalization() { when(m_deviceInterface.normalizeNotification(m_notification)).thenReturn(m_notification); m_deviceNotificationListener.notificationReceived(m_notification); verify(m_notificationService).executeCallBack(eq(m_notification), m_notificationContextCaptor.capture()); NotificationContext context = m_notificationContextCaptor.getValue(); assertEquals(m_device, context.get(Device.class.getSimpleName())); assertEquals(m_deviceAdapterId, context.get(DeviceAdapterId.class.getSimpleName())); }
@Test public void testNotificationReceivedForNormalization() { when(m_deviceInterface.normalizeNotification(m_notification)).thenReturn(m_normalizedNotification); m_deviceNotificationListener.notificationReceived(m_notification); verify(m_notificationService).executeCallBack(eq(m_normalizedNotification), m_notificationContextCaptor.capture()); NotificationContext context = m_notificationContextCaptor.getValue(); assertEquals(m_device, context.get(Device.class.getSimpleName())); assertEquals(m_deviceAdapterId, context.get(DeviceAdapterId.class.getSimpleName())); }
@Test public void testNormalizedNotificationIsNull() { when(m_deviceInterface.normalizeNotification(m_notification)).thenReturn(null); m_deviceNotificationListener.notificationReceived(m_notification); verifyZeroInteractions(m_notificationService); }
@Test public void testOnuStateChangeNotificationWithDetectedRegIdAbsent() throws NetconfMessageBuilderException { String onuNotificationStr = "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n" + " <eventTime>2019-07-25T05:53:36+00:00</eventTime>\n" + " <bbf-xpon-onu-states:onu-state-change xmlns:bbf-xpon-onu-states=\"urn:bbf:yang:bbf-xpon-onu-states\">\n" + " <bbf-xpon-onu-states:detected-serial-number>ABCD0P5S6T7Y</bbf-xpon-onu-states:detected-serial-number>\n" + " <bbf-xpon-onu-states:channel-termination-ref>chterm</bbf-xpon-onu-states:channel-termination-ref>\n" + " <bbf-xpon-onu-states:onu-state-last-change>2019-07-25T05:51:36+00:00</bbf-xpon-onu-states:onu-state-last-change>\n" + " <bbf-xpon-onu-states:onu-state xmlns:bbf-xpon-onu-types=\"urn:bbf:yang:bbf-xpon-more-types\">bbf-xpon-onu-types:onu-present</bbf-xpon-onu-states:onu-state>\n" + " <bbf-xpon-onu-states:onu-id>25</bbf-xpon-onu-states:onu-id>\n" + " </bbf-xpon-onu-states:onu-state-change>\n" + "</notification>\n"; m_notification = new NetconfNotification(DocumentUtils.stringToDocument(onuNotificationStr)); when(m_deviceInterface.normalizeNotification(m_notification)).thenReturn(m_notification); m_deviceNotificationListener.notificationReceived(m_notification); verifyNotification("DPU1-SLOT-PORT"); }
@Test public void testOnuStateChangeNotitifcationReplaceDetectedRegId() throws NetconfMessageBuilderException { String onuNotificationStr = "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n" + " <eventTime>2019-07-25T05:53:36+00:00</eventTime>\n" + " <bbf-xpon-onu-states:onu-state-change xmlns:bbf-xpon-onu-states=\"urn:bbf:yang:bbf-xpon-onu-states\">\n" + " <bbf-xpon-onu-states:detected-serial-number>ABCD0P5S6T7Y</bbf-xpon-onu-states:detected-serial-number>\n" + " <bbf-xpon-onu-states:channel-termination-ref>chterm</bbf-xpon-onu-states:channel-termination-ref>\n" + " <bbf-xpon-onu-states:onu-state-last-change>2019-07-25T05:51:36+00:00</bbf-xpon-onu-states:onu-state-last-change>\n" + " <bbf-xpon-onu-states:onu-state xmlns:bbf-xpon-onu-types=\"urn:bbf:yang:bbf-xpon-more-types\">bbf-xpon-onu-types:onu-present</bbf-xpon-onu-states:onu-state>\n" + " <bbf-xpon-onu-states:onu-id>25</bbf-xpon-onu-states:onu-id>\n" + " <bbf-xpon-onu-states:detected-registration-id>shouldBeReplaced</bbf-xpon-onu-states:detected-registration-id>\n" + " </bbf-xpon-onu-states:onu-state-change>\n" + "</notification>\n"; m_notification = new NetconfNotification(DocumentUtils.stringToDocument(onuNotificationStr)); when(m_deviceInterface.normalizeNotification(m_notification)).thenReturn(m_notification); m_deviceNotificationListener.notificationReceived(m_notification); verifyNotification("DPU1-SLOT-PORT"); }
@Test public void testOnuStateChangeNotitifcationWithChannelRefNotInDS() throws NetconfMessageBuilderException { String onuNotificationStr = "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n" + " <eventTime>2019-07-25T05:53:36+00:00</eventTime>\n" + " <bbf-xpon-onu-states:onu-state-change xmlns:bbf-xpon-onu-states=\"urn:bbf:yang:bbf-xpon-onu-states\">\n" + " <bbf-xpon-onu-states:detected-serial-number>ABCD0P5S6T7Y</bbf-xpon-onu-states:detected-serial-number>\n" + " <bbf-xpon-onu-states:channel-termination-ref>chtermnotpresentinds</bbf-xpon-onu-states:channel-termination-ref>\n" + " <bbf-xpon-onu-states:onu-state-last-change>2019-07-25T05:51:36+00:00</bbf-xpon-onu-states:onu-state-last-change>\n" + " <bbf-xpon-onu-states:onu-state xmlns:bbf-xpon-onu-types=\"urn:bbf:yang:bbf-xpon-more-types\">bbf-xpon-onu-types:onu-present</bbf-xpon-onu-states:onu-state>\n" + " <bbf-xpon-onu-states:onu-id>25</bbf-xpon-onu-states:onu-id>\n" + " <bbf-xpon-onu-states:detected-registration-id>shouldBeReplaced</bbf-xpon-onu-states:detected-registration-id>\n" + " </bbf-xpon-onu-states:onu-state-change>\n" + "</notification>\n"; m_notification = new NetconfNotification(DocumentUtils.stringToDocument(onuNotificationStr)); when(m_deviceInterface.normalizeNotification(m_notification)).thenReturn(m_notification); m_deviceNotificationListener.notificationReceived(m_notification); verifyNotification("DPU1--"); }