Clean up NetconfDeviceSimulator.addModuleCapability() 66/103166/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Nov 2022 20:21:37 +0000 (21:21 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Nov 2022 20:52:42 +0000 (21:52 +0100)
Use local variable type inference to shorten the code. Also use
different messages for acquire and read.

Change-Id: Ic429328469271419478e93e24bf02044d0ff6a8a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/NetconfDeviceSimulator.java

index 8407b94064082f1a14aec37d3ff05b424fa8a7dc..c60f5116c841728285ca344f1fdd23da492aee38 100644 (file)
@@ -343,18 +343,19 @@ public class NetconfDeviceSimulator implements Closeable {
 
     private static void addModuleCapability(final SharedSchemaRepository consumer, final Set<Capability> capabilities,
                                             final ModuleLike module) {
-        final SourceIdentifier moduleSourceIdentifier = new SourceIdentifier(module.getName(),
+        final var sourceId = new SourceIdentifier(module.getName(),
             module.getRevision().map(Revision::toString).orElse(null));
-        try {
 
-            final String moduleContent = consumer.getSchemaSource(moduleSourceIdentifier, YangTextSchemaSource.class)
-                .get().asCharSource(StandardCharsets.UTF_8).read();
-            capabilities.add(new YangModuleCapability(module, moduleContent));
-            //IOException would be thrown in creating SchemaContext already
-        } catch (final ExecutionException | InterruptedException | IOException e) {
+        final String moduleContent;
+        try {
+            moduleContent = consumer.getSchemaSource(sourceId, YangTextSchemaSource.class).get()
+                .asCharSource(StandardCharsets.UTF_8).read();
+        } catch (ExecutionException | InterruptedException | IOException e) {
             throw new IllegalStateException(
-                "Cannot retrieve schema source for module " + moduleSourceIdentifier + " from schema repository", e);
+                "Cannot retrieve schema source for module " + sourceId + " from schema repository", e);
         }
+
+        capabilities.add(new YangModuleCapability(module, moduleContent));
     }
 
     private static void registerSource(final SharedSchemaRepository consumer, final String resource,