- private static SchemaContext parseYangStreams(final List<InputStream> streams) {
- CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
- .newBuild();
- final SchemaContext schemaContext;
- try {
- schemaContext = reactor.buildEffective(streams);
- } catch (ReactorException e) {
- throw new RuntimeException("Unable to build schema context from " + streams, e);
- }
- return schemaContext;
+ @Test
+ public void testNetconfDeviceAvailableCapabilitiesBuilding() throws Exception {
+ final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
+ final NetconfDeviceCommunicator listener = getListener();
+
+ final SchemaContextFactory schemaContextProviderFactory = getSchemaFactory();
+
+ final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
+ getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
+ final NetconfDevice device = new NetconfDeviceBuilder()
+ .setReconnectOnSchemasChange(true)
+ .setSchemaResourcesDTO(schemaResourcesDTO)
+ .setGlobalProcessingExecutor(getExecutor())
+ .setId(getId())
+ .setSalFacade(facade)
+ .build();
+ final NetconfDevice netconfSpy = Mockito.spy(device);
+
+ final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
+ Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
+ final Map<QName, AvailableCapability.CapabilityOrigin> moduleBasedCaps = new HashMap<>();
+ moduleBasedCaps.putAll(sessionCaps.getModuleBasedCapsOrigin());
+ moduleBasedCaps
+ .put(QName.create("(test:qname:side:loading)test"), AvailableCapability.CapabilityOrigin.UserDefined);
+
+ netconfSpy.onRemoteSessionUp(sessionCaps.replaceModuleCaps(moduleBasedCaps), listener);
+
+ final ArgumentCaptor<NetconfSessionPreferences> argument =
+ ArgumentCaptor.forClass(NetconfSessionPreferences.class);
+ verify(facade, timeout(5000))
+ .onDeviceConnected(any(SchemaContext.class), argument.capture(), any(DOMRpcService.class), isNull());
+ final NetconfDeviceCapabilities netconfDeviceCaps = argument.getValue().getNetconfDeviceCapabilities();
+
+ netconfDeviceCaps.getResolvedCapabilities()
+ .forEach(entry -> assertEquals("Builded 'AvailableCapability' schemas should match input capabilities.",
+ moduleBasedCaps.get(
+ QName.create(entry.getCapability())).getName(), entry.getCapabilityOrigin().getName()));
+ }
+
+ private static SchemaContextFactory getSchemaFactory() throws Exception {
+ final SchemaContextFactory schemaFactory = mockClass(SchemaContextFactory.class);
+ doReturn(Futures.immediateFuture(getSchema()))
+ .when(schemaFactory).createSchemaContext(any(Collection.class));
+ return schemaFactory;