use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange in project netconf by opendaylight.
the class NetconfCapabilityMonitoringServiceTest method testOnCapabilitiesChanged.
@Test
public void testOnCapabilitiesChanged() throws Exception {
final String capUri = "test";
final Uri uri = new Uri(capUri);
final HashSet<Capability> testCaps = new HashSet<>();
testCaps.add(new BasicCapability(capUri));
final ArgumentCaptor<NetconfCapabilityChange> capabilityChangeCaptor = ArgumentCaptor.forClass(NetconfCapabilityChange.class);
final ArgumentCaptor<Capabilities> monitoringListenerCaptor = ArgumentCaptor.forClass(Capabilities.class);
// add capability
monitoringService.onCapabilitiesChanged(testCaps, Set.of());
// remove capability
monitoringService.onCapabilitiesChanged(Set.of(), testCaps);
verify(listener, times(3)).onCapabilitiesChanged(monitoringListenerCaptor.capture());
verify(notificationPublisher, times(2)).onCapabilityChanged(capabilityChangeCaptor.capture());
// verify listener calls
final List<Capabilities> listenerValues = monitoringListenerCaptor.getAllValues();
final List<Uri> afterRegisterState = listenerValues.get(0).getCapability();
final List<Uri> afterAddState = listenerValues.get(1).getCapability();
final List<Uri> afterRemoveState = listenerValues.get(2).getCapability();
assertEquals(capabilitiesSize, afterRegisterState.size());
assertEquals(capabilitiesSize + 1, afterAddState.size());
assertEquals(capabilitiesSize, afterRemoveState.size());
assertFalse(afterRegisterState.contains(uri));
assertTrue(afterAddState.contains(uri));
assertFalse(afterRemoveState.contains(uri));
// verify notification publication
final List<NetconfCapabilityChange> publisherValues = capabilityChangeCaptor.getAllValues();
final NetconfCapabilityChange afterAdd = publisherValues.get(0);
final NetconfCapabilityChange afterRemove = publisherValues.get(1);
assertEquals(Set.of(uri), Set.copyOf(afterAdd.getAddedCapability()));
assertEquals(List.of(), afterAdd.getDeletedCapability());
assertEquals(Set.of(uri), Set.copyOf(afterRemove.getDeletedCapability()));
assertEquals(List.of(), afterRemove.getAddedCapability());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange in project netconf by opendaylight.
the class NotificationsTransformUtilTest method testTransform.
@Test
public void testTransform() throws Exception {
final NetconfCapabilityChangeBuilder netconfCapabilityChangeBuilder = new NetconfCapabilityChangeBuilder();
netconfCapabilityChangeBuilder.setAddedCapability(Lists.newArrayList(new Uri("uri1"), new Uri("uri1")));
netconfCapabilityChangeBuilder.setDeletedCapability(Lists.newArrayList(new Uri("uri4"), new Uri("uri3")));
final NetconfCapabilityChange capabilityChange = netconfCapabilityChangeBuilder.build();
final NetconfNotification transform = UTIL.transform(capabilityChange, DATE, SchemaPath.create(true, NetconfCapabilityChange.QNAME));
final String serialized = XmlUtil.toString(transform.getDocument());
compareXml(EXPECTED_NOTIFICATION, serialized);
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange in project netconf by opendaylight.
the class NetconfCapabilityMonitoringService method computeDiff.
private static NetconfCapabilityChange computeDiff(final Set<Capability> added, final Set<Capability> removed) {
final NetconfCapabilityChangeBuilder netconfCapabilityChangeBuilder = new NetconfCapabilityChangeBuilder();
netconfCapabilityChangeBuilder.setChangedBy(new ChangedByBuilder().setServerOrUser(new ServerBuilder().setServer(Empty.value()).build()).build());
netconfCapabilityChangeBuilder.setDeletedCapability(Lists.newArrayList(Collections2.transform(removed, CAPABILITY_TO_URI)));
netconfCapabilityChangeBuilder.setAddedCapability(Lists.newArrayList(Collections2.transform(added, CAPABILITY_TO_URI)));
// TODO modified should be computed ... but why ?
netconfCapabilityChangeBuilder.setModifiedCapability(Collections.emptyList());
return netconfCapabilityChangeBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange in project netconf by opendaylight.
the class CapabilityChangeNotificationProducerTest method changedCapabilitesFrom.
private static NetconfCapabilityChange changedCapabilitesFrom(final List<Uri> added, final List<Uri> deleted) {
NetconfCapabilityChangeBuilder netconfCapabilityChangeBuilder = new NetconfCapabilityChangeBuilder();
netconfCapabilityChangeBuilder.setChangedBy(new ChangedByBuilder().setServerOrUser(new ServerBuilder().setServer(Empty.value()).build()).build());
netconfCapabilityChangeBuilder.setModifiedCapability(Collections.emptyList());
netconfCapabilityChangeBuilder.setAddedCapability(added);
netconfCapabilityChangeBuilder.setDeletedCapability(deleted);
return netconfCapabilityChangeBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange in project netconf by opendaylight.
the class NetconfNotificationManagerTest method testNotificationListeners.
@Test
public void testNotificationListeners() throws Exception {
final NetconfNotificationManager netconfNotificationManager = createManager();
final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration = netconfNotificationManager.registerBaseNotificationPublisher();
final NetconfCapabilityChangeBuilder capabilityChangedBuilder = new NetconfCapabilityChangeBuilder();
final NetconfNotificationListener listener = mock(NetconfNotificationListener.class);
doNothing().when(listener).onNotification(any(StreamNameType.class), any(NetconfNotification.class));
final NotificationListenerRegistration notificationListenerRegistration = netconfNotificationManager.registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener);
final NetconfCapabilityChange notification = capabilityChangedBuilder.build();
baseNotificationPublisherRegistration.onCapabilityChanged(notification);
verify(listener).onNotification(any(StreamNameType.class), any(NetconfNotification.class));
notificationListenerRegistration.close();
baseNotificationPublisherRegistration.onCapabilityChanged(notification);
verifyNoMoreInteractions(listener);
}
Aggregations