Refactor AbstractDataBrokerTestCustomizer
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 7 Oct 2020 20:41:32 +0000 (22:41 +0200)
committerAnil Belur <abelur@linuxfoundation.org>
Wed, 19 Jun 2024 00:41:34 +0000 (10:41 +1000)
Since we are dealing with binding classes and their translation,
make sure we operate on BindingRuntimeContext as the primary
entrypoint for tests and other harness.

This allows us to eliminate a few testing-only classes, which
were dealing with EffectiveModelContext -> BindingRuntimeContext
translation.

JIRA: MDSAL-578
Change-Id: I2539ea427cdc6d8a76699bb59fcad1f9e02f60dd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-runtime-spi/src/main/java/org/opendaylight/mdsal/binding/runtime/spi/BindingRuntimeHelpers.java

index 62c36378ab99b3318aab5b605beedef12923267d..5d62c8e5bc799c845a76148a5f525579f4f24b3a 100644 (file)
@@ -75,6 +75,20 @@ public final class BindingRuntimeHelpers {
         }
     }
 
+    public static @NonNull BindingRuntimeContext createRuntimeContext(
+            final Collection<? extends YangModuleInfo> infos) {
+        final ModuleInfoSnapshot snapshot;
+
+        try {
+            snapshot = prepareContext(ServiceLoaderState.ParserFactory.INSTANCE, infos);
+        } catch (YangParserException e) {
+            throw new IllegalStateException("Failed to parse models", e);
+        }
+
+        return new DefaultBindingRuntimeContext(
+            ServiceLoaderState.Generator.INSTANCE.generateTypeMapping(snapshot.getEffectiveModelContext()), snapshot);
+    }
+
     public static @NonNull BindingRuntimeContext createRuntimeContext(final YangParserFactory parserFactory,
             final BindingRuntimeGenerator generator, final Class<?>... classes) throws YangParserException {
         return createRuntimeContext(parserFactory, generator, Arrays.asList(classes));