Move ErrorTags 37/108537/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 20 Oct 2023 12:44:02 +0000 (14:44 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 20 Oct 2023 14:47:49 +0000 (16:47 +0200)
ErrorTags is primarily a JAX-RS mapping utility, move it to restconf-nb
to hide it from the outside world.

JIRA: NETCONF-773
Change-Id: I3fc5f4022da40a8fc536a7e9d6ec965344c1223f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-common/src/test/java/org/opendaylight/restconf/common/ErrorTagsTest.java [deleted file]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/legacy/ErrorTags.java [moved from restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/ErrorTags.java with 93% similarity]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/legacy/ErrorTagsTest.java [new file with mode: 0644]
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifierTest.java

diff --git a/restconf/restconf-common/src/test/java/org/opendaylight/restconf/common/ErrorTagsTest.java b/restconf/restconf-common/src/test/java/org/opendaylight/restconf/common/ErrorTagsTest.java
deleted file mode 100644 (file)
index 3c8841e..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2021 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.restconf.common;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.stream.Stream;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.MethodSource;
-import org.opendaylight.yangtools.yang.common.ErrorTag;
-
-public class ErrorTagsTest {
-    @MethodSource("testStatusOfData")
-    @ParameterizedTest(name = "{0} => {1}")
-    void testStatusOf(final String tagName, final int status) {
-        assertEquals(status, ErrorTags.statusOf(new ErrorTag(tagName)).getStatusCode());
-    }
-
-    static Stream<Object[]> testStatusOfData() {
-        return Stream.of(new Object[][] {
-            { "in-use", 409 },
-            { "invalid-value", 400 },
-            { "too-big", 413 },
-            { "missing-attribute", 400 },
-            { "bad-attribute", 400 },
-            { "unknown-attribute", 400 },
-            { "missing-element", 400 },
-            { "bad-element", 400 },
-            { "unknown-element", 400 },
-            { "unknown-namespace", 400 },
-            { "access-denied", 403 },
-            { "lock-denied", 409 },
-            { "resource-denied", 409 },
-            { "rollback-failed", 500 },
-            { "data-exists", 409 },
-            { "data-missing", 409 },
-            { "operation-not-supported", 501 },
-            { "operation-failed", 500 },
-            { "partial-operation", 500 },
-            { "malformed-message", 400 },
-            { "resource-denied-transport", 503 }
-        });
-    }
-
-}
index ff3f94278cf0a93da1a9fe640055ba570112ed30..5177b1fff512258db286f9c1795fbe34fc529c43 100644 (file)
@@ -29,11 +29,11 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.Provider;
-import org.opendaylight.restconf.common.ErrorTags;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
+import org.opendaylight.restconf.nb.rfc8040.legacy.ErrorTags;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.errors.Errors;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.errors.errors.Error;
 import org.opendaylight.yangtools.yang.common.QName;
similarity index 93%
rename from restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/ErrorTags.java
rename to restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/legacy/ErrorTags.java
index b2d3b810e508cc3aa90b257864391a12879fc676..6e1072378c9d25fe5a3aedaf450fb86d0ed2558b 100644 (file)
@@ -5,11 +5,10 @@
  * 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.common;
+package org.opendaylight.restconf.nb.rfc8040.legacy;
 
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableMap;
 import javax.ws.rs.core.Response.Status;
 import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -22,7 +21,6 @@ import org.slf4j.LoggerFactory;
  * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-7">RFC8040 section 7</a>, we also define tags which
  * map to useful {@link Status} codes.
  */
-@Beta
 @NonNullByDefault
 public final class ErrorTags {
     /**
@@ -71,7 +69,7 @@ public final class ErrorTags {
      * @throws NullPointerException if {@code tag} is null
      */
     public static Status statusOf(final ErrorTag tag) {
-        final Status known = WELL_KNOWN_ERROR_TAGS.get(requireNonNull(tag));
+        final var known = WELL_KNOWN_ERROR_TAGS.get(requireNonNull(tag));
         return known != null ? known : Status.INTERNAL_SERVER_ERROR;
     }
 
@@ -80,8 +78,8 @@ public final class ErrorTags {
         // HTTP status 409 as specified by RFC8040 (and all previous drafts). See the discussion in:
         // https://www.rfc-editor.org/errata/eid5565
         // https://mailarchive.ietf.org/arch/msg/netconf/hkVDdHK4xA74NgvXzWP0zObMiyY/
-        final String propName = "org.opendaylight.restconf.eid5565";
-        final String propValue = System.getProperty(propName, "disabled");
+        final var propName = "org.opendaylight.restconf.eid5565";
+        final var propValue = System.getProperty(propName, "disabled");
         switch (propValue) {
             case "enabled":
                 // RFC7231 interpretation: 404 Not Found
index 0b816ebbc4e22d0372f60e8c04952f226a2fe3a7..d2e398cd2d6a3983c5f836c9a9f144d00e5c07de 100644 (file)
@@ -25,8 +25,8 @@ import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
-import org.opendaylight.restconf.common.ErrorTags;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.nb.rfc8040.legacy.ErrorTags;
 import org.opendaylight.restconf.nb.rfc8040.legacy.InstanceIdentifierContext;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.SchemaExportContext;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/legacy/ErrorTagsTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/legacy/ErrorTagsTest.java
new file mode 100644 (file)
index 0000000..f278a32
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2021 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.restconf.nb.rfc8040.legacy;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.List;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+
+class ErrorTagsTest {
+    @ParameterizedTest(name = "{0} => {1}")
+    @MethodSource
+    void testStatusOf(final String tagName, final int status) {
+        assertEquals(status, ErrorTags.statusOf(new ErrorTag(tagName)).getStatusCode());
+    }
+
+    static List<Arguments> testStatusOf() {
+        return List.of(
+            Arguments.of("in-use", 409),
+            Arguments.of("invalid-value", 400),
+            Arguments.of("too-big", 413),
+            Arguments.of("missing-attribute", 400),
+            Arguments.of("bad-attribute", 400),
+            Arguments.of("unknown-attribute", 400),
+            Arguments.of("missing-element", 400),
+            Arguments.of("bad-element", 400),
+            Arguments.of("unknown-element", 400),
+            Arguments.of("unknown-namespace", 400),
+            Arguments.of("access-denied", 403),
+            Arguments.of("lock-denied", 409),
+            Arguments.of("resource-denied", 409),
+            Arguments.of("rollback-failed", 500),
+            Arguments.of("data-exists", 409),
+            Arguments.of("data-missing", 409),
+            Arguments.of("operation-not-supported", 501),
+            Arguments.of("operation-failed", 500),
+            Arguments.of("partial-operation", 500),
+            Arguments.of("malformed-message", 400),
+            Arguments.of("resource-denied-transport", 503));
+    }
+}
index 3b704d9f4bc5d3b5b76a4b4c0467bb015110644b..c6ed924800a93db874d156dc37e164a1dda333b7 100644 (file)
@@ -30,9 +30,9 @@ import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl;
 import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
-import org.opendaylight.restconf.common.ErrorTags;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
+import org.opendaylight.restconf.nb.rfc8040.legacy.ErrorTags;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.SchemaExportContext;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;