Remove Rfc8040 class 85/106985/9
authorMatej Sramcik <matej.sramcik@pantheon.tech>
Mon, 24 Jul 2023 07:46:44 +0000 (09:46 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 27 Jul 2023 10:22:41 +0000 (12:22 +0200)
This class only holds ietf-yang-library constants. Move those constants
to their users are eliminate the class.

JIRA: NETCONF-1092
Change-Id: Id089620022afc629ade29451dcc9ccc140bb54fa
Signed-off-by: Matej Sramcik <matej.sramcik@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040.java [deleted file]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/legacy/SchemaContextHandler.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImpl.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/monitoring/RestconfStateStreamsTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfImplTest.java

diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040.java
deleted file mode 100644 (file)
index 7906dee..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.restconf.nb.rfc8040;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.$YangModuleInfoImpl;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.Module;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.Revision;
-
-/**
- * Common constants defined and relating to RFC8040.
- */
-public final class Rfc8040 {
-    private Rfc8040() {
-        // Hidden on purpose
-    }
-
-    /**
-     * Constants for ietf-yang-library model.
-     */
-    // FIXME: split this out
-    public static final class IetfYangLibrary {
-        public static final QNameModule MODULE_QNAME = $YangModuleInfoImpl.getInstance().getName().getModule();
-        public static final Revision REVISION = MODULE_QNAME.getRevision().orElseThrow();
-
-        public static final QName MODULE_SET_ID_LEAF_QNAME = QName.create(MODULE_QNAME, "module-set-id").intern();
-
-        public static final QName MODULE_QNAME_LIST = Module.QNAME;
-
-        private IetfYangLibrary() {
-            // Hidden on purpose
-        }
-    }
-}
index 7c33f2b0c257d80b174d36ce192e10020f86c014..2905dfdeea4f5739f97888058dcb34cac78e6f68 100644 (file)
@@ -25,8 +25,9 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesState;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.Module;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.Module.ConformanceType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.module.Deviation;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.module.Submodule;
@@ -66,17 +67,19 @@ public final class SchemaContextHandler implements EffectiveModelContextListener
     private static final Logger LOG = LoggerFactory.getLogger(SchemaContextHandler.class);
 
     private static final NodeIdentifier MODULE_CONFORMANCE_NODEID =
-        NodeIdentifier.create(QName.create(IetfYangLibrary.MODULE_QNAME, "conformance-type").intern());
+        NodeIdentifier.create(QName.create(YangLibrary.QNAME, "conformance-type").intern());
     private static final NodeIdentifier MODULE_FEATURE_NODEID =
-        NodeIdentifier.create(QName.create(IetfYangLibrary.MODULE_QNAME, "feature").intern());
+        NodeIdentifier.create(QName.create(YangLibrary.QNAME, "feature").intern());
     private static final NodeIdentifier MODULE_NAME_NODEID =
-        NodeIdentifier.create(QName.create(IetfYangLibrary.MODULE_QNAME, "name").intern());
+        NodeIdentifier.create(QName.create(YangLibrary.QNAME, "name").intern());
     private static final NodeIdentifier MODULE_NAMESPACE_NODEID =
-        NodeIdentifier.create(QName.create(IetfYangLibrary.MODULE_QNAME, "namespace").intern());
+        NodeIdentifier.create(QName.create(YangLibrary.QNAME, "namespace").intern());
     private static final NodeIdentifier MODULE_REVISION_NODEID =
-        NodeIdentifier.create(QName.create(IetfYangLibrary.MODULE_QNAME, "revision").intern());
+        NodeIdentifier.create(QName.create(YangLibrary.QNAME, "revision").intern());
     private static final NodeIdentifier MODULE_SCHEMA_NODEID =
-        NodeIdentifier.create(QName.create(IetfYangLibrary.MODULE_QNAME, "schema").intern());
+        NodeIdentifier.create(QName.create(YangLibrary.QNAME, "schema").intern());
+    private static final NodeIdentifier MODULE_SET_ID_LEAF_NODEID =
+        NodeIdentifier.create(QName.create(YangLibrary.QNAME, "module-set-id").intern());
 
     private final AtomicInteger moduleSetId = new AtomicInteger();
     private final DOMDataBroker domDataBroker;
@@ -103,7 +106,7 @@ public final class SchemaContextHandler implements EffectiveModelContextListener
     public void onModelContextUpdated(final EffectiveModelContext context) {
         schemaContext = requireNonNull(context);
 
-        if (context.findModuleStatement(IetfYangLibrary.MODULE_QNAME).isPresent()) {
+        if (context.findModuleStatement(YangLibrary.QNAME.getModule()).isPresent()) {
             putData(mapModulesByIetfYangLibraryYang(context, String.valueOf(moduleSetId.incrementAndGet())));
         }
     }
@@ -150,13 +153,13 @@ public final class SchemaContextHandler implements EffectiveModelContextListener
     public static ContainerNode mapModulesByIetfYangLibraryYang(final EffectiveModelContext context,
             final String moduleSetId) {
         final var mapBuilder = Builders.mapBuilder()
-            .withNodeIdentifier(new NodeIdentifier(IetfYangLibrary.MODULE_QNAME_LIST));
+            .withNodeIdentifier(new NodeIdentifier(Module.QNAME));
         for (var module : context.getModules()) {
-            fillMapByModules(mapBuilder, IetfYangLibrary.MODULE_QNAME_LIST, false, module, context);
+            fillMapByModules(mapBuilder, Module.QNAME, false, module, context);
         }
         return Builders.containerBuilder()
             .withNodeIdentifier(new NodeIdentifier(ModulesState.QNAME))
-            .withChild(ImmutableNodes.leafNode(IetfYangLibrary.MODULE_SET_ID_LEAF_QNAME, moduleSetId))
+            .withChild(ImmutableNodes.leafNode(MODULE_SET_ID_LEAF_NODEID, moduleSetId))
             .withChild(mapBuilder.build())
             .build();
     }
index 3e5b0d02a7110f5c60f6fae305e35fefa85e6033..c52ba89f92bc19786aac3c9e6e6133521fcf2859 100644 (file)
@@ -11,11 +11,11 @@ import static java.util.Objects.requireNonNull;
 
 import javax.ws.rs.Path;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.Restconf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
@@ -24,6 +24,7 @@ import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
 @Path("/")
 public class RestconfImpl implements RestconfService {
     private static final QName YANG_LIBRARY_VERSION = QName.create(Restconf.QNAME, "yang-library-version").intern();
+    private static final String YANG_LIBRARY_REVISION = YangLibrary.QNAME.getRevision().orElseThrow().toString();
 
     private final DatabindProvider databindProvider;
 
@@ -42,6 +43,6 @@ public class RestconfImpl implements RestconfService {
         stack.enterDataTree(YANG_LIBRARY_VERSION);
 
         return NormalizedNodePayload.of(InstanceIdentifierContext.ofStack(stack),
-            ImmutableNodes.leafNode(YANG_LIBRARY_VERSION, IetfYangLibrary.REVISION.toString()));
+            ImmutableNodes.leafNode(YANG_LIBRARY_VERSION, YANG_LIBRARY_REVISION));
     }
 }
index 234eab97b937a5c8717e5d56ed8b9c09ff9718c1..16af6ea2003845803be4270d0ff160988b85afbf 100644 (file)
@@ -16,15 +16,13 @@ import java.time.Instant;
 import java.time.OffsetDateTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
-import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.legacy.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.Module;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.module.Deviation;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -34,7 +32,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,15 +44,12 @@ public class RestconfStateStreamsTest {
 
     private static EffectiveModelContext schemaContext;
     private static EffectiveModelContext schemaContextMonitoring;
-    private static Collection<? extends Module> modulesRest;
 
     @BeforeClass
     public static void loadTestSchemaContextAndModules() throws Exception {
         // FIXME: assemble these from dependencies
         schemaContext = YangParserTestUtils.parseYangResourceDirectory("/modules/restconf-module-testing");
         schemaContextMonitoring = YangParserTestUtils.parseYangResourceDirectory("/modules");
-        modulesRest = YangParserTestUtils
-                .parseYangFiles(TestRestconfUtils.loadFiles("/modules/restconf-module-testing")).getModules();
     }
 
     /**
@@ -157,10 +151,10 @@ public class RestconfStateStreamsTest {
 
         for (var child : containerNode.body()) {
             if (child instanceof LeafNode) {
-                assertEquals(IetfYangLibrary.MODULE_SET_ID_LEAF_QNAME, child.name().getNodeType());
+                assertEquals(QName.create(Module.QNAME, "module-set-id"), child.name().getNodeType());
             }
             if (child instanceof MapNode mapChild) {
-                assertEquals(IetfYangLibrary.MODULE_QNAME_LIST, child.name().getNodeType());
+                assertEquals(Module.QNAME, child.name().getNodeType());
                 for (var mapEntryNode : mapChild.body()) {
                     String name = "";
                     String revision = "";
@@ -183,21 +177,10 @@ public class RestconfStateStreamsTest {
             }
         }
 
-        verifyLoadedModules(modulesRest, loadedModules);
-    }
-
-    /**
-     * Verify if correct modules were loaded into Restconf module by comparison with modules from
-     * <code>SchemaContext</code>.
-     * @param expectedModules Modules from <code>SchemaContext</code>
-     * @param loadedModules Loaded modules into Restconf module
-     */
-    private static void verifyLoadedModules(final Collection<? extends Module> expectedModules,
-            final Map<String, String> loadedModules) {
+        final var expectedModules = schemaContext.getModules();
         assertEquals("Number of loaded modules is not as expected", expectedModules.size(), loadedModules.size());
-        for (final Module m : expectedModules) {
+        for (var m : expectedModules) {
             final String name = m.getName();
-
             final String revision = loadedModules.get(name);
             assertNotNull("Expected module not found", revision);
             assertEquals("Incorrect revision of loaded module", Revision.ofNullable(revision), m.getRevision());
index e21c3299dc1e7f9a4891f03ac8f368833b2f548e..ce0039fa622c1bfb1f21c02ec3e99493206c6907 100644 (file)
@@ -10,19 +10,15 @@ package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 import static org.junit.Assert.assertEquals;
 
 import org.junit.Test;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
-import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class RestconfImplTest {
     @Test
     public void restImplTest() {
         final var context = YangParserTestUtils.parseYangResourceDirectory("/restconf/impl");
-        final RestconfImpl restconfImpl = new RestconfImpl(() -> DatabindContext.ofModel(context));
-        final NormalizedNodePayload libraryVersion = restconfImpl.getLibraryVersion();
-        final LeafNode<?> value = (LeafNode<?>) libraryVersion.getData();
-        assertEquals(IetfYangLibrary.REVISION.toString(), value.body());
+        final var restconfImpl = new RestconfImpl(() -> DatabindContext.ofModel(context));
+        final var libraryVersion = restconfImpl.getLibraryVersion();
+        assertEquals("2019-01-04", libraryVersion.getData().body());
     }
 }