use of org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory in project netconf by opendaylight.
the class NetconfDeviceTest method getSchemaFactory.
private static EffectiveModelContextFactory getSchemaFactory() throws Exception {
final EffectiveModelContextFactory schemaFactory = mockClass(EffectiveModelContextFactory.class);
doReturn(Futures.immediateFuture(SCHEMA_CONTEXT)).when(schemaFactory).createEffectiveModelContext(any(Collection.class));
return schemaFactory;
}
use of org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory in project netconf by opendaylight.
the class NetconfDeviceTest method testNetconfDeviceMissingSource.
@Test
public void testNetconfDeviceMissingSource() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = getListener();
final EffectiveModelContextFactory schemaFactory = getSchemaFactory();
final SchemaRepository schemaRepository = getSchemaRepository();
// Make fallback attempt to fail due to empty resolved sources
final MissingSchemaSourceException schemaResolutionException = new MissingSchemaSourceException("fail first", TEST_SID);
doReturn(Futures.immediateFailedFuture(schemaResolutionException)).when(schemaRepository).getSchemaSource(eq(TEST_SID), eq(YangTextSchemaSource.class));
doAnswer(invocation -> {
if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
return Futures.immediateFailedFuture(schemaResolutionException);
} else {
return Futures.immediateFuture(SCHEMA_CONTEXT);
}
}).when(schemaFactory).createEffectiveModelContext(anyCollection());
final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id, schemaContext) -> {
final Module first = Iterables.getFirst(SCHEMA_CONTEXT.getModules(), null);
final QName qName = QName.create(first.getQNameModule(), first.getName());
final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName);
final NetconfStateSchemas.RemoteYangSchema source2 = new NetconfStateSchemas.RemoteYangSchema(QName.create(first.getQNameModule(), "test-module2"));
return new NetconfStateSchemas(Sets.newHashSet(source1, source2));
};
final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, stateSchemasResolver);
final NetconfDevice device = new NetconfDeviceBuilder().setReconnectOnSchemasChange(true).setSchemaResourcesDTO(schemaResourcesDTO).setGlobalProcessingExecutor(getExecutor()).setBaseSchemas(BASE_SCHEMAS).setId(getId()).setSalFacade(facade).build();
// Monitoring supported
final NetconfSessionPreferences sessionCaps = getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
device.onRemoteSessionUp(sessionCaps, listener);
verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollection());
}
use of org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory in project yangtools by opendaylight.
the class OpenconfigVerSharedSchemaRepositoryTest method testSemVerSharedSchemaRepository.
@Test
public void testSemVerSharedSchemaRepository() throws Exception {
final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("openconfig-ver-shared-schema-repo-test");
final SettableSchemaProvider<IRSchemaSource> bar = getImmediateYangSourceProviderFromResource("/openconfig-version/openconfigver-shared-schema-repository/bar@2016-01-01.yang");
bar.register(sharedSchemaRepository);
bar.setResult();
final SettableSchemaProvider<IRSchemaSource> foo = getImmediateYangSourceProviderFromResource("/openconfig-version/openconfigver-shared-schema-repository/foo.yang");
foo.register(sharedSchemaRepository);
foo.setResult();
final SettableSchemaProvider<IRSchemaSource> semVer = getImmediateYangSourceProviderFromResource("/openconfig-version/openconfigver-shared-schema-repository/openconfig-extensions.yang");
semVer.register(sharedSchemaRepository);
semVer.setResult();
final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory(SchemaContextFactoryConfiguration.builder().setStatementParserMode(StatementParserMode.SEMVER_MODE).build());
final ListenableFuture<EffectiveModelContext> inetAndTopologySchemaContextFuture = fact.createEffectiveModelContext(bar.getId(), foo.getId(), semVer.getId());
assertTrue(inetAndTopologySchemaContextFuture.isDone());
assertSchemaContext(inetAndTopologySchemaContextFuture.get(), 3);
final ListenableFuture<EffectiveModelContext> barSchemaContextFuture = fact.createEffectiveModelContext(bar.getId(), semVer.getId());
assertTrue(barSchemaContextFuture.isDone());
assertSchemaContext(barSchemaContextFuture.get(), 2);
}
use of org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory in project netconf by opendaylight.
the class NetconfDeviceTest method testNetconfDeviceFailFirstSchemaFailSecondEmpty.
@Test
public void testNetconfDeviceFailFirstSchemaFailSecondEmpty() throws Exception {
final ArrayList<String> capList = Lists.newArrayList(TEST_CAPABILITY);
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = getListener();
final EffectiveModelContextFactory schemaFactory = getSchemaFactory();
final SchemaRepository schemaRepository = getSchemaRepository();
// Make fallback attempt to fail due to empty resolved sources
final SchemaResolutionException schemaResolutionException = new SchemaResolutionException("fail first", Collections.emptyList(), HashMultimap.create());
doReturn(Futures.immediateFailedFuture(schemaResolutionException)).when(schemaFactory).createEffectiveModelContext(anyCollection());
final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, STATE_SCHEMAS_RESOLVER);
final NetconfDevice device = new NetconfDeviceBuilder().setReconnectOnSchemasChange(true).setSchemaResourcesDTO(schemaResourcesDTO).setGlobalProcessingExecutor(getExecutor()).setId(getId()).setSalFacade(facade).setBaseSchemas(BASE_SCHEMAS).build();
// Monitoring not supported
final NetconfSessionPreferences sessionCaps = getSessionCaps(false, capList);
device.onRemoteSessionUp(sessionCaps, listener);
verify(facade, timeout(5000)).onDeviceDisconnected();
verify(listener, timeout(5000)).close();
verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollection());
}
use of org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory in project netconf by opendaylight.
the class NetconfDeviceTest method testNetconfDeviceNotificationsModelNotPresentWithCapability.
@Test
public void testNetconfDeviceNotificationsModelNotPresentWithCapability() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = getListener();
final EffectiveModelContextFactory schemaContextProviderFactory = getSchemaFactory();
final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
final NetconfDevice device = new NetconfDeviceBuilder().setSchemaResourcesDTO(schemaResourcesDTO).setGlobalProcessingExecutor(getExecutor()).setId(getId()).setSalFacade(facade).setBaseSchemas(BASE_SCHEMAS).build();
final NetconfDevice netconfSpy = spy(device);
final NetconfSessionPreferences sessionCaps = getSessionCaps(false, Lists.newArrayList(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0));
netconfSpy.onRemoteSessionUp(sessionCaps, listener);
final ArgumentCaptor<NetconfSessionPreferences> argument = ArgumentCaptor.forClass(NetconfSessionPreferences.class);
verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), argument.capture(), any(DOMRpcService.class), isNull());
List<String> notificationModulesName = Arrays.asList(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.$YangModuleInfoImpl.getInstance().getName().toString(), org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.$YangModuleInfoImpl.getInstance().getName().toString());
final Set<AvailableCapability> resolvedCapabilities = argument.getValue().getNetconfDeviceCapabilities().getResolvedCapabilities();
assertEquals(2, resolvedCapabilities.size());
assertTrue(resolvedCapabilities.stream().anyMatch(entry -> notificationModulesName.contains(entry.getCapability())));
}
Aggregations