@Test public void testOnDeploy() throws URISyntaxException { SchemaRegistryImpl mountRegistry = mock(SchemaRegistryImpl.class); Module module = mock(Module.class); String alarmNS = "urn:ietf:params:xml:ns:yang:ietf-alarms"; String alarmNotification = "alarm-notification"; String moduleCapabilityString = "urn:ietf:params:xml:ns:yang:ietf-alarms?module=ietf-alarms&revision=2019-09-11"; QName alarmNotificationQName = QName.create(alarmNS, alarmNotification); QNameModule qNameModule = QNameModule.create(new URI("urn:ietf:params:xml:ns:yang:ietf-alarms"), Revision.of("2019-09-11")); when(module.getNamespace()).thenReturn(new URI(alarmNS)); when(module.getName()).thenReturn("ietf-alarms"); when(module.getQNameModule()).thenReturn(qNameModule); when(mountRegistry.getModuleByNamespace(alarmNS)).thenReturn(module); when(m_adapter.getDeviceAdapterId()).thenReturn(m_deviceAdapterId); when(m_adapterManager.getAdapterContext(m_deviceAdapterId)).thenReturn(m_adapterContext); when(m_notificationService.isNotificationCallbackRegistered(alarmNotificationQName, moduleCapabilityString)).thenReturn(false); when(m_adapterContext.getSchemaRegistry()).thenReturn(mountRegistry); AlarmManagementCallbackRegistrator registrator = new AlarmManagementCallbackRegistrator(m_notificationService, m_alarmService, null); @SuppressWarnings({"rawtypes", "unchecked"}) Class<List<NotificationCallBackInfo>> listClass = (Class<List<NotificationCallBackInfo>>) (Class) List.class; ArgumentCaptor<List<NotificationCallBackInfo>> capture = ArgumentCaptor.forClass(listClass); registrator.onDeployed(m_adapter, m_adapterContext); verify(m_notificationService).registerCallBack(capture.capture()); List<NotificationCallBackInfo> callbacks = capture.getValue(); assertEquals(alarmNotificationQName, callbacks.get(0).getNotificationTypes().iterator().next()); }
public void onDeployed(DeviceAdapter adapter, AdapterContext adapterContext) { DeviceAdapterId deviceAdapterId = adapter.getDeviceAdapterId(); LOGGER.debug("Invoked deploy to register alarm callback for deviceAdapterId: " + deviceAdapterId); Module module = getMatchedAlarmModule(adapterContext); if (module != null) { String alarmNS = module.getNamespace().toString(); m_alarmNotificationQName = getAlarmNotificationQName(alarmNS); m_alarmService.updateAlarmNotificationQNameToAdapterTypeVersion(m_alarmNotificationQName, deviceAdapterId.getType() + "." + deviceAdapterId.getInterfaceVersion() + "." + deviceAdapterId.getModel() + "." + deviceAdapterId.getVendor()); LOGGER.debug(String.format("Going to register alarmCallBack if not already registered during deployment of adapter %s ", deviceAdapterId)); String moduleName = module.getName(); Optional<Revision> moduleRevision = module.getQNameModule().getRevision(); if (m_callbackMapPerAdapter.get(deviceAdapterId) == null) { List<NotificationCallBackInfo> notificationCallBackInfos = createNotificationCallBackInfo(alarmNS, moduleName, moduleRevision, adapter, adapterContext); m_notificationService.registerCallBack(notificationCallBackInfos); LOGGER.info(String.format("notification callback is registered for the notification namespace %s for adapter %s", alarmNS, deviceAdapterId)); } } else { LOGGER.error("No matching alarm module found for adapter: " + deviceAdapterId); } }
AlarmManagementCallbackRegistrator implements StandardAdapterModelRegistrator { public void onDeployed(DeviceAdapter adapter, AdapterContext adapterContext) { DeviceAdapterId deviceAdapterId = adapter.getDeviceAdapterId(); LOGGER.debug("Invoked deploy to register alarm callback for deviceAdapterId: " + deviceAdapterId); Module module = getMatchedAlarmModule(adapterContext); if (module != null) { String alarmNS = module.getNamespace().toString(); m_alarmNotificationQName = getAlarmNotificationQName(alarmNS); m_alarmService.updateAlarmNotificationQNameToAdapterTypeVersion(m_alarmNotificationQName, deviceAdapterId.getType() + "." + deviceAdapterId.getInterfaceVersion() + "." + deviceAdapterId.getModel() + "." + deviceAdapterId.getVendor()); LOGGER.debug(String.format("Going to register alarmCallBack if not already registered during deployment of adapter %s ", deviceAdapterId)); String moduleName = module.getName(); Optional<Revision> moduleRevision = module.getQNameModule().getRevision(); if (m_callbackMapPerAdapter.get(deviceAdapterId) == null) { List<NotificationCallBackInfo> notificationCallBackInfos = createNotificationCallBackInfo(alarmNS, moduleName, moduleRevision, adapter, adapterContext); m_notificationService.registerCallBack(notificationCallBackInfos); LOGGER.info(String.format("notification callback is registered for the notification namespace %s for adapter %s", alarmNS, deviceAdapterId)); } } else { LOGGER.error("No matching alarm module found for adapter: " + deviceAdapterId); } } }
AlarmManagementCallbackRegistrator implements StandardAdapterModelRegistrator { public void onDeployed(DeviceAdapter adapter, AdapterContext adapterContext) { DeviceAdapterId deviceAdapterId = adapter.getDeviceAdapterId(); LOGGER.debug("Invoked deploy to register alarm callback for deviceAdapterId: " + deviceAdapterId); Module module = getMatchedAlarmModule(adapterContext); if (module != null) { String alarmNS = module.getNamespace().toString(); m_alarmNotificationQName = getAlarmNotificationQName(alarmNS); m_alarmService.updateAlarmNotificationQNameToAdapterTypeVersion(m_alarmNotificationQName, deviceAdapterId.getType() + "." + deviceAdapterId.getInterfaceVersion() + "." + deviceAdapterId.getModel() + "." + deviceAdapterId.getVendor()); LOGGER.debug(String.format("Going to register alarmCallBack if not already registered during deployment of adapter %s ", deviceAdapterId)); String moduleName = module.getName(); Optional<Revision> moduleRevision = module.getQNameModule().getRevision(); if (m_callbackMapPerAdapter.get(deviceAdapterId) == null) { List<NotificationCallBackInfo> notificationCallBackInfos = createNotificationCallBackInfo(alarmNS, moduleName, moduleRevision, adapter, adapterContext); m_notificationService.registerCallBack(notificationCallBackInfos); LOGGER.info(String.format("notification callback is registered for the notification namespace %s for adapter %s", alarmNS, deviceAdapterId)); } } else { LOGGER.error("No matching alarm module found for adapter: " + deviceAdapterId); } } AlarmManagementCallbackRegistrator(NotificationService notificationService, AlarmService alarmService,
                                              SchemaRegistry dmSchemaRegistry); }
