Search in sources :

Example 1 with NetconfCapabilityChange

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());
}
Also used : Capability(org.opendaylight.netconf.api.capability.Capability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) YangModuleCapability(org.opendaylight.netconf.api.capability.YangModuleCapability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) Capabilities(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities) NetconfCapabilityChange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with NetconfCapabilityChange

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);
}
Also used : NetconfCapabilityChangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder) NetconfCapabilityChange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) NetconfNotification(org.opendaylight.netconf.notifications.NetconfNotification) Test(org.junit.Test)

Example 3 with NetconfCapabilityChange

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();
}
Also used : NetconfCapabilityChangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder) ChangedByBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.changed.by.parms.ChangedByBuilder) ServerBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.changed.by.parms.changed.by.server.or.user.ServerBuilder)

Example 4 with NetconfCapabilityChange

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();
}
Also used : NetconfCapabilityChangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder) ChangedByBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.changed.by.parms.ChangedByBuilder) ServerBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.changed.by.parms.changed.by.server.or.user.ServerBuilder)

Example 5 with NetconfCapabilityChange

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);
}
Also used : StreamNameType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType) BaseNotificationPublisherRegistration(org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration) NetconfCapabilityChangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder) NetconfNotificationListener(org.opendaylight.netconf.notifications.NetconfNotificationListener) NotificationListenerRegistration(org.opendaylight.netconf.notifications.NotificationListenerRegistration) NetconfCapabilityChange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange) NetconfNotification(org.opendaylight.netconf.notifications.NetconfNotification) Test(org.junit.Test)

Aggregations

NetconfCapabilityChangeBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder)4 Test (org.junit.Test)3 NetconfCapabilityChange (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange)3 NetconfNotification (org.opendaylight.netconf.notifications.NetconfNotification)2 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)2 ChangedByBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.changed.by.parms.ChangedByBuilder)2 ServerBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.changed.by.parms.changed.by.server.or.user.ServerBuilder)2 HashSet (java.util.HashSet)1 BasicCapability (org.opendaylight.netconf.api.capability.BasicCapability)1 Capability (org.opendaylight.netconf.api.capability.Capability)1 YangModuleCapability (org.opendaylight.netconf.api.capability.YangModuleCapability)1 BaseNotificationPublisherRegistration (org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration)1 NetconfNotificationListener (org.opendaylight.netconf.notifications.NetconfNotificationListener)1 NotificationListenerRegistration (org.opendaylight.netconf.notifications.NotificationListenerRegistration)1 StreamNameType (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType)1 Capabilities (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities)1