use of org.opendaylight.netconf.api.capability.BasicCapability in project netconf by opendaylight.
the class NetconfCapabilityMonitoringServiceTest method setUp.
@Before
public void setUp() throws Exception {
doReturn(XMLNamespace.of(TEST_MODULE_NAMESPACE.getValue())).when(moduleMock).getNamespace();
doReturn(TEST_MODULE_NAME).when(moduleMock).getName();
doReturn(Optional.of(TEST_MODULE_DATE)).when(moduleMock).getRevision();
moduleCapability1 = new YangModuleCapability(moduleMock, TEST_MODULE_CONTENT);
capabilities.add(moduleCapability1);
doReturn(XMLNamespace.of(TEST_MODULE_NAMESPACE.getValue())).when(moduleMock2).getNamespace();
doReturn(TEST_MODULE_NAME).when(moduleMock2).getName();
doReturn(Optional.of(TEST_MODULE_DATE2)).when(moduleMock2).getRevision();
moduleCapability2 = new YangModuleCapability(moduleMock2, TEST_MODULE_CONTENT2);
capabilities.add(new BasicCapability("urn:ietf:params:netconf:base:1.0"));
capabilities.add(new BasicCapability("urn:ietf:params:netconf:base:1.1"));
capabilities.add(new BasicCapability("urn:ietf:params:xml:ns:yang:ietf-inet-types?module=ietf-inet-types&" + "revision=2010-09-24"));
doReturn(capabilities).when(operationServiceFactoryMock).getCapabilities();
doReturn(null).when(operationServiceFactoryMock).registerCapabilityListener(any(NetconfCapabilityMonitoringService.class));
doNothing().when(listener).onCapabilitiesChanged(any());
doNothing().when(listener).onSchemasChanged(any());
doNothing().when(notificationPublisher).onCapabilityChanged(any());
monitoringService = new NetconfCapabilityMonitoringService(operationServiceFactoryMock);
monitoringService.onCapabilitiesChanged(capabilities, Set.of());
monitoringService.setNotificationPublisher(notificationPublisher);
monitoringService.registerListener(listener);
capabilitiesSize = monitoringService.getCapabilities().getCapability().size();
}
use of org.opendaylight.netconf.api.capability.BasicCapability 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.netconf.api.capability.BasicCapability in project netconf by opendaylight.
the class NetconfDeviceSimulator method createDispatcher.
private NetconfServerDispatcherImpl createDispatcher(final Set<Capability> capabilities, final SchemaSourceProvider<YangTextSchemaSource> sourceProvider) {
final Set<Capability> transformedCapabilities = new HashSet<>(Collections2.transform(capabilities, input -> {
if (sendFakeSchema) {
sendFakeSchema = false;
return new FakeCapability((YangModuleCapability) input);
} else {
return input;
}
}));
transformedCapabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0"));
final NetconfMonitoringService monitoringService1 = new DummyMonitoringService(transformedCapabilities);
final SessionIdProvider idProvider = new SessionIdProvider();
final NetconfOperationServiceFactory aggregatedNetconfOperationServiceFactory = createOperationServiceFactory(sourceProvider, transformedCapabilities, monitoringService1, idProvider);
final Set<String> serverCapabilities = configuration.getCapabilities();
final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new TesttoolNegotiationFactory(hashedWheelTimer, aggregatedNetconfOperationServiceFactory, idProvider, configuration.getGenerateConfigsTimeout(), monitoringService1, serverCapabilities);
final ServerChannelInitializer serverChannelInitializer = new ServerChannelInitializer(serverNegotiatorFactory);
return new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
}
use of org.opendaylight.netconf.api.capability.BasicCapability in project netconf by opendaylight.
the class AggregatedNetconfOperationServiceFactoryTest method setUp.
@Before
public void setUp() throws Exception {
factory1Caps.add(new BasicCapability("AAA"));
factory1Caps.add(new BasicCapability("BBB"));
factory2Caps.add(new BasicCapability("CCC"));
factory2Caps.add(new BasicCapability("DDD"));
aggregatedFactory = new AggregatedNetconfOperationServiceFactory();
aggregatedFactory.registerCapabilityListener(listener1);
aggregatedFactory.registerCapabilityListener(listener2);
doReturn(autoCloseable1).when(factory1).registerCapabilityListener(listener1);
doReturn(autoCloseable2).when(factory1).registerCapabilityListener(listener2);
doReturn(factory1Caps).when(factory1).getCapabilities();
doReturn(autoCloseable1).when(factory2).registerCapabilityListener(listener1);
doReturn(autoCloseable2).when(factory2).registerCapabilityListener(listener2);
doReturn(factory2Caps).when(factory2).getCapabilities();
doNothing().when(autoCloseable1).close();
doNothing().when(autoCloseable2).close();
doReturn(autoCloseable3).when(factory1).registerCapabilityListener(listener3);
doReturn(autoCloseable3).when(factory2).registerCapabilityListener(listener3);
}
use of org.opendaylight.netconf.api.capability.BasicCapability in project netconf by opendaylight.
the class NetconfCapabilityMonitoringServiceTest method testListeners.
@Test
public void testListeners() throws Exception {
HashSet<Capability> added = new HashSet<>();
added.add(new BasicCapability("toAdd"));
monitoringService.onCapabilitiesChanged(added, Set.of());
// onCapabilitiesChanged and onSchemasChanged are invoked also after listener registration
verify(listener, times(2)).onCapabilitiesChanged(any());
verify(listener, times(2)).onSchemasChanged(any());
}
Aggregations