AlarmManagementCallbackRegistrator implements StandardAdapterModelRegistrator { public void onDeployed(DeviceAdapter adapter, AdapterContext adapterContext) { DeviceAdapterId deviceAdapterId = adapter.getDeviceAdapterId(); LOGGER.debug("Invoked deploy to register alarm callback for deviceAdapterId: " + deviceAdapterId); Module module = getMatchedAlarmModule(adapterContext); if (module != null) { String alarmNS = module.getNamespace().toString(); m_alarmNotificationQName = getAlarmNotificationQName(alarmNS); m_alarmService.updateAlarmNotificationQNameToAdapterTypeVersion(m_alarmNotificationQName, deviceAdapterId.getType() + "." + deviceAdapterId.getInterfaceVersion() + "." + deviceAdapterId.getModel() + "." + deviceAdapterId.getVendor()); LOGGER.debug(String.format("Going to register alarmCallBack if not already registered during deployment of adapter %s ", deviceAdapterId)); String moduleName = module.getName(); Optional<Revision> moduleRevision = module.getQNameModule().getRevision(); if (m_callbackMapPerAdapter.get(deviceAdapterId) == null) { List<NotificationCallBackInfo> notificationCallBackInfos = createNotificationCallBackInfo(alarmNS, moduleName, moduleRevision, adapter, adapterContext); m_notificationService.registerCallBack(notificationCallBackInfos); LOGGER.info(String.format("notification callback is registered for the notification namespace %s for adapter %s", alarmNS, deviceAdapterId)); } } else { LOGGER.error("No matching alarm module found for adapter: " + deviceAdapterId); } } AlarmManagementCallbackRegistrator(NotificationService notificationService, AlarmService alarmService,
                                              SchemaRegistry dmSchemaRegistry); void onDeployed(DeviceAdapter adapter, AdapterContext adapterContext); void onUndeployed(DeviceAdapter adapter, AdapterContext adapterContext); void setOldIdentities(Set<IdentitySchemaNode> oldIdentities); }
AlarmManagementCallbackRegistrator implements StandardAdapterModelRegistrator { public void onDeployed(DeviceAdapter adapter, AdapterContext adapterContext) { DeviceAdapterId deviceAdapterId = adapter.getDeviceAdapterId(); LOGGER.debug("Invoked deploy to register alarm callback for deviceAdapterId: " + deviceAdapterId); Module module = getMatchedAlarmModule(adapterContext); if (module != null) { String alarmNS = module.getNamespace().toString(); m_alarmNotificationQName = getAlarmNotificationQName(alarmNS); m_alarmService.updateAlarmNotificationQNameToAdapterTypeVersion(m_alarmNotificationQName, deviceAdapterId.getType() + "." + deviceAdapterId.getInterfaceVersion() + "." + deviceAdapterId.getModel() + "." + deviceAdapterId.getVendor()); LOGGER.debug(String.format("Going to register alarmCallBack if not already registered during deployment of adapter %s ", deviceAdapterId)); String moduleName = module.getName(); Optional<Revision> moduleRevision = module.getQNameModule().getRevision(); if (m_callbackMapPerAdapter.get(deviceAdapterId) == null) { List<NotificationCallBackInfo> notificationCallBackInfos = createNotificationCallBackInfo(alarmNS, moduleName, moduleRevision, adapter, adapterContext); m_notificationService.registerCallBack(notificationCallBackInfos); LOGGER.info(String.format("notification callback is registered for the notification namespace %s for adapter %s", alarmNS, deviceAdapterId)); } } else { LOGGER.error("No matching alarm module found for adapter: " + deviceAdapterId); } } AlarmManagementCallbackRegistrator(NotificationService notificationService, AlarmService alarmService,
                                              SchemaRegistry dmSchemaRegistry); void onDeployed(DeviceAdapter adapter, AdapterContext adapterContext); void onUndeployed(DeviceAdapter adapter, AdapterContext adapterContext); void setOldIdentities(Set<IdentitySchemaNode> oldIdentities);  }