+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.repo;
+
+import com.google.common.collect.SetMultimap;
+import com.google.common.util.concurrent.ListenableFuture;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
+
+public abstract class AbstractSchemaRepositoryTest {
+ static ListenableFuture<EffectiveModelContext> createSchemaContext(
+ final SetMultimap<QNameModule, QNameModule> modulesWithSupportedDeviations, final String... resources) {
+ final var sharedSchemaRepository = new SharedSchemaRepository();
+ final var requiredSources = Arrays.stream(resources)
+ .map(resource -> {
+ final var yangSource = assertYangTextResource(resource);
+ yangSource.register(sharedSchemaRepository);
+ yangSource.setResult();
+ return yangSource.getId();
+ })
+ .collect(Collectors.toUnmodifiableList());
+
+ return sharedSchemaRepository
+ .createEffectiveModelContextFactory(SchemaContextFactoryConfiguration.builder()
+ .setModulesDeviatedByModules(modulesWithSupportedDeviations)
+ .build())
+ .createEffectiveModelContext(requiredSources);
+ }
+
+ private static SettableSchemaProvider<IRSchemaSource> assertYangTextResource(final String resourceName) {
+ final IRSchemaSource yangSource;
+ try {
+ yangSource = TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName));
+ } catch (YangSyntaxErrorException | IOException e) {
+ throw new AssertionError("Failed to parse " + resourceName, e);
+ }
+ return SettableSchemaProvider.createImmediate(yangSource, IRSchemaSource.class);
+ }
+}