Remove RestconfError.ErrorTag 30/97030/15
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 26 Jul 2021 21:08:07 +0000 (23:08 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 11 Sep 2021 02:09:04 +0000 (04:09 +0200)
The concept of an error-tag is shared between NETCONF and RESTCONF, or
anything iteracting with YANG. We have a unified definition in
yang.common, which NETCONF is already using. Eliminate
RestconfError.ErrorTag in favor of the yang.common.

Implementation updates are rather straighforward, except the fact we end
up having custom well-known error-tags. Deal with this through
relocation towards RESTCONF-specific ErrorTags, which concentrate all
related tasks.

JIRA: NETCONF-793
Change-Id: I21a79625a2509adabf50f706739c88f9a3359777
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
73 files changed:
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/ErrorTags.java [new file with mode: 0644]
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfDocumentedException.java
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfError.java
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/RestconfSchemaUtil.java
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/validation/RestconfValidationUtils.java
restconf/restconf-common/src/test/java/org/opendaylight/restconf/common/ErrorTagsTest.java [new file with mode: 0644]
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaRetrievalServiceImpl.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/PatchJsonBodyWriter.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/PatchXmlBodyWriter.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfDocumentedExceptionMapper.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlNormalizedNodeBodyReader.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlToPatchBodyReader.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/QueryParametersParser.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/AbstractBodyReaderTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPatchBodyReader.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPatchBodyReaderMountPoint.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReader.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReaderMountPoint.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReader.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReaderMountPoint.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/input/to/cnsn/test/RestPutListDataTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfErrorTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReader.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchStatusBodyWriter.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchStatusBodyWriter.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataStreamServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfTransaction.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureCallbackTx.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/ReadDataTransactionUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameter.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapperTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfSchemaServiceTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtilTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtilTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/ReadDataTransactionUtilTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameterTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifierTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/RestconfValidationTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java

diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/ErrorTags.java b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/ErrorTags.java
new file mode 100644 (file)
index 0000000..952218a
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * 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 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;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link ErrorTag} mapping to HTTP errors. Aside from the mappings defined by
+ * <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-7">RFC8040 section 7</a>, we also define tags which
+ * map to useful {@link Status} codes.
+ */
+@Beta
+@NonNullByDefault
+public final class ErrorTags {
+    /**
+     * Error reported when the request is valid, but the resource cannot be accessed. This tag typically maps to
+     * {@link Status#SERVICE_UNAVAILABLE}.
+     */
+    // FIXME: redefine as SERVICE_UNAVAILABLE? It would be more obvious
+    public static final ErrorTag RESOURCE_DENIED_TRANSPORT = new ErrorTag("resource-denied-transport");
+
+    private static final Logger LOG = LoggerFactory.getLogger(ErrorTags.class);
+    private static final ImmutableMap<ErrorTag, Status> WELL_KNOWN_ERROR_TAGS = ImmutableMap.<ErrorTag, Status>builder()
+        .put(ErrorTag.IN_USE,                     Status.CONFLICT)
+        .put(ErrorTag.INVALID_VALUE,              Status.BAD_REQUEST)
+        .put(ErrorTag.TOO_BIG,                    Status.REQUEST_ENTITY_TOO_LARGE)
+        .put(ErrorTag.MISSING_ATTRIBUTE,          Status.BAD_REQUEST)
+        .put(ErrorTag.BAD_ATTRIBUTE,              Status.BAD_REQUEST)
+        .put(ErrorTag.UNKNOWN_ATTRIBUTE,          Status.BAD_REQUEST)
+        .put(ErrorTag.MISSING_ELEMENT,            Status.BAD_REQUEST)
+        .put(ErrorTag.BAD_ELEMENT,                Status.BAD_REQUEST)
+        .put(ErrorTag.UNKNOWN_ELEMENT,            Status.BAD_REQUEST)
+        .put(ErrorTag.UNKNOWN_NAMESPACE,          Status.BAD_REQUEST)
+
+        .put(ErrorTag.ACCESS_DENIED,              Status.FORBIDDEN)
+        .put(ErrorTag.LOCK_DENIED,                Status.CONFLICT)
+        .put(ErrorTag.RESOURCE_DENIED,            Status.CONFLICT)
+        .put(ErrorTag.ROLLBACK_FAILED,            Status.INTERNAL_SERVER_ERROR)
+        .put(ErrorTag.DATA_EXISTS,                Status.CONFLICT)
+        .put(ErrorTag.DATA_MISSING,               dataMissingHttpStatus())
+
+        .put(ErrorTag.OPERATION_NOT_SUPPORTED,    Status.NOT_IMPLEMENTED)
+        .put(ErrorTag.OPERATION_FAILED,           Status.INTERNAL_SERVER_ERROR)
+        .put(ErrorTag.PARTIAL_OPERATION,          Status.INTERNAL_SERVER_ERROR)
+        .put(ErrorTag.MALFORMED_MESSAGE,          Status.BAD_REQUEST)
+        .put(ErrorTags.RESOURCE_DENIED_TRANSPORT, Status.SERVICE_UNAVAILABLE)
+        .build();
+
+    private ErrorTags() {
+        // Hidden on purpose
+    }
+
+    /**
+     * Return the HTTP {@link Status} corresponding to specified {@link ErrorTag}.
+     *
+     * @param tag Error tag to map
+     * @return HTTP Status
+     * @throws NullPointerException if {@code tag} is null
+     */
+    public static Status statusOf(final ErrorTag tag) {
+        final Status known = WELL_KNOWN_ERROR_TAGS.get(requireNonNull(tag));
+        return known != null ? known : Status.INTERNAL_SERVER_ERROR;
+    }
+
+    private static Status dataMissingHttpStatus() {
+        // Control over the HTTP status reported on "data-missing" conditions. This defaults to disabled,
+        // 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");
+        switch (propValue) {
+            case "enabled":
+                // RFC7231 interpretation: 404 Not Found
+                LOG.info("RESTCONF data-missing condition is reported as HTTP status 404 (Errata 5565)");
+                return Status.NOT_FOUND;
+            case "disabled":
+                break;
+            default:
+                LOG.warn("Unhandled {} value \"{}\", assuming disabled", propName, propValue);
+        }
+
+        // RFC8040 specification: 409 Conflict
+        return Status.CONFLICT;
+    }
+}
index 66ead84da2bdc658d3f5cbcb11f29e6370bafe8f..d09003857abc34c00fa33a4d7a70050d886046ac 100644 (file)
@@ -17,13 +17,16 @@ import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response.Status;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.restconf.common.ErrorTags;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.OperationFailedException;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.YangError;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.codec.YangInvalidValueException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Unchecked exception to communicate error information, as defined in the ietf restcong draft, to be sent to the
@@ -36,7 +39,7 @@ import org.opendaylight.yangtools.yang.data.api.codec.YangInvalidValueException;
  * @author Thomas Pantelis
  */
 public class RestconfDocumentedException extends WebApplicationException {
-
+    private static final Logger LOG = LoggerFactory.getLogger(RestconfDocumentedException.class);
     private static final long serialVersionUID = 1L;
 
     private final ImmutableList<RestconfError> errors;
@@ -50,7 +53,7 @@ public class RestconfDocumentedException extends WebApplicationException {
      *            A string which provides a plain text string describing the error.
      */
     public RestconfDocumentedException(final String message) {
-        this(message, ErrorType.APPLICATION, RestconfError.ErrorTag.OPERATION_FAILED);
+        this(message, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED);
     }
 
     /**
@@ -111,8 +114,8 @@ public class RestconfDocumentedException extends WebApplicationException {
      *            The underlying exception cause.
      */
     public RestconfDocumentedException(final String message, final Throwable cause) {
-        this(cause, new RestconfError(ErrorType.APPLICATION, RestconfError.ErrorTag.OPERATION_FAILED,
-                message, null, cause.getMessage(), null));
+        this(cause, new RestconfError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, message, null,
+            cause.getMessage(), null));
     }
 
     /**
@@ -132,8 +135,8 @@ public class RestconfDocumentedException extends WebApplicationException {
         if (!errors.isEmpty()) {
             this.errors = ImmutableList.copyOf(errors);
         } else {
-            this.errors = ImmutableList.of(new RestconfError(ErrorType.APPLICATION,
-                    RestconfError.ErrorTag.OPERATION_FAILED, message));
+            this.errors = ImmutableList.of(
+                new RestconfError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, message));
         }
 
         status = null;
@@ -159,7 +162,7 @@ public class RestconfDocumentedException extends WebApplicationException {
     }
 
     public RestconfDocumentedException(final Throwable cause, final RestconfError error) {
-        super(cause, error.getErrorTag().getStatusCode());
+        super(cause, ErrorTags.statusOf(error.getErrorTag()));
         errors = ImmutableList.of(error);
         status = null;
     }
@@ -168,9 +171,9 @@ public class RestconfDocumentedException extends WebApplicationException {
             final OperationFailedException cause) {
         for (final RpcError error : cause.getErrorList()) {
             if (error.getErrorType() == RpcError.ErrorType.TRANSPORT
-                    && error.getTag().equals(ErrorTag.RESOURCE_DENIED.getTagValue())) {
+                    && error.getTag().equals(ErrorTag.RESOURCE_DENIED.elementBody())) {
                 throw new RestconfDocumentedException(error.getMessage(), ErrorType.TRANSPORT,
-                    ErrorTag.RESOURCE_DENIED_TRANSPORT, cause);
+                    ErrorTags.RESOURCE_DENIED_TRANSPORT, cause);
             }
         }
         throw new RestconfDocumentedException(message, cause, cause.getErrorList());
index db193ddd9cbad52dba6bfdfb3c2bece91fd95cbc..d9f701564bdcf9f5fb45ba370ff1d14839209c4b 100644 (file)
@@ -11,11 +11,10 @@ import static java.util.Objects.requireNonNull;
 
 import java.io.Serializable;
 import java.util.Locale;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Encapsulates a restconf error as defined in the ietf restconf draft.
@@ -28,79 +27,8 @@ import org.slf4j.LoggerFactory;
  *     See also <a href="https://tools.ietf.org/html/draft-bierman-netconf-restconf-02">RESTCONF</a>.
  */
 public class RestconfError implements Serializable {
-    private static final Logger LOG = LoggerFactory.getLogger(RestconfError.class);
     private static final long serialVersionUID = 1L;
 
-    public enum ErrorTag {
-        IN_USE("in-use", 409 /* Conflict */),
-        INVALID_VALUE("invalid-value", 400 /* Bad Request */),
-        TOO_BIG("too-big", 413 /* Request Entity Too Large */),
-        MISSING_ATTRIBUTE("missing-attribute", 400 /* Bad Request */),
-        BAD_ATTRIBUTE("bad-attribute", 400 /* Bad Request */),
-        UNKNOWN_ATTRIBUTE("unknown-attribute", 400 /* Bad Request */),
-        MISSING_ELEMENT("missing-element", 400 /* Bad Request */),
-        BAD_ELEMENT("bad-element", 400 /* Bad Request */),
-        UNKNOWN_ELEMENT("unknown-element", 400 /* Bad Request */),
-        UNKNOWN_NAMESPACE("unknown-namespace", 400 /* Bad Request */),
-        ACCESS_DENIED("access-denied", 403 /* Forbidden */),
-        LOCK_DENIED("lock-denied", 409 /* Conflict */),
-        RESOURCE_DENIED("resource-denied", 409 /* Conflict */),
-        ROLLBACK_FAILED("rollback-failed", 500 /* INTERNAL_SERVER_ERROR */),
-        DATA_EXISTS("data-exists", 409 /* Conflict */),
-        DATA_MISSING("data-missing", dataMissingHttpStatus()),
-        OPERATION_NOT_SUPPORTED("operation-not-supported", 501 /* Not Implemented */),
-        OPERATION_FAILED("operation-failed", 500 /* INTERNAL_SERVER_ERROR */),
-        PARTIAL_OPERATION("partial-operation", 500 /* INTERNAL_SERVER_ERROR */),
-        MALFORMED_MESSAGE("malformed-message", 400 /* Bad Request */),
-        RESOURCE_DENIED_TRANSPORT("resource-denied-transport", 503 /* Service Unavailable */);
-
-        private final String tagValue;
-        private final int statusCode;
-
-        ErrorTag(final String tagValue, final int statusCode) {
-            this.tagValue = tagValue;
-            this.statusCode = statusCode;
-        }
-
-        public String getTagValue() {
-            return this.tagValue.toLowerCase(Locale.ROOT);
-        }
-
-        public static ErrorTag valueOfCaseInsensitive(final String value) {
-            try {
-                return ErrorTag.valueOf(ErrorTag.class, value.toUpperCase(Locale.ROOT).replaceAll("-", "_"));
-            } catch (IllegalArgumentException e) {
-                return OPERATION_FAILED;
-            }
-        }
-
-        public int getStatusCode() {
-            return statusCode;
-        }
-
-        private static int dataMissingHttpStatus() {
-            // Control over the HTTP status reported on "data-missing" conditions. This defaults to disabled,
-            // 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");
-            switch (propValue) {
-                case "enabled":
-                    // RFC7231 interpretation: 404 Not Found
-                    LOG.info("RESTCONF data-missing condition is reported as HTTP status 404 (Errata 5565)");
-                    return 404;
-                case "disabled":
-                    break;
-                default:
-                    LOG.warn("Unhandled {} value \"{}\", assuming disabled", propName, propValue);
-            }
-
-            // RFC8040 specification: 409 Conflict
-            return 409;
-        }
-    }
-
     private final ErrorType errorType;
     private final ErrorTag errorTag;
     private final String errorInfo;
@@ -208,8 +136,8 @@ public class RestconfError implements Serializable {
 
         this.errorType = rpcError.getErrorType().toNetconf();
 
-        this.errorTag = rpcError.getTag() == null ? ErrorTag.OPERATION_FAILED : ErrorTag
-                .valueOfCaseInsensitive(rpcError.getTag());
+        final String tag = rpcError.getTag();
+        this.errorTag = tag == null ? ErrorTag.OPERATION_FAILED : new ErrorTag(tag);
 
         this.errorMessage = rpcError.getMessage();
         this.errorAppTag = rpcError.getApplicationTag();
@@ -257,7 +185,7 @@ public class RestconfError implements Serializable {
     @Override
     public String toString() {
         return "RestconfError ["
-                + "error-type: " + errorType.elementBody() + ", error-tag: " + errorTag.getTagValue()
+                + "error-type: " + errorType.elementBody() + ", error-tag: " + errorTag.elementBody()
                 + (errorAppTag != null ? ", error-app-tag: " + errorAppTag : "")
                 + (errorMessage != null ? ", error-message: " + errorMessage : "")
                 + (errorInfo != null ? ", error-info: " + errorInfo : "")
index 64110daf73848061606750ff59a287c091f24f04..7e266c7d49048b87640e33817b98609b9d14df4c 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.restconf.common.util;
 
 import java.util.Collection;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
index cac528f6424497b2352b18b92dd3a8399de67c08..987ce42c84f559b9e924cdd90ff029244f6152c3 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.restconf.common.validation;
 
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 
 /**
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
new file mode 100644 (file)
index 0000000..a05f256
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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 java.util.Objects.requireNonNull;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+
+@RunWith(Parameterized.class)
+public class ErrorTagsTest {
+    @Parameters(name = "{0} => {1}")
+    public static Iterable<Object[]> data() {
+        return Arrays.asList(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 }
+        });
+    }
+
+    private final String tagName;
+    private final int status;
+
+    public ErrorTagsTest(final String tagName, final int status) {
+        this.tagName = requireNonNull(tagName);
+        this.status = status;
+    }
+
+    @Test
+    public void testStatusOf() {
+        assertEquals(status, ErrorTags.statusOf(new ErrorTag(tagName)).getStatusCode());
+    }
+}
index 801b16bffb4c9a6ac09aef5fe13c5183761e96b8..70b09bf97ba60c6033fb2d89bf97b26cf1448985 100644 (file)
@@ -15,9 +15,9 @@ import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.schema.SchemaExportContext;
 import org.opendaylight.restconf.common.validation.RestconfValidationUtils;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.Module;
index cda7ab71355ee871af4a7545b7544f36771d4b88..69ea71d56970abcfff5b690ffb875792b6e81a85 100644 (file)
@@ -31,8 +31,8 @@ import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.util.RestUtil;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
index d0686046cf10aa19e2abaf21206a97998e367000..f17666c59e72c72f3ad3d7c0533f336af6e72c2b 100644 (file)
@@ -37,11 +37,11 @@ import org.opendaylight.netconf.sal.rest.api.RestconfService;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEditOperation;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.common.util.RestUtil;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
index cdca49d7ca73e7e9995702656eb623ce827fadd7..63586af75b220ae8210864cae52102df902d4c86 100644 (file)
@@ -100,7 +100,7 @@ public class PatchJsonBodyWriter implements MessageBodyWriter<PatchStatusContext
         for (final RestconfError restconfError : errors) {
             jsonWriter.beginObject();
             jsonWriter.name("error-type").value(restconfError.getErrorType().elementBody());
-            jsonWriter.name("error-tag").value(restconfError.getErrorTag().getTagValue());
+            jsonWriter.name("error-tag").value(restconfError.getErrorTag().elementBody());
 
             // optional node
             if (restconfError.getErrorPath() != null) {
index f9f3ae731019ad49d2d97e15ccf75d60699a6d3b..d941d6ceb3874e8616f914401c4408f3f239b306 100644 (file)
@@ -113,7 +113,7 @@ public class PatchXmlBodyWriter implements MessageBodyWriter<PatchStatusContext>
             writer.writeEndElement();
 
             writer.writeStartElement("error-tag");
-            writer.writeCharacters(restconfError.getErrorTag().getTagValue());
+            writer.writeCharacters(restconfError.getErrorTag().elementBody());
             writer.writeEndElement();
 
             // optional node
index 22fa6c71f6fa60dd027d089ea7c6d947db73833f..2aaea2b91c3d59657014e7d2fb7d14fb42a87bef 100644 (file)
@@ -23,6 +23,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 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 javax.xml.XMLConstants;
@@ -32,6 +33,7 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import org.opendaylight.netconf.sal.rest.api.Draft02;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
+import org.opendaylight.restconf.common.ErrorTags;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
@@ -118,11 +120,9 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
             return Response.status(exception.getStatus()).type(MediaType.TEXT_PLAIN_TYPE).entity(" ").build();
         }
 
-        final int status = errors.iterator().next().getErrorTag().getStatusCode();
-
+        final Status status = ErrorTags.statusOf(errors.iterator().next().getErrorTag());
         final DataNodeContainer errorsSchemaNode =
                 (DataNodeContainer) controllerContext.getRestconfModuleErrorsSchemaNode();
-
         if (errorsSchemaNode == null) {
             return Response.status(status).type(MediaType.TEXT_PLAIN_TYPE).entity(exception.getMessage()).build();
         }
@@ -176,7 +176,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
         final DataSchemaNode errTagSchemaNode = Iterables.getFirst(lsChildDataSchemaNode, null);
         checkState(errTagSchemaNode instanceof LeafSchemaNode);
         errNodeValues.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) errTagSchemaNode)
-                .withValue(error.getErrorTag().getTagValue()).build());
+                .withValue(error.getErrorTag().elementBody()).build());
 
         if (error.getErrorAppTag() != null) {
             lsChildDataSchemaNode = ControllerContext.findInstanceDataChildrenByName(
index 8245916efaad9c79b4b8fd9f8f0814fc83286d31..12dd0c5c25f5786a35061b627f728598cb275096 100644 (file)
@@ -34,9 +34,9 @@ import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.util.RestUtil;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
index 5913d7832f617fe4d5567633df1ee316a02b38ca..3e6ea0520e1c0e0a9dce0046fc2930e091e9d68b 100644 (file)
@@ -37,12 +37,12 @@ import org.opendaylight.netconf.sal.rest.api.RestconfService;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEditOperation;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.common.util.RestUtil;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
index 78ec0b719e8e57209d7f0323d2535a6950ab6471..c9e0731d46938edce67b17653b174273ec5f8a07 100644 (file)
@@ -53,7 +53,6 @@ import org.opendaylight.netconf.sal.streams.listeners.NotificationListenerAdapte
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEditOperation;
 import org.opendaylight.restconf.common.patch.PatchEntity;
@@ -61,6 +60,7 @@ import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.common.patch.PatchStatusEntity;
 import org.opendaylight.restconf.common.util.DataChangeScope;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
index 52095f5c93c0dd4a8e607e25b7486920c4078522..a7d9fa2429be41c9a01aa80fea43caca87a29511 100644 (file)
@@ -43,10 +43,10 @@ import org.opendaylight.netconf.sal.rest.api.Draft02;
 import org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.util.RestUtil;
 import org.opendaylight.yangtools.concepts.IllegalArgumentCodec;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
index 19cba39740e9f397d486f06d93907fbc0339a888..c719cc65658d6ca120a60baaf60b0f387dac2f24 100644 (file)
@@ -34,10 +34,10 @@ import org.opendaylight.netconf.sal.restconf.api.JSONRestconfService;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.common.util.SimpleUriInfo;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.OperationFailedException;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@@ -283,7 +283,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService {
         final RpcError[] to = new RpcError[from.size()];
         int index = 0;
         for (final RestconfError e: from) {
-            to[index++] = RpcResultBuilder.newError(e.getErrorType().toLegacy(), e.getErrorTag().getTagValue(),
+            to[index++] = RpcResultBuilder.newError(e.getErrorType().toLegacy(), e.getErrorTag().elementBody(),
                     e.getErrorMessage());
         }
 
index aea1864d414adda34e9ff45d6359fb3d3becad71..58589c2d2b190b31fbdc8cfe4001419fc95114e9 100644 (file)
@@ -12,6 +12,7 @@ import javax.ws.rs.core.UriInfo;
 import org.opendaylight.restconf.common.context.WriterParameters;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 
 public final class QueryParametersParser {
@@ -57,14 +58,14 @@ public final class QueryParametersParser {
                 final int depth = Integer.parseInt(param);
                 if (depth < 1) {
                     throw new RestconfDocumentedException(
-                            new RestconfError(ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
+                            new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
                             "Invalid depth parameter: " + depth, null,
                             "The depth parameter must be an integer > 1 or \"unbounded\""));
                 }
                 wpBuilder.setDepth(depth);
             } catch (final NumberFormatException e) {
                 throw new RestconfDocumentedException(e, new RestconfError(
-                        ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
+                        ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
                         "Invalid depth parameter: " + e.getMessage(), null,
                         "The depth parameter must be an integer > 1 or \"unbounded\""));
             }
index 503fc62b62ca45d1c23a065dc822c2924b247959..77bb5f0635ce84796e13119a683bc44511d091a2 100644 (file)
@@ -74,7 +74,6 @@ import org.opendaylight.netconf.sal.streams.websockets.WebSocketServer;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.common.util.DataChangeScope;
@@ -82,6 +81,7 @@ import org.opendaylight.restconf.common.util.OperationsResourceUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
index 677ef51eca66c05a232a64ed0030864bfdca41fe..a9a8ce14311bbde7b16431cffa5715fabeb8d525 100644 (file)
@@ -36,11 +36,9 @@ public abstract class AbstractBodyReaderTest {
 
     static {
         try {
-            uriField = AbstractIdentifierAwareJaxRsProvider.class
-                    .getDeclaredField("uriInfo");
+            uriField = AbstractIdentifierAwareJaxRsProvider.class.getDeclaredField("uriInfo");
             uriField.setAccessible(true);
-            requestField = AbstractIdentifierAwareJaxRsProvider.class
-                    .getDeclaredField("request");
+            requestField = AbstractIdentifierAwareJaxRsProvider.class.getDeclaredField("request");
             requestField.setAccessible(true);
         } catch (NoSuchFieldException e) {
             throw new RuntimeException(e);
@@ -75,7 +73,7 @@ public abstract class AbstractBodyReaderTest {
         when(uriInfoMock.getPathParameters()).thenReturn(pathParm);
         when(uriInfoMock.getPathParameters(false)).thenReturn(pathParm);
         when(uriInfoMock.getPathParameters(true)).thenReturn(pathParm);
-        when(uriInfoMock.getAbsolutePath()).thenReturn(new URI("restconf"));
+        when(uriInfoMock.getAbsolutePath()).thenReturn(URI.create("restconf"));
         uriField.set(normalizedNodeProvider, uriInfoMock);
 
         final Request request = mock(Request.class);
@@ -97,10 +95,8 @@ public abstract class AbstractBodyReaderTest {
     protected static void checkNormalizedNodeContext(
             final NormalizedNodeContext nnContext) {
         assertNotNull(nnContext.getData());
-        assertNotNull(nnContext.getInstanceIdentifierContext()
-                .getInstanceIdentifier());
-        assertNotNull(nnContext.getInstanceIdentifierContext()
-                .getSchemaContext());
+        assertNotNull(nnContext.getInstanceIdentifierContext().getInstanceIdentifier());
+        assertNotNull(nnContext.getInstanceIdentifierContext().getSchemaContext());
         assertNotNull(nnContext.getInstanceIdentifierContext().getSchemaNode());
     }
 
index d1c23ed6bd209fed3744a99e59a7c7ee2c3e265d..f2a6c415319d2785a8dd3d54c6ec924fe09603a1 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.controller.sal.rest.impl.test.providers;
 
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
 
 import java.io.InputStream;
 import javax.ws.rs.core.MediaType;
@@ -18,38 +18,38 @@ import org.junit.Test;
 import org.opendaylight.netconf.sal.rest.impl.JsonToPatchBodyReader;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 public class TestJsonPatchBodyReader extends AbstractBodyReaderTest {
+    private static EffectiveModelContext schemaContext;
 
     private final JsonToPatchBodyReader jsonToPatchBodyReader;
-    private static EffectiveModelContext schemaContext;
 
     public TestJsonPatchBodyReader() {
         super(schemaContext, null);
         jsonToPatchBodyReader = new JsonToPatchBodyReader(controllerContext);
     }
 
-    @Override
-    protected MediaType getMediaType() {
-        return new MediaType(APPLICATION_JSON, null);
-    }
-
     @BeforeClass
     public static void initialization() {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
     }
 
+    @Override
+    protected MediaType getMediaType() {
+        return new MediaType(APPLICATION_JSON, null);
+    }
+
     @Test
     public void modulePatchDataTest() throws Exception {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = TestJsonBodyReader.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHdata.json");
+        final InputStream inputStream = TestJsonBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHdata.json");
 
-        final PatchContext returnValue = jsonToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
@@ -61,11 +61,10 @@ public class TestJsonPatchBodyReader extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = TestJsonBodyReader.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataCreateAndDelete.json");
+        final InputStream inputStream = TestJsonBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHdataCreateAndDelete.json");
 
-        final PatchContext returnValue = jsonToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
@@ -78,15 +77,12 @@ public class TestJsonPatchBodyReader extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = TestJsonBodyReader.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataValueMissing.json");
-
-        try {
-            jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-            fail("Test should return error 400 due to missing value node when attempt to invoke create operation");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final InputStream inputStream = TestJsonBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHdataValueMissing.json");
+
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -98,15 +94,12 @@ public class TestJsonPatchBodyReader extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = TestJsonBodyReader.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataValueNotSupported.json");
-
-        try {
-            jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-            fail("Test should return error 400 due to present value node when attempt to invoke delete operation");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final InputStream inputStream = TestJsonBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHdataValueNotSupported.json");
+
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -117,11 +110,10 @@ public class TestJsonPatchBodyReader extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = TestJsonBodyReader.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json");
+        final InputStream inputStream = TestJsonBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json");
 
-        final PatchContext returnValue = jsonToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
@@ -136,8 +128,7 @@ public class TestJsonPatchBodyReader extends AbstractBodyReaderTest {
         final InputStream inputStream = TestJsonBodyReader.class
                 .getResourceAsStream("/instanceidentifier/json/jsonPATCHMergeOperationOnList.json");
 
-        final PatchContext returnValue = jsonToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
@@ -149,11 +140,10 @@ public class TestJsonPatchBodyReader extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = TestJsonBodyReader.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json");
+        final InputStream inputStream = TestJsonBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json");
 
-        final PatchContext returnValue = jsonToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
index c3bee822fdc5392ab5021b24e63b34453c5302a4..4ad1a6599a9df751a7538e15748df430106eea43 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.controller.sal.rest.impl.test.providers;
 
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.mock;
 
 import java.io.InputStream;
@@ -20,6 +20,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.netconf.sal.rest.impl.JsonToPatchBodyReader;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 public class TestJsonPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
@@ -80,15 +81,12 @@ public class TestJsonPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
         final String uri = MOUNT_POINT + "/instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = TestJsonBodyReader.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataValueMissing.json");
-
-        try {
-            jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-            fail("Test should return error 400 due to missing value node when attempt to invoke create operation");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final InputStream inputStream = TestJsonBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHdataValueMissing.json");
+
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -103,12 +101,9 @@ public class TestJsonPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
         final InputStream inputStream = TestJsonBodyReader.class
                 .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataValueNotSupported.json");
 
-        try {
-            jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-            fail("Test should return error 400 due to present value node when attempt to invoke delete operation");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
index 6eea15d81e7403eb78d01e3d7ec69d49607c7071..de8b21e07f305eaf9e41b4e79a66fe02d6183268 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -280,8 +281,8 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest {
             Assert.fail("Test should fail due to malformed PUT operation message");
         } catch (final RestconfDocumentedException exception) {
             final RestconfError restconfError = exception.getErrors().get(0);
-            Assert.assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
-            Assert.assertEquals(RestconfError.ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
+            assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
+            assertEquals(ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
         }
     }
 }
index 8ad7d0a8c17e97cb2b831b8097c2d4957cb992ef..a66e3e7872c80f5a63d9583859b57d741cb887ad 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -212,8 +213,8 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest {
             Assert.fail("Test should fail due to malformed PUT operation message");
         } catch (final RestconfDocumentedException exception) {
             final RestconfError restconfError = exception.getErrors().get(0);
-            Assert.assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
-            Assert.assertEquals(RestconfError.ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
+            assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
+            assertEquals(ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
         }
     }
 }
index 9e3f54cd824c49f82a6b3f175b082938bbb425b0..8b37ba4ee50d03ca63ec3042d0a5f42d48ea1216 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.controller.sal.rest.impl.test.providers;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
 
 import java.io.InputStream;
 import javax.ws.rs.core.MediaType;
@@ -17,6 +17,7 @@ import org.junit.Test;
 import org.opendaylight.netconf.sal.rest.impl.XmlToPatchBodyReader;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 public class TestXmlPatchBodyReader extends AbstractBodyReaderTest {
@@ -43,10 +44,9 @@ public class TestXmlPatchBodyReader extends AbstractBodyReaderTest {
     public void moduleDataTest() throws Exception {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdata.xml");
+        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
@@ -57,14 +57,12 @@ public class TestXmlPatchBodyReader extends AbstractBodyReaderTest {
     public void moduleDataValueMissingNegativeTest() throws Exception {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
-        try {
-            xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-            fail("Test should return error 400 due to missing value node when attempt to invoke create operation");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+        assertEquals(1, ex.getErrors().size());
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -75,14 +73,13 @@ public class TestXmlPatchBodyReader extends AbstractBodyReaderTest {
     public void moduleDataNotValueNotSupportedNegativeTest() throws Exception {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
-        try {
-            xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-            fail("Test should return error 400 due to present value node when attempt to invoke delete operation");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
+
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+        assertEquals(1, ex.getErrors().size());
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -94,8 +91,7 @@ public class TestXmlPatchBodyReader extends AbstractBodyReaderTest {
         mockBodyReader(uri, xmlToPatchBodyReader, false);
         final InputStream inputStream = TestXmlBodyReader.class
                 .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
@@ -122,8 +118,7 @@ public class TestXmlPatchBodyReader extends AbstractBodyReaderTest {
         mockBodyReader(uri, xmlToPatchBodyReader, false);
         final InputStream inputStream = TestXmlBodyReader.class
                 .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
@@ -136,8 +131,7 @@ public class TestXmlPatchBodyReader extends AbstractBodyReaderTest {
         mockBodyReader(uri, xmlToPatchBodyReader, false);
         final InputStream inputStream = TestXmlBodyReader.class
                 .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 }
index cb791543d059a3ab92a9b4090bc24d6b20cd9de8..614f36ed026c29a98586a3918854d0d89ff1d7c6 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.controller.sal.rest.impl.test.providers;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.mock;
 
 import java.io.InputStream;
@@ -19,6 +19,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.netconf.sal.rest.impl.XmlToPatchBodyReader;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
@@ -32,25 +33,23 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
         xmlToPatchBodyReader = new XmlToPatchBodyReader(controllerContext);
     }
 
-    @Override
-    protected MediaType getMediaType() {
-        return new MediaType(MediaType.APPLICATION_XML, null);
-    }
-
     @BeforeClass
     public static void initialization() throws NoSuchFieldException, SecurityException {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
     }
 
+    @Override
+    protected MediaType getMediaType() {
+        return new MediaType(MediaType.APPLICATION_XML, null);
+    }
+
     @Test
     public void moduleDataTest() throws Exception {
         final String uri = MOUNT_POINT + "/instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
-        checkPatchContextMountPoint(returnValue);
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdata.xml");
+        checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
     }
 
     /**
@@ -60,14 +59,11 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     public void moduleDataValueMissingNegativeTest() throws Exception {
         final String uri = MOUNT_POINT + "/instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
-        try {
-            xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-            fail("Test should return error 400 due to missing value node when attempt to invoke create operation");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -80,12 +76,9 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
         mockBodyReader(uri, xmlToPatchBodyReader, false);
         final InputStream inputStream = TestXmlBodyReader.class
                 .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
-        try {
-            xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-            fail("Test should return error 400 due to present value node when attempt to invoke delete operation");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -95,10 +88,9 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     public void moduleDataAbsoluteTargetPathTest() throws Exception {
         final String uri = MOUNT_POINT;
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml");
+        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContextMountPoint(returnValue);
     }
 
@@ -109,10 +101,9 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     public void modulePatchCompleteTargetInURITest() throws Exception {
         final String uri = MOUNT_POINT + "/instance-identifier-patch-module:patch-cont";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml");
+        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContextMountPoint(returnValue);
     }
 
@@ -123,11 +114,9 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     public void moduleDataMergeOperationOnListTest() throws Exception {
         final String uri = MOUNT_POINT + "/instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
-        checkPatchContextMountPoint(returnValue);
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml");
+        checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
     }
 
     /**
@@ -137,10 +126,8 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     public void moduleDataMergeOperationOnContainerTest() throws Exception {
         final String uri = MOUNT_POINT + "/instance-identifier-patch-module:patch-cont";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
-        checkPatchContextMountPoint(returnValue);
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml");
+        checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
     }
 }
index 39d297e7bdb9c46523478c26def862a59faafaa9..f9b34838b8198456b9eaa11238213bae8038be2b 100644 (file)
@@ -35,7 +35,7 @@ import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
index c39251394b8850ec377ef2957e705eddca87deba..65f446fed1a20a5281e2dabcf46de71d0d0551ee 100644 (file)
@@ -11,8 +11,8 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doReturn;
@@ -33,6 +33,7 @@ import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
+import java.util.List;
 import java.util.Optional;
 import org.junit.Before;
 import org.junit.Test;
@@ -63,15 +64,16 @@ import org.opendaylight.netconf.sal.restconf.impl.PutResult;
 import org.opendaylight.netconf.sal.streams.listeners.ListenerAdapter;
 import org.opendaylight.netconf.sal.streams.listeners.NotificationListenerAdapter;
 import org.opendaylight.netconf.sal.streams.listeners.Notificator;
+import org.opendaylight.restconf.common.ErrorTags;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.common.util.DataChangeScope;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
@@ -168,19 +170,18 @@ public class BrokerFacadeTest {
     public void test503() throws Exception {
         final RpcError error = RpcResultBuilder.newError(
                 RpcError.ErrorType.TRANSPORT,
-                ErrorTag.RESOURCE_DENIED.getTagValue(),
+                ErrorTag.RESOURCE_DENIED.elementBody(),
                 "Master is down. Please try again.");
         doReturn(immediateFailedFluentFuture(new ReadFailedException("Read from transaction failed", error)))
                 .when(readTransaction).read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class));
-        try {
-            brokerFacade.readConfigurationData(this.instanceID, "explicit");
-            fail("This test should fail.");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("getErrorTag", ErrorTag.RESOURCE_DENIED_TRANSPORT, e.getErrors().get(0).getErrorTag());
-            assertEquals("getErrorType", ErrorType.TRANSPORT, e.getErrors().get(0).getErrorType());
-            assertEquals("getErrorMessage", "Master is down. Please try again.",
-                    e.getErrors().get(0).getErrorMessage());
-        }
+
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> brokerFacade.readConfigurationData(this.instanceID, "explicit"));
+        final List<RestconfError> errors = ex.getErrors();
+        assertEquals(1, errors.size());
+        assertEquals("getErrorTag", ErrorTags.RESOURCE_DENIED_TRANSPORT, errors.get(0).getErrorTag());
+        assertEquals("getErrorType", ErrorType.TRANSPORT,errors.get(0).getErrorType());
+        assertEquals("getErrorMessage", "Master is down. Please try again.", errors.get(0).getErrorMessage());
     }
 
     @Test
@@ -242,7 +243,7 @@ public class BrokerFacadeTest {
             this.brokerFacade.commitConfigurationDataPost((EffectiveModelContext) null, this.instanceID, this.dummyNode,
                     null, null);
         } catch (final RestconfDocumentedException e) {
-            assertEquals("getErrorTag", RestconfError.ErrorTag.DATA_EXISTS, e.getErrors().get(0).getErrorTag());
+            assertEquals("getErrorTag", ErrorTag.DATA_EXISTS, e.getErrors().get(0).getErrorTag());
             throw e;
         }
     }
@@ -281,13 +282,12 @@ public class BrokerFacadeTest {
         prepareDataForDelete(false);
 
         // try to delete and expect DATA_MISSING error
-        try {
-            this.brokerFacade.commitConfigurationDataDelete(this.instanceID);
-            fail("Delete operation should fail due to missing data");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals(ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> brokerFacade.commitConfigurationDataDelete(this.instanceID));
+        final List<RestconfError> errors = ex.getErrors();
+        assertEquals(1, errors.size());
+        assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
+        assertEquals(ErrorTag.DATA_MISSING, errors.get(0).getErrorTag());
     }
 
     /**
index b744008d3d90d2acc3e5611cb00644438dd31067..b470f3933c19035eb968da7c21c6d5b75a176b63 100644 (file)
@@ -42,11 +42,12 @@ import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
+import org.opendaylight.restconf.common.ErrorTags;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
@@ -199,8 +200,13 @@ public class InvokeRpcMethodTest {
 
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> this.restconfImpl.invokeRpc("toaster:cancel-toast", null, uriInfo));
-        verifyRestconfDocumentedException(ex, 0, ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED, Optional.of("foo"),
-            Optional.empty());
+
+        // We are performing pass-through here of error-tag, hence the tag remains as specified, but we want to make
+        // sure the HTTP status remains the same as
+        final ErrorTag bogus = new ErrorTag("bogusTag");
+        verifyRestconfDocumentedException(ex, 0, ErrorType.TRANSPORT, bogus, Optional.of("foo"), Optional.empty());
+        assertEquals(ErrorTags.statusOf(ErrorTag.OPERATION_FAILED), ErrorTags.statusOf(bogus));
+
         verifyRestconfDocumentedException(ex, 1, ErrorType.RPC, ErrorTag.IN_USE, Optional.of("bar"),
             Optional.of("app-tag"));
     }
index fffd64e0608ced9b3a5bb1d88df2c8a56b55dfcb..4abf3abe1acdc0eaadbcc40e9c79aa66ae8d63af 100644 (file)
@@ -64,8 +64,8 @@ import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.slf4j.Logger;
@@ -746,7 +746,7 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         }
 
         assertEquals("error-type", expErrorType.elementBody(), leafMap.remove("error-type"));
-        assertEquals("error-tag", expErrorTag.getTagValue(), leafMap.remove("error-tag"));
+        assertEquals("error-tag", expErrorTag.elementBody(), leafMap.remove("error-tag"));
 
         verifyOptionalJsonLeaf(leafMap.remove("error-message"), expErrorMessage, "error-message");
         verifyOptionalJsonLeaf(leafMap.remove("error-app-tag"), expErrorAppTag, "error-app-tag");
@@ -798,7 +798,7 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         assertEquals("error-type", expErrorType.elementBody(), errorType);
 
         final String errorTag = (String) ERROR_TAG.evaluate(errorNode, XPathConstants.STRING);
-        assertEquals("error-tag", expErrorTag.getTagValue(), errorTag);
+        assertEquals("error-tag", expErrorTag.elementBody(), errorTag);
 
         verifyOptionalXMLLeaf(errorNode, ERROR_MESSAGE, expErrorMessage, "error-message");
         verifyOptionalXMLLeaf(errorNode, ERROR_APP_TAG, expErrorAppTag, "error-app-tag");
index faddeca5993393899745d6d6bbe1a5ab959c2804..e986a56cc2742509ae083ebb8758a5d1f51eed06 100644 (file)
@@ -10,16 +10,13 @@ package org.opendaylight.controller.sal.restconf.impl.test;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 
-import java.util.HashMap;
-import java.util.Map;
 import org.hamcrest.BaseMatcher;
 import org.hamcrest.Description;
 import org.hamcrest.Matcher;
 import org.junit.Test;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@@ -52,49 +49,6 @@ public class RestconfErrorTest {
         }
     }
 
-    @Test
-    public void testErrorTagValueOf() {
-        assertEquals(ErrorTag.IN_USE, ErrorTag.valueOfCaseInsensitive(ErrorTag.IN_USE.getTagValue()));
-    }
-
-    @Test
-    public void testErrorTagValueOfIsLowercase() {
-        assertEquals("in-use", ErrorTag.IN_USE.getTagValue());
-    }
-
-    @Test
-    public void testErrorTagStatusCodes() {
-        Map<String, Integer> lookUpMap = new HashMap<>();
-
-        lookUpMap.put("in-use", 409);
-        lookUpMap.put("invalid-value", 400);
-        lookUpMap.put("too-big", 413);
-        lookUpMap.put("missing-attribute", 400);
-        lookUpMap.put("bad-attribute", 400);
-        lookUpMap.put("unknown-attribute", 400);
-        lookUpMap.put("missing-element", 400);
-        lookUpMap.put("bad-element", 400);
-        lookUpMap.put("unknown-element", 400);
-        lookUpMap.put("unknown-namespace", 400);
-        lookUpMap.put("access-denied", 403);
-        lookUpMap.put("lock-denied", 409);
-        lookUpMap.put("resource-denied", 409);
-        lookUpMap.put("rollback-failed", 500);
-        lookUpMap.put("data-exists", 409);
-        lookUpMap.put("data-missing", 409);
-        lookUpMap.put("operation-not-supported", 501);
-        lookUpMap.put("operation-failed", 500);
-        lookUpMap.put("partial-operation", 500);
-        lookUpMap.put("malformed-message", 400);
-        lookUpMap.put("resource-denied-transport", 503);
-
-        for (ErrorTag tag : ErrorTag.values()) {
-            Integer expectedStatusCode = lookUpMap.get(tag.getTagValue());
-            assertNotNull("Failed to find " + tag.getTagValue(), expectedStatusCode);
-            assertEquals("Status Code does not match", expectedStatusCode, Integer.valueOf(tag.getStatusCode()));
-        }
-    }
-
     @Test
     public void testRestConfDocumentedException_NoCause() {
         String expectedMessage = "Message";
@@ -139,7 +93,7 @@ public class RestconfErrorTest {
 
         // All fields set
         RpcError rpcError = RpcResultBuilder.newError(
-                RpcError.ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE.getTagValue(), "mock error-message",
+                RpcError.ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE.elementBody(), "mock error-message",
                 "mock app-tag", "mock error-info", new Exception("mock cause"));
 
         validateRestConfError("mock error-message", ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE, "mock app-tag",
@@ -147,7 +101,7 @@ public class RestconfErrorTest {
 
         // All fields set except 'info' - expect error-info set to 'cause'
         rpcError = RpcResultBuilder.newError(
-                RpcError.ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE.getTagValue(), "mock error-message",
+                RpcError.ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE.elementBody(), "mock error-message",
                 "mock app-tag", null, new Exception("mock cause"));
 
         validateRestConfError("mock error-message", ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE, "mock app-tag",
@@ -155,17 +109,15 @@ public class RestconfErrorTest {
 
         // Some fields set - expect error-info set to ErrorSeverity
         rpcError = RpcResultBuilder.newError(
-                RpcError.ErrorType.RPC, ErrorTag.ACCESS_DENIED.getTagValue(), null, null, null, null);
+                RpcError.ErrorType.RPC, ErrorTag.ACCESS_DENIED.elementBody(), null, null, null, null);
 
         validateRestConfError(null, ErrorType.RPC, ErrorTag.ACCESS_DENIED, null, "<severity>error</severity>",
                 new RestconfError(rpcError));
 
-        // 'tag' field not mapped to ErrorTag - expect error-tag set to
-        // OPERATION_FAILED
-        rpcError = RpcResultBuilder.newWarning(
-                RpcError.ErrorType.TRANSPORT, "not mapped", null, null, null, null);
+        // 'tag' field not mapped to ErrorTag - expect error-tag set to OPERATION_FAILED
+        rpcError = RpcResultBuilder.newWarning(RpcError.ErrorType.TRANSPORT, "not mapped", null, null, null, null);
 
-        validateRestConfError(null, ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED, null,
+        validateRestConfError(null, ErrorType.TRANSPORT, new ErrorTag("not mapped"), null,
                 "<severity>warning</severity>", new RestconfError(rpcError));
 
         // No fields set - edge case
index 3b6cb71b411d74c6ffb638debe91080dfb165ba2..1101905f1e8a4426696bdaff4eb9c783e5f7876d 100644 (file)
@@ -55,8 +55,8 @@ import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
index 6ea9c5a90f4e5591edd8f3938d78db5d979138e0..e5574facdbcb631501d8982bc6bfa8cca8845081 100644 (file)
@@ -24,9 +24,9 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
@@ -144,6 +144,6 @@ public class JsonNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyRead
 
         RestconfDocumentedException.throwIfYangError(exception);
         throw new RestconfDocumentedException("Error parsing input: " + exception.getMessage(), ErrorType.PROTOCOL,
-                ErrorTag.MALFORMED_MESSAGE, exception);
+            ErrorTag.MALFORMED_MESSAGE, exception);
     }
 }
index 3e28d04324b21e0a88793b14fc344a27c10e58bd..41ef125f2d830c77aeeddd96df17074c0791ae3c 100644 (file)
@@ -28,10 +28,10 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
index 9f6619c897938fd91f15f53d72a4df33cb0bb14f..ebc7c5eda68d5419bf5f871cb15e48f09d7c2555 100644 (file)
@@ -29,6 +29,7 @@ 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;
@@ -145,7 +146,7 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
             ImmutableUnkeyedListEntryNodeBuilder.create()
                 .withNodeIdentifier(NodeIdentifier.create(Error.QNAME))
                 .withChild(ImmutableNodes.leafNode(ERROR_TYPE_QNAME, restconfError.getErrorType().elementBody()))
-                .withChild(ImmutableNodes.leafNode(ERROR_TAG_QNAME, restconfError.getErrorTag().getTagValue()));
+                .withChild(ImmutableNodes.leafNode(ERROR_TAG_QNAME, restconfError.getErrorTag().elementBody()));
 
         // filling in optional fields
         if (restconfError.getErrorMessage() != null) {
@@ -232,8 +233,8 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
             return DEFAULT_STATUS_CODE;
         }
 
-        final Set<Integer> allStatusCodesOfErrorEntries = errors.stream()
-                .map(restconfError -> restconfError.getErrorTag().getStatusCode())
+        final Set<Status> allStatusCodesOfErrorEntries = errors.stream()
+                .map(restconfError -> ErrorTags.statusOf(restconfError.getErrorTag()))
                 // we would like to preserve iteration order in collected entries - hence usage of LinkedHashSet
                 .collect(Collectors.toCollection(LinkedHashSet::new));
         // choosing of the first status code from appended errors, if there are different status codes in error
@@ -243,7 +244,7 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
                     + "Different status codes have been found in appended error entries: {}. The first error "
                     + "entry status code is chosen for response.", exception, allStatusCodesOfErrorEntries);
         }
-        return Status.fromStatusCode(allStatusCodesOfErrorEntries.iterator().next());
+        return allStatusCodesOfErrorEntries.iterator().next();
     }
 
     /**
index 40c12b2b06013113a8c03e030f050ffb28a3438d..8135e8d90d525915d927b5d76cfdc0cdcdcb21f9 100644 (file)
@@ -32,13 +32,13 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEditOperation;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -110,7 +110,7 @@ public class JsonPatchBodyReader extends AbstractPatchBodyReader {
 
         RestconfDocumentedException.throwIfYangError(exception);
         throw new RestconfDocumentedException("Error parsing json input: " + exception.getMessage(), ErrorType.PROTOCOL,
-                ErrorTag.MALFORMED_MESSAGE, exception);
+            ErrorTag.MALFORMED_MESSAGE, exception);
     }
 
     private List<PatchEntity> read(final JsonReader in, final InstanceIdentifierContext<?> path,
index f000f7c1338f9ac5507f778c8827d3a01820cb60..d4bb1c0eaffcaa406155f81b7a6db13f862be037 100644 (file)
@@ -82,7 +82,7 @@ public class JsonPatchStatusBodyWriter extends AbstractPatchStatusBodyWriter {
         for (final RestconfError restconfError : errors) {
             jsonWriter.beginObject();
             jsonWriter.name("error-type").value(restconfError.getErrorType().elementBody());
-            jsonWriter.name("error-tag").value(restconfError.getErrorTag().getTagValue());
+            jsonWriter.name("error-tag").value(restconfError.getErrorTag().elementBody());
 
             // optional node
             if (restconfError.getErrorPath() != null) {
index 59be92ce53b894f331dc16c26b034d46d2690443..75b8bac83a30dfcc9ae8c00a8428001455e414a5 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
 import static com.google.common.base.Verify.verify;
 import static com.google.common.base.Verify.verifyNotNull;
 
-import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableList;
 import java.io.IOException;
 import java.io.InputStream;
@@ -28,7 +27,6 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEditOperation;
 import org.opendaylight.restconf.common.patch.PatchEntity;
@@ -36,6 +34,7 @@ import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -63,7 +62,6 @@ import org.xml.sax.SAXException;
 @Consumes(MediaTypes.APPLICATION_YANG_PATCH_XML)
 public class XmlPatchBodyReader extends AbstractPatchBodyReader {
     private static final Logger LOG = LoggerFactory.getLogger(XmlPatchBodyReader.class);
-    private static final Splitter SLASH_SPLITTER = Splitter.on('/');
 
     public XmlPatchBodyReader(final SchemaContextHandler schemaContextHandler,
             final DOMMountPointService mountPointService) {
index 8b279360bf546f40e71664a67d9dd6556e0ff8a0..768041dfdf6f4a944d46a3ecd779e6b078432b94 100644 (file)
@@ -97,7 +97,7 @@ public class XmlPatchStatusBodyWriter extends AbstractPatchStatusBodyWriter {
             writer.writeEndElement();
 
             writer.writeStartElement("error-tag");
-            writer.writeCharacters(restconfError.getErrorTag().getTagValue());
+            writer.writeCharacters(restconfError.getErrorTag().elementBody());
             writer.writeEndElement();
 
             // optional node
index 69274fcb8a5c20641d074c3a32d3cc807fcbf9f5..4e2c5a9aff4aa33709adeb8fe609f40f24044bda 100644 (file)
@@ -18,13 +18,13 @@ import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.util.DataChangeScope;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListenerAdapter;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
index 67a85b4586da35b854d3b05fd75b78e1a1c00cef..74e118885855b285160656216058304147ade1a0 100644 (file)
@@ -47,8 +47,6 @@ import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.context.WriterParameters;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
@@ -72,6 +70,7 @@ import org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUti
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -171,7 +170,7 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         if (node == null) {
             throw new RestconfDocumentedException(
                     "Request could not be completed because the relevant data model content does not exist",
-                    ErrorType.PROTOCOL, RestconfError.ErrorTag.DATA_MISSING);
+                    ErrorType.PROTOCOL, ErrorTag.DATA_MISSING);
         }
 
         if (parameters.getContent().equals(RestconfDataServiceConstant.ReadData.ALL)
@@ -249,7 +248,7 @@ public class RestconfDataServiceImpl implements RestconfDataService {
                 case INSERT:
                     if (insertUsed) {
                         throw new RestconfDocumentedException("Insert parameter can be used only once.",
-                            ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
+                            ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
                     }
 
                     insertUsed = true;
@@ -257,13 +256,13 @@ public class RestconfDataServiceImpl implements RestconfDataService {
                     insert = Insert.forValue(str);
                     if (insert == null) {
                         throw new RestconfDocumentedException("Unrecognized insert parameter value '" + str + "'",
-                            ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
+                            ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
                     }
                     break;
                 case POINT:
                     if (pointUsed) {
                         throw new RestconfDocumentedException("Point parameter can be used only once.",
-                            ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
+                            ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
                     }
 
                     pointUsed = true;
@@ -271,7 +270,7 @@ public class RestconfDataServiceImpl implements RestconfDataService {
                     break;
                 default:
                     throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey(),
-                            ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
+                            ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
             }
         }
 
@@ -283,13 +282,13 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         if (pointUsed) {
             if (!insertUsed) {
                 throw new RestconfDocumentedException("Point parameter can't be used without Insert parameter.",
-                    ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
+                    ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
             }
 
             if (insert != Insert.BEFORE && insert != Insert.AFTER) {
                 throw new RestconfDocumentedException(
                     "Point parameter can be used only with 'after' or 'before' values of Insert parameter.",
-                    ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
+                    ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
             }
         }
     }
index 9f90352a4061650e3078f5fbe1de89e70a70cfa3..0862e2eab2d87ce3c1d999c8b01dcf59b0717470 100644 (file)
@@ -15,12 +15,12 @@ import javax.ws.rs.sse.Sse;
 import javax.ws.rs.sse.SseEventSink;
 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataStreamService;
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 import org.opendaylight.restconf.nb.rfc8040.streams.SSESessionHandler;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.BaseListenerInterface;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index cb6283be6f1ffeeb70cee83d04c525a25de77fb3..76f2b1fc42188794067218efecffc7e7c742405b 100644 (file)
@@ -21,11 +21,11 @@ import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfInvokeOperationsService;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfInvokeOperationsUtil;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
index 8b34d287cb0e6e27c647723815ea2ef4fa86ba54..4e12ba40a640cd494d4e0f2af025b0e325eefae3 100644 (file)
@@ -18,12 +18,12 @@ import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.util.OperationsResourceUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfOperationsService;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
index c9f6b6b000cde11b926e271d5fd3d48d461640f4..31562f11e66d3cb61be88a9678ec1c665a408af3 100644 (file)
@@ -21,7 +21,6 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteOperations;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl.HandlersHolder;
@@ -33,6 +32,7 @@ import org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListen
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUtil;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
index 522b3b52ca9bacdb8be5d8c42aa1c3fc35f21bbc..c5cc67f8c49fe22af7b550964318180e362eb1f1 100644 (file)
@@ -21,9 +21,9 @@ import org.opendaylight.mdsal.common.api.ReadFailedException;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.DeleteDataTransactionUtil;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.TransactionUtil;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
@@ -128,7 +128,7 @@ final class MdsalRestconfTransaction extends RestconfTransaction {
             final ReadFailedException e = failure.getValue();
             if (e == null) {
                 throw new RestconfDocumentedException("Data already exists",
-                    ErrorType.PROTOCOL, RestconfError.ErrorTag.DATA_EXISTS, failure.getKey());
+                    ErrorType.PROTOCOL, ErrorTag.DATA_EXISTS, failure.getKey());
             }
 
             throw new RestconfDocumentedException(
index 84702fed22dab2ecb8daaf4d3e32d080f8994793..f346892e0317c448bd0d107b4b20b0776520827d 100644 (file)
@@ -12,9 +12,9 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.slf4j.Logger;
index 48163eb83fd0ab24c9a61e8587e9a0102b3073dd..5ed9290f1fc2943f28f4c38b1d014f01b8a254cc 100644 (file)
@@ -111,19 +111,18 @@ final class FutureCallbackTx {
                             LOG.trace("Operation via Restconf was not executed because data at {} already exists",
                                 path);
                             throw new RestconfDocumentedException(e, new RestconfError(ErrorType.PROTOCOL,
-                                RestconfError.ErrorTag.DATA_EXISTS, "Data already exists", path));
+                                ErrorTag.DATA_EXISTS, "Data already exists", path));
                         } else if (errorTag.equals(ErrorTag.DATA_MISSING)) {
                             LOG.trace("Operation via Restconf was not executed because data at {} does not exist",
                                 path);
                             throw new RestconfDocumentedException(e, new RestconfError(ErrorType.PROTOCOL,
-                                RestconfError.ErrorTag.DATA_MISSING, "Data does not exist", path));
+                                ErrorTag.DATA_MISSING, "Data does not exist", path));
                         }
                     }
                     if (error instanceof NetconfDocumentedException) {
                         throw new RestconfDocumentedException(error.getMessage(),
                                 ((NetconfDocumentedException) error).getErrorType(),
-                                RestconfError.ErrorTag.valueOfCaseInsensitive(
-                                        ((NetconfDocumentedException) error).getErrorTag().elementBody()), e);
+                                ((NetconfDocumentedException) error).getErrorTag(), e);
                     }
                 }
 
index 8b15b8bb4dfad1b21b1588fe54ef05bf77475615..2449f48a46915f51fd08ace32ffa5c48cb4606eb 100644 (file)
@@ -18,13 +18,13 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.common.patch.PatchStatusEntity;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
index 869fd79d6cbaa93ac8899ba55e0bb3a48ec4d770..31c787aa8ab8ee322c4e26066752d0d9fb564c40 100644 (file)
@@ -20,12 +20,11 @@ import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant.PostPutQueryParameters.Insert;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
@@ -139,7 +138,7 @@ public final class PostDataTransactionUtil {
             default:
                 throw new RestconfDocumentedException(
                     "Used bad value of insert parameter. Possible values are first, last, before or after, but was: "
-                        + insert, ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ATTRIBUTE);
+                        + insert, ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE);
         }
     }
 
index 316a0481753a86238a981f8c5030f7bf15eef3dc..37b360b16e6a2a65ab2935271c507788b02183cf 100644 (file)
@@ -17,11 +17,11 @@ import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant.PostPutQueryParameters.Insert;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
index 875438290a519224d0707312f1e6a8cd5fddba5d..a109731dc9930495d131dc4d3649a3cde7d2ee90 100644 (file)
@@ -31,9 +31,9 @@ import org.opendaylight.restconf.common.context.WriterParameters;
 import org.opendaylight.restconf.common.context.WriterParameters.WriterParametersBuilder;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant.ReadData.WithDefaults;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -141,7 +141,7 @@ public final class ReadDataTransactionUtil {
                 break;
             default:
                 throw new RestconfDocumentedException(
-                    new RestconfError(ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
+                    new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
                         "Invalid content parameter: " + contentValue, null,
                         "The content parameter value must be either config, nonconfig or all (default)"));
         }
@@ -153,7 +153,7 @@ public final class ReadDataTransactionUtil {
             if (value == null || value < RestconfDataServiceConstant.ReadData.MIN_DEPTH
                     || value > RestconfDataServiceConstant.ReadData.MAX_DEPTH) {
                 throw new RestconfDocumentedException(
-                        new RestconfError(ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
+                        new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
                                 "Invalid depth parameter: " + depth, null,
                                 "The depth parameter must be an integer between 1 and 65535 or \"unbounded\""));
             } else {
@@ -175,8 +175,8 @@ public final class ReadDataTransactionUtil {
             final String str = withDefaults.get(0);
             final WithDefaults val = WithDefaults.forValue(str);
             if (val == null) {
-                throw new RestconfDocumentedException(new RestconfError(ErrorType.PROTOCOL,
-                    RestconfError.ErrorTag.INVALID_VALUE, "Invalid with-defaults parameter: " + str, null,
+                throw new RestconfDocumentedException(new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
+                    "Invalid with-defaults parameter: " + str, null,
                     "The with-defaults parameter must be a string in " + WithDefaults.possibleValues()));
             }
 
@@ -223,7 +223,7 @@ public final class ReadDataTransactionUtil {
                 return readAllData(strategy, path, withDefa, ctx);
             default:
                 throw new RestconfDocumentedException(
-                        new RestconfError(ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
+                        new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
                                 "Invalid content parameter: " + valueOfContent, null,
                                 "The content parameter value must be either config, nonconfig or all (default)"));
         }
@@ -259,8 +259,8 @@ public final class ReadDataTransactionUtil {
             case RestconfDataServiceConstant.ReadData.ALL:
                 return readAllData(strategy, path, withDefa, ctx, fields);
             default:
-                throw new RestconfDocumentedException(new RestconfError(ErrorType.PROTOCOL,
-                        RestconfError.ErrorTag.INVALID_VALUE, "Invalid content parameter: " + valueOfContent, null,
+                throw new RestconfDocumentedException(new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
+                        "Invalid content parameter: " + valueOfContent, null,
                         "The content parameter value must be either config, nonconfig or all (default)"));
         }
     }
@@ -295,7 +295,7 @@ public final class ReadDataTransactionUtil {
                 .collect(Collectors.toSet());
             throw new RestconfDocumentedException(
                 "Not allowed parameters for " + READ_TYPE_TX + " operation: " + notAllowedParameters,
-                ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE);
+                ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
         }
     }
 
index a0bee88262c155278fa97a56e524de27211d9961..71a5333b924e52b9e749aed8d204703aa8b2b0ba 100644 (file)
@@ -18,7 +18,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.YangConstants;
index b5c6cdc6da8611c60a6223de4698ebfdb174fe18..20b966e0321d5b15f406c0e15b0b6de40abab4d5 100644 (file)
@@ -21,7 +21,7 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
index ae8e1995a2e235c7c1339db00a5b315e6bd3ac91..22c73f62ab19fc2384f5e80f183422579e6e1884 100644 (file)
@@ -26,11 +26,12 @@ 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.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.schema.SchemaExportContext;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -92,7 +93,7 @@ public final class ParserIdentifier {
         final YangInstanceIdentifier mountPath = IdentifierCodec.deserialize(mountPointId, schemaContext);
         final DOMMountPoint mountPoint = mountPointService.get().getMountPoint(mountPath)
                 .orElseThrow(() -> new RestconfDocumentedException("Mount point does not exist.",
-                    ErrorType.PROTOCOL, ErrorTag.RESOURCE_DENIED_TRANSPORT));
+                    ErrorType.PROTOCOL, ErrorTags.RESOURCE_DENIED_TRANSPORT));
 
         final EffectiveModelContext mountSchemaContext = coerceModelContext(mountPoint);
         final String pathId = pathsIt.next().replaceFirst("/", "");
index 275b91a59cad82bac29cf2db7c28571f1deb3b9f..c8647a675d510da12777103c07c87a6c56429d08 100644 (file)
@@ -18,10 +18,10 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Optional;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.util.RestUtil;
 import org.opendaylight.restconf.common.util.RestconfSchemaUtil;
 import org.opendaylight.restconf.nb.rfc8040.codecs.RestCodec;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -289,7 +289,7 @@ public final class YangInstanceIdentifierDeserializer {
 
     private void checkValidIdentifierStart() {
         checkValid(ParserConstants.YANG_IDENTIFIER_START.matches(currentChar()), ErrorTag.MALFORMED_MESSAGE,
-                "Identifier must start with character from set 'a-zA-Z_'");
+            "Identifier must start with character from set 'a-zA-Z_'");
     }
 
     private RestconfDocumentedException getParsingCharFailedException() {
index bea3dfe82fe0ccc478f15be7343b7e2f9422f176..5b3e4fdcb5664585806c5cca7987acc636ca0789 100644 (file)
@@ -13,8 +13,8 @@ import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map.Entry;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.yangtools.concepts.Serializer;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
index 962950a267b62114e7717e3c93f45112b4b42459..af0bb0d0d24ac1fdb02e1c823c657a1a93b3e328 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
@@ -16,7 +17,6 @@ import java.io.InputStream;
 import java.util.Collection;
 import java.util.Optional;
 import javax.ws.rs.core.MediaType;
-import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
@@ -26,6 +26,7 @@ import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -197,11 +198,11 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
      */
     @Test
     public void findBarContainerUsingNamespaceTest() throws Exception {
-        mockBodyReader("instance-identifier-module:cont/yang-ext:mount", this.xmlBodyReader, true);
-        final InputStream inputStream = XmlBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml");
-        final NormalizedNodeContext returnValue = this.xmlBodyReader
-                .readFrom(null, null, null, this.mediaType, null, inputStream);
+        mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, true);
+        final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlDataFindBarContainer.xml");
+        final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
+            inputStream);
 
         // check return value
         checkMountPointNormalizedNodeContext(returnValue);
@@ -220,16 +221,13 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
     @Test
     public void wrongRootElementTest() throws Exception {
         mockBodyReader("instance-identifier-module:cont/yang-ext:mount", this.xmlBodyReader, false);
-        final InputStream inputStream =
-                XmlBodyReaderTest.class.getResourceAsStream(
-                "/instanceidentifier/xml/bug7933.xml");
-        try {
-            this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
-            Assert.fail("Test should fail due to malformed PUT operation message");
-        } catch (final RestconfDocumentedException exception) {
-            final RestconfError restconfError = exception.getErrors().get(0);
-            Assert.assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
-            Assert.assertEquals(RestconfError.ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
-        }
+        final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
+            "/instanceidentifier/xml/bug7933.xml");
+
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream));
+        final RestconfError restconfError = ex.getErrors().get(0);
+        assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
     }
 }
index b92901f1d3cdcf164c473e870c4e26c9d9dd1c09..c537e6cc460119a29785faa1d224565480416fea 100644 (file)
@@ -29,9 +29,9 @@ import org.junit.runners.Parameterized.Parameter;
 import org.junit.runners.Parameterized.Parameters;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
index 505a4b41cc82fb250b85a2f11883f3377da3b1f9..9673a4b504f8574a34baad23a2a392cce411592b 100644 (file)
@@ -16,9 +16,9 @@ import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
@@ -47,9 +47,8 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
-            JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHdata.json"));
-        checkPatchContextMountPoint(returnValue);
+        checkPatchContextMountPoint(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+            JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHdata.json")));
     }
 
     /**
@@ -60,9 +59,9 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
-            JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHdataCreateAndDelete.json"));
-        checkPatchContextMountPoint(returnValue);
+        checkPatchContextMountPoint(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+            JsonBodyReaderTest.class.getResourceAsStream(
+                "/instanceidentifier/json/jsonPATCHdataCreateAndDelete.json")));
     }
 
     /**
@@ -76,9 +75,10 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
 
         final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream(
             "/instanceidentifier/json/jsonPATCHdataValueMissing.json");
+
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
-        assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -92,9 +92,10 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
 
         final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream(
             "/instanceidentifier/json/jsonPATCHdataValueNotSupported.json");
+
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
-        assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -105,10 +106,9 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+        checkPatchContextMountPoint(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
             JsonBodyReaderTest.class.getResourceAsStream(
-                "/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json"));
-        checkPatchContextMountPoint(returnValue);
+                "/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json")));
     }
 
     /**
@@ -119,10 +119,9 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+        checkPatchContextMountPoint(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
             JsonBodyReaderTest.class.getResourceAsStream(
-                "/instanceidentifier/json/jsonPATCHMergeOperationOnList.json"));
-        checkPatchContextMountPoint(returnValue);
+                "/instanceidentifier/json/jsonPATCHMergeOperationOnList.json")));
     }
 
     /**
@@ -133,10 +132,9 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+        checkPatchContextMountPoint(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
             JsonBodyReaderTest.class.getResourceAsStream(
-                "/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json"));
-        checkPatchContextMountPoint(returnValue);
+                "/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json")));
     }
 
     /**
@@ -147,8 +145,7 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
-            JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHSimpleLeafValue.json"));
-        checkPatchContext(returnValue);
+        checkPatchContext(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+            JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHSimpleLeafValue.json")));
     }
 }
index 1a478219d8d8fcf70a858d920768a926c068e27c..91a409d763eedd325052cf876f2e29201ccfee78 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
 
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
 
 import java.io.InputStream;
 import javax.ws.rs.core.MediaType;
@@ -19,6 +19,7 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
@@ -46,11 +47,10 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = JsonBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHdata.json");
+        final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHdata.json");
 
-        final PatchContext returnValue = jsonToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
@@ -62,11 +62,10 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = JsonBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataCreateAndDelete.json");
+        final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHdataCreateAndDelete.json");
 
-        final PatchContext returnValue = jsonToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
@@ -79,15 +78,12 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = JsonBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataValueMissing.json");
+        final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHdataValueMissing.json");
 
-        try {
-            jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-            fail("Test should return error 400 due to missing value node when attempt to invoke create operation");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -99,15 +95,12 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = JsonBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataValueNotSupported.json");
+        final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHdataValueNotSupported.json");
 
-        try {
-            jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-            fail("Test should return error 400 due to present value node when attempt to invoke delete operation");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -118,11 +111,10 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = JsonBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json");
+        final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json");
 
-        final PatchContext returnValue = jsonToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
@@ -134,11 +126,10 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = JsonBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHMergeOperationOnList.json");
+        final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHMergeOperationOnList.json");
 
-        final PatchContext returnValue = jsonToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
@@ -150,11 +141,10 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream = JsonBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json");
+        final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json");
 
-        final PatchContext returnValue = jsonToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 
@@ -166,12 +156,10 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
         final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
         mockBodyReader(uri, jsonToPatchBodyReader, false);
 
-        final InputStream inputStream =
-                JsonBodyReaderTest.class
-                .getResourceAsStream("/instanceidentifier/json/jsonPATCHSimpleLeafValue.json");
+        final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream(
+            "/instanceidentifier/json/jsonPATCHSimpleLeafValue.json");
 
-        final PatchContext returnValue = jsonToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContext(returnValue);
     }
 }
index 3eb8f43f687451fdf98027491ea44690966c8d81..54a355e421f8e95e5885d51bc3e2ad9521f67b88 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
@@ -47,8 +48,9 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
 
-        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
-            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml"));
+        final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdata.xml");
+        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContextMountPoint(returnValue);
     }
 
@@ -64,7 +66,7 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
 
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
-        assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -78,12 +80,11 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
             "/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
 
-        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
-        assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
-
     /**
      * Test of Yang Patch with absolute target path.
      */
@@ -92,9 +93,9 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final String uri = MOUNT_POINT;
         mockBodyReader(uri, xmlToPatchBodyReader, false);
 
-        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
-            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml"));
-        checkPatchContextMountPoint(returnValue);
+        checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream(
+                "/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml")));
     }
 
     /**
@@ -105,9 +106,9 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
 
-        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
-            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml"));
-        checkPatchContextMountPoint(returnValue);
+        checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream(
+                "/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml")));
     }
 
     /**
@@ -118,10 +119,9 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
 
-        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+        checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
             XmlBodyReaderTest.class.getResourceAsStream(
-                "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml"));
-        checkPatchContextMountPoint(returnValue);
+                "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml")));
     }
 
     /**
@@ -132,9 +132,8 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
 
-        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+        checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
             XmlBodyReaderTest.class.getResourceAsStream(
-                "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml"));
-        checkPatchContextMountPoint(returnValue);
+                "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml")));
     }
 }
index cc29eadd5395767364415fae90982c5dfac90c9d..60571fa66a2d1d952bc3d923b2ef6f817b58eff4 100644 (file)
@@ -15,9 +15,9 @@ import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
@@ -42,12 +42,9 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
 
     @Test
     public void moduleDataTest() throws Exception {
-        final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
-        mockBodyReader(uri, xmlToPatchBodyReader, false);
-
-        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
-            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml"));
-        checkPatchContext(returnValue);
+        mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
+        checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml")));
     }
 
     /**
@@ -55,14 +52,12 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
      */
     @Test
     public void moduleDataValueMissingNegativeTest() throws Exception {
-        final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
-        mockBodyReader(uri, xmlToPatchBodyReader, false);
+        mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
         final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
             "/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
-
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
-        assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -71,28 +66,22 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
      */
     @Test
     public void moduleDataNotValueNotSupportedNegativeTest() throws Exception {
-        final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
-        mockBodyReader(uri, xmlToPatchBodyReader, false);
+        mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
         final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
             "/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
-
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
-        assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
-
     /**
      * Test of Yang Patch with absolute target path.
      */
     @Test
     public void moduleDataAbsoluteTargetPathTest() throws Exception {
-        final String uri = "";
-        mockBodyReader(uri, xmlToPatchBodyReader, false);
-
-        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
-            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml"));
-        checkPatchContext(returnValue);
+        mockBodyReader("", xmlToPatchBodyReader, false);
+        checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml")));
     }
 
     /**
@@ -100,12 +89,10 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
      */
     @Test
     public void modulePatchCompleteTargetInURITest() throws Exception {
-        final String uri = "instance-identifier-patch-module:patch-cont";
-        mockBodyReader(uri, xmlToPatchBodyReader, false);
-
-        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
-            XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml"));
-        checkPatchContext(returnValue);
+        mockBodyReader("instance-identifier-patch-module:patch-cont", xmlToPatchBodyReader, false);
+        checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+            XmlBodyReaderTest.class.getResourceAsStream(
+                "/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml")));
     }
 
     /**
@@ -113,13 +100,10 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
      */
     @Test
     public void moduleDataMergeOperationOnListTest() throws Exception {
-        final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
-        mockBodyReader(uri, xmlToPatchBodyReader, false);
-
-        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
-            XmlBodyReaderTest.class.getResourceAsStream(
-                "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml"));
-        checkPatchContext(returnValue);
+        mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
+        final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml");
+        checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
     }
 
     /**
@@ -127,11 +111,9 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
      */
     @Test
     public void moduleDataMergeOperationOnContainerTest() throws Exception {
-        final String uri = "instance-identifier-patch-module:patch-cont";
-        mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
-            XmlBodyReaderTest.class.getResourceAsStream(
-                "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml"));
-        checkPatchContext(returnValue);
+        mockBodyReader("instance-identifier-patch-module:patch-cont", xmlToPatchBodyReader, false);
+        final InputStream inputStream = XmlBodyReaderTest.class
+                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml");
+        checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
     }
 }
index 2832e2ebd0d10d256d16e45df7a9ba3a897d337f..a721718d76658cb5a87c6cea45c014b93780a9b5 100644 (file)
@@ -31,12 +31,12 @@ import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.TestUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
@@ -67,9 +67,7 @@ public abstract class AbstractBodyReaderTest {
     }
 
     protected static <T extends AbstractIdentifierAwareJaxRsProvider<?>> void mockBodyReader(
-            final String identifier, final T normalizedNodeProvider,
-            final boolean isPost) throws NoSuchFieldException,
-            SecurityException, IllegalArgumentException, IllegalAccessException {
+            final String identifier, final T normalizedNodeProvider, final boolean isPost) {
         final UriInfo uriInfoMock = mock(UriInfo.class);
         final MultivaluedMap<String, String> pathParm = new MultivaluedHashMap<>(1);
 
index abc193ba79238f497c1363d354bec05bccc6aff0..2a182e4205ffd5158120f643a7b3c011ee74a3c6 100644 (file)
@@ -28,6 +28,7 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlNormalizedNodeBodyReader;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -282,7 +283,7 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
         } catch (final RestconfDocumentedException exception) {
             final RestconfError restconfError = exception.getErrors().get(0);
             Assert.assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
-            Assert.assertEquals(RestconfError.ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
+            Assert.assertEquals(ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
         }
     }
 
@@ -295,5 +296,4 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
 
         assertRangeViolation(() -> xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream));
     }
-
 }
index e8eec5df8996c17f6ebdfbeb74139848440546f9..33ba82bbb77edf6c2a833399a25cf4e8cc2653ea 100644 (file)
@@ -11,7 +11,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.fail;
 import static org.mockito.Mockito.when;
 
 import java.io.FileNotFoundException;
@@ -28,11 +27,11 @@ 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.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.schema.SchemaExportContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfSchemaService;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -103,14 +102,6 @@ public class RestconfSchemaServiceTest {
         this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler, mountPointService, sourceProvider);
     }
 
-    /**
-     * Test if service was successfully created.
-     */
-    @Test
-    public void schemaServiceImplInitTest() {
-        assertNotNull("Schema service should be initialized and not null", this.schemaService);
-    }
-
     /**
      * Get schema with identifier of existing module and check if correct module was found.
      */
@@ -120,7 +111,7 @@ public class RestconfSchemaServiceTest {
         when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT);
 
         // make test
-        final SchemaExportContext exportContext = this.schemaService.getSchema(TEST_MODULE);
+        final SchemaExportContext exportContext = schemaService.getSchema(TEST_MODULE);
 
         // verify
         assertNotNull("Export context should not be null", exportContext);
@@ -143,7 +134,7 @@ public class RestconfSchemaServiceTest {
         when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT);
 
         // make test
-        final SchemaExportContext exportContext = this.schemaService.getSchema(NOT_EXISTING_MODULE);
+        final SchemaExportContext exportContext = schemaService.getSchema(NOT_EXISTING_MODULE);
 
         // verify
         assertNotNull("Export context should not be null", exportContext);
@@ -160,7 +151,7 @@ public class RestconfSchemaServiceTest {
 
         // make test
         final SchemaExportContext exportContext =
-                this.schemaService.getSchema(MOUNT_POINT + TEST_MODULE_BEHIND_MOUNT_POINT);
+                schemaService.getSchema(MOUNT_POINT + TEST_MODULE_BEHIND_MOUNT_POINT);
 
         // verify
         assertNotNull("Export context should not be null", exportContext);
@@ -183,7 +174,7 @@ public class RestconfSchemaServiceTest {
         when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT_WITH_MOUNT_POINTS);
 
         // make test
-        final SchemaExportContext exportContext = this.schemaService.getSchema(MOUNT_POINT + NOT_EXISTING_MODULE);
+        final SchemaExportContext exportContext = schemaService.getSchema(MOUNT_POINT + NOT_EXISTING_MODULE);
 
         // verify
         assertNotNull("Export context should not be null", exportContext);
@@ -199,7 +190,7 @@ public class RestconfSchemaServiceTest {
         when(this.mockContextHandler.get()).thenReturn(null);
 
         // make test
-        assertThrows(NullPointerException.class, () -> this.schemaService.getSchema(TEST_MODULE));
+        assertThrows(NullPointerException.class, () -> schemaService.getSchema(TEST_MODULE));
     }
 
     /**
@@ -213,7 +204,7 @@ public class RestconfSchemaServiceTest {
 
         // make test
         assertThrows(NullPointerException.class,
-            () -> this.schemaService.getSchema(MOUNT_POINT + TEST_MODULE_BEHIND_MOUNT_POINT));
+            () -> schemaService.getSchema(MOUNT_POINT + TEST_MODULE_BEHIND_MOUNT_POINT));
     }
 
     /**
@@ -254,14 +245,10 @@ public class RestconfSchemaServiceTest {
         when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT);
 
         // make test and verify
-        try {
-            this.schemaService.getSchema("");
-            fail("Test should fail due to invalid identifier");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals(RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals(400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> schemaService.getSchema(""));
+        assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -275,14 +262,10 @@ public class RestconfSchemaServiceTest {
         when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT_WITH_MOUNT_POINTS);
 
         // make test and verify
-        try {
-            this.schemaService.getSchema(MOUNT_POINT + "");
-            fail("Test should fail due to invalid identifier");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals(RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals(400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> schemaService.getSchema(MOUNT_POINT + ""));
+        assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -295,14 +278,10 @@ public class RestconfSchemaServiceTest {
         when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT);
 
         // make test and verify
-        try {
-            this.schemaService.getSchema("01_module/2016-01-01");
-            fail("Test should fail due to invalid identifier");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals(RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals(400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> schemaService.getSchema("01_module/2016-01-01"));
+        assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -316,14 +295,10 @@ public class RestconfSchemaServiceTest {
         when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT_WITH_MOUNT_POINTS);
 
         // make test and verify
-        try {
-            this.schemaService.getSchema(MOUNT_POINT + "01_module/2016-01-01");
-            fail("Test should fail due to invalid identifier");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals(RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals(400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> schemaService.getSchema(MOUNT_POINT + "01_module/2016-01-01"));
+        assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -339,14 +314,10 @@ public class RestconfSchemaServiceTest {
         when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT);
 
         // make test and verify
-        try {
-            this.schemaService.getSchema("2014-01-01");
-            fail("Test should fail due to invalid identifier");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals(RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals(400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> schemaService.getSchema("2014-01-01"));
+        assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -363,14 +334,10 @@ public class RestconfSchemaServiceTest {
         when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT_WITH_MOUNT_POINTS);
 
         // make test and verify
-        try {
-            this.schemaService.getSchema(MOUNT_POINT + "2014-01-01");
-            fail("Test should fail due to invalid identifier");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals(RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals(400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> schemaService.getSchema(MOUNT_POINT + "2014-01-01"));
+        assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -384,14 +351,10 @@ public class RestconfSchemaServiceTest {
         when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT);
 
         // make test and verify
-        try {
-            this.schemaService.getSchema("module");
-            fail("Test should fail due to invalid identifier");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals(RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals(400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> schemaService.getSchema("module"));
+        assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -405,14 +368,10 @@ public class RestconfSchemaServiceTest {
         when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT_WITH_MOUNT_POINTS);
 
         // make test and verify
-        try {
-            this.schemaService.getSchema(MOUNT_POINT + "module");
-            fail("Test should fail due to invalid identifier");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals(RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals(400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> schemaService.getSchema(MOUNT_POINT + "module"));
+        assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -426,6 +385,6 @@ public class RestconfSchemaServiceTest {
 
         // make test
         assertThrows(RestconfDocumentedException.class,
-            () -> this.schemaService.getSchema(NOT_EXISTING_MOUNT_POINT + TEST_MODULE_BEHIND_MOUNT_POINT));
+            () -> schemaService.getSchema(NOT_EXISTING_MOUNT_POINT + TEST_MODULE_BEHIND_MOUNT_POINT));
     }
 }
index 419853552d4f60249d67ddba3b17bdaa4b19f8a7..163f834c9a42ce51a07c75c68d6129f03b6657c1 100644 (file)
@@ -33,7 +33,6 @@ import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
@@ -112,7 +111,7 @@ public class DeleteDataTransactionUtilTest {
             fail("Delete operation should fail due to missing data");
         } catch (final RestconfDocumentedException e) {
             assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals(RestconfError.ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
+            assertEquals(ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
         }
     }
 }
index 03e661895385588616e45b8ad77afd2d0f150c43..0b7ed3e2a3e1d030c232c9a1fed42e4546d1df82 100644 (file)
@@ -40,7 +40,6 @@ import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
@@ -291,7 +290,7 @@ public class PatchDataTransactionUtilTest {
         assertFalse(patchStatusContext.isOk());
         assertEquals(ErrorType.PROTOCOL,
                 patchStatusContext.getEditCollection().get(0).getEditErrors().get(0).getErrorType());
-        assertEquals(RestconfError.ErrorTag.DATA_MISSING,
+        assertEquals(ErrorTag.DATA_MISSING,
                 patchStatusContext.getEditCollection().get(0).getEditErrors().get(0).getErrorTag());
     }
 
@@ -302,7 +301,7 @@ public class PatchDataTransactionUtilTest {
         assertFalse(patchStatusContext.isOk());
         assertEquals(ErrorType.PROTOCOL,
             patchStatusContext.getGlobalErrors().get(0).getErrorType());
-        assertEquals(RestconfError.ErrorTag.DATA_MISSING,
+        assertEquals(ErrorTag.DATA_MISSING,
             patchStatusContext.getGlobalErrors().get(0).getErrorTag());
     }
 }
index be1e939baea3b6f051869b7bc9e6bd96dd99b3b6..9a7ebc65a62f9ced780e22ebad491e66ead285ea 100644 (file)
@@ -14,7 +14,6 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -41,12 +40,12 @@ import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.WriterParameters;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant.ReadData;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant.ReadData.WithDefaults;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -412,15 +411,11 @@ public class ReadDataTransactionUtilTest {
         parameters.put("content", List.of("not-allowed-parameter-value"));
         when(uriInfo.getQueryParameters()).thenReturn(parameters);
 
-        try {
-            ReadDataTransactionUtil.parseUriParameters(context, uriInfo);
-            fail("Test expected to fail due to not allowed parameter value");
-        } catch (final RestconfDocumentedException e) {
-            // Bad request
-            assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ReadDataTransactionUtil.parseUriParameters(context, uriInfo));
+        // Bad request
+        assertEquals("Error type is not correct", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -435,15 +430,11 @@ public class ReadDataTransactionUtilTest {
         parameters.put("depth", List.of("bounded"));
         when(uriInfo.getQueryParameters()).thenReturn(parameters);
 
-        try {
-            ReadDataTransactionUtil.parseUriParameters(context, uriInfo);
-            fail("Test expected to fail due to not allowed parameter value");
-        } catch (final RestconfDocumentedException e) {
-            // Bad request
-            assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ReadDataTransactionUtil.parseUriParameters(context, uriInfo));
+        // Bad request
+        assertEquals("Error type is not correct", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -459,15 +450,11 @@ public class ReadDataTransactionUtilTest {
                 "depth", List.of(String.valueOf(RestconfDataServiceConstant.ReadData.MIN_DEPTH - 1)));
         when(uriInfo.getQueryParameters()).thenReturn(parameters);
 
-        try {
-            ReadDataTransactionUtil.parseUriParameters(context, uriInfo);
-            fail("Test expected to fail due to not allowed parameter value");
-        } catch (final RestconfDocumentedException e) {
-            // Bad request
-            assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ReadDataTransactionUtil.parseUriParameters(context, uriInfo));
+        // Bad request
+        assertEquals("Error type is not correct", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -479,19 +466,14 @@ public class ReadDataTransactionUtilTest {
         final MultivaluedHashMap<String, String> parameters = new MultivaluedHashMap<>();
 
         // inserted value is too high
-        parameters.put(
-                "depth", List.of(String.valueOf(RestconfDataServiceConstant.ReadData.MAX_DEPTH + 1)));
+        parameters.put("depth", List.of(String.valueOf(RestconfDataServiceConstant.ReadData.MAX_DEPTH + 1)));
         when(uriInfo.getQueryParameters()).thenReturn(parameters);
 
-        try {
-            ReadDataTransactionUtil.parseUriParameters(context, uriInfo);
-            fail("Test expected to fail due to not allowed parameter value");
-        } catch (final RestconfDocumentedException e) {
-            // Bad request
-            assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ReadDataTransactionUtil.parseUriParameters(context, uriInfo));
+        // Bad request
+        assertEquals("Error type is not correct", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -587,7 +569,6 @@ public class ReadDataTransactionUtilTest {
         final RestconfError error = errors.get(0);
         assertEquals("Error type is not correct", ErrorType.PROTOCOL, error.getErrorType());
         assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, error.getErrorTag());
-        assertEquals("Error status code is not correct", 400, error.getErrorTag().getStatusCode());
     }
 
 
@@ -614,7 +595,6 @@ public class ReadDataTransactionUtilTest {
         final RestconfError error = errors.get(0);
         assertEquals("Error type is not correct", ErrorType.PROTOCOL, error.getErrorType());
         assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, error.getErrorTag());
-        assertEquals("Error status code is not correct", 400, error.getErrorTag().getStatusCode());
     }
 
     /**
index e5fd6b7acadb9e9cbdca34615ad98dd9be7eeb50..375485ba577cee6fb79c65a8ddd5ea81219ee935 100644 (file)
@@ -9,13 +9,11 @@ package org.opendaylight.restconf.nb.rfc8040.utils.parser;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.when;
 
-import com.google.common.collect.Sets;
-import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
@@ -26,8 +24,8 @@ import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -185,8 +183,8 @@ public class ParserFieldsParameterTest {
         when(leafSpeed.isAugmenting()).thenReturn(true);
         when(containerPlayer.dataChildByName(SPEED_Q_NAME)).thenReturn(leafSpeed);
         when(containerPlayer.getDataChildByName(SPEED_Q_NAME)).thenReturn(leafSpeed);
-        doReturn(Collections.singletonList(leafSpeed)).when(speedAugmentation).getChildNodes();
-        doReturn(Collections.singleton(speedAugmentation)).when(containerPlayer).getAvailableAugmentations();
+        doReturn(List.of(leafSpeed)).when(speedAugmentation).getChildNodes();
+        doReturn(List.of(speedAugmentation)).when(containerPlayer).getAvailableAugmentations();
         when(speedAugmentation.findDataChildByName(SPEED_Q_NAME)).thenReturn(Optional.of(leafSpeed));
     }
 
@@ -322,10 +320,10 @@ public class ParserFieldsParameterTest {
         assertTrue(parsedFields.get(0).contains(SERVICES_Q_NAME));
 
         assertEquals(parsedFields.get(1).size(), 2);
-        assertTrue(parsedFields.get(1).containsAll(Sets.newHashSet(TYPE_OF_SERVICE_Q_NAME, INSTANCE_Q_NAME)));
+        assertTrue(parsedFields.get(1).containsAll(List.of(TYPE_OF_SERVICE_Q_NAME, INSTANCE_Q_NAME)));
 
         assertEquals(parsedFields.get(2).size(), 2);
-        assertTrue(parsedFields.get(2).containsAll(Sets.newHashSet(INSTANCE_NAME_Q_NAME, PROVIDER_Q_NAME)));
+        assertTrue(parsedFields.get(2).containsAll(List.of(INSTANCE_NAME_Q_NAME, PROVIDER_Q_NAME)));
     }
 
     /**
@@ -344,10 +342,10 @@ public class ParserFieldsParameterTest {
         assertTrue(parsedFields.get(0).contains(SERVICES_Q_NAME));
 
         assertEquals(parsedFields.get(1).size(), 2);
-        assertTrue(parsedFields.get(1).containsAll(Sets.newHashSet(TYPE_OF_SERVICE_Q_NAME, INSTANCE_Q_NAME)));
+        assertTrue(parsedFields.get(1).containsAll(List.of(TYPE_OF_SERVICE_Q_NAME, INSTANCE_Q_NAME)));
 
         assertEquals(parsedFields.get(2).size(), 2);
-        assertTrue(parsedFields.get(2).containsAll(Sets.newHashSet(INSTANCE_NAME_Q_NAME, PROVIDER_Q_NAME)));
+        assertTrue(parsedFields.get(2).containsAll(List.of(INSTANCE_NAME_Q_NAME, PROVIDER_Q_NAME)));
     }
 
     /**
@@ -367,11 +365,11 @@ public class ParserFieldsParameterTest {
 
         assertEquals(parsedFields.get(1).size(), 3);
         assertTrue(parsedFields.get(1).containsAll(
-                Sets.newHashSet(TYPE_OF_SERVICE_Q_NAME, INSTANCE_Q_NAME, NEXT_DATA_Q_NAME)));
+                List.of(TYPE_OF_SERVICE_Q_NAME, INSTANCE_Q_NAME, NEXT_DATA_Q_NAME)));
 
         assertEquals(parsedFields.get(2).size(), 2);
         assertTrue(parsedFields.get(2).containsAll(
-                Sets.newHashSet(INSTANCE_NAME_Q_NAME, NEXT_SERVICE_Q_NAME)));
+                List.of(INSTANCE_NAME_Q_NAME, NEXT_SERVICE_Q_NAME)));
     }
 
     /**
@@ -379,17 +377,11 @@ public class ParserFieldsParameterTest {
      */
     @Test
     public void parseFieldsParameterNotExpectedCharacterNegativeTest() {
-        final String input = "*";
-
-        try {
-            ParserFieldsParameter.parseFieldsParameter(this.identifierJukebox, input);
-            fail("Test should fail due to not expected character used in parameter input value");
-        } catch (final RestconfDocumentedException e) {
-            // Bad request
-            assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserFieldsParameter.parseFieldsParameter(identifierJukebox, "*"));
+        // Bad request
+        assertEquals("Error type is not correct", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -399,15 +391,11 @@ public class ParserFieldsParameterTest {
     public void parseFieldsParameterMissingParenthesisNegativeTest() {
         final String input = "library(";
 
-        try {
-            ParserFieldsParameter.parseFieldsParameter(this.identifierJukebox, input);
-            fail("Test should fail due to missing closing parenthesis");
-        } catch (final RestconfDocumentedException e) {
-            // Bad request
-            assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserFieldsParameter.parseFieldsParameter(identifierJukebox, input));
+        // Bad request
+        assertEquals("Error type is not correct", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -417,15 +405,11 @@ public class ParserFieldsParameterTest {
     public void parseFieldsParameterMissingChildNodeNegativeTest() {
         final String input = "library(not-existing)";
 
-        try {
-            ParserFieldsParameter.parseFieldsParameter(this.identifierJukebox, input);
-            fail("Test should fail due to missing child node in parent node");
-        } catch (final RestconfDocumentedException e) {
-            // Bad request
-            assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserFieldsParameter.parseFieldsParameter(identifierJukebox, input));
+        // Bad request
+        assertEquals("Error type is not correct", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -435,15 +419,11 @@ public class ParserFieldsParameterTest {
     public void parseFieldsParameterAfterParenthesisNegativeTest() {
         final String input = "library(album);";
 
-        try {
-            ParserFieldsParameter.parseFieldsParameter(this.identifierJukebox, input);
-            fail("Test should fail due to unexpected character after parenthesis");
-        } catch (final RestconfDocumentedException e) {
-            // Bad request
-            assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserFieldsParameter.parseFieldsParameter(identifierJukebox, input));
+        // Bad request
+        assertEquals("Error type is not correct", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -453,15 +433,11 @@ public class ParserFieldsParameterTest {
     public void parseFieldsParameterMissingSemicolonNegativeTest() {
         final String input = "library(album)player";
 
-        try {
-            ParserFieldsParameter.parseFieldsParameter(this.identifierJukebox, input);
-            fail("Test should fail due to missing semicolon after parenthesis");
-        } catch (final RestconfDocumentedException e) {
-            // Bad request
-            assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserFieldsParameter.parseFieldsParameter(this.identifierJukebox, input));
+        // Bad request
+        assertEquals("Error type is not correct", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     @Test
index c782be9bb0293c7f7aa6e86ac42d61e43d8c3ec6..1c4f8fec60572b16d9a649ac4a5a9efadc454acc 100644 (file)
@@ -14,6 +14,7 @@ import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.when;
 
+import java.util.List;
 import java.util.Map.Entry;
 import java.util.Optional;
 import org.junit.AfterClass;
@@ -29,13 +30,14 @@ 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.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.schema.SchemaExportContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -249,8 +251,10 @@ public class ParserIdentifierTest {
         RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> ParserIdentifier.toInstanceIdentifier("/yang-ext:mount", SCHEMA_CONTEXT,
                 Optional.of(this.mountPointService)));
-        assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", ErrorTag.RESOURCE_DENIED_TRANSPORT, ex.getErrors().get(0).getErrorTag());
+        final List<RestconfError> errors = ex.getErrors();
+        assertEquals(1, errors.size());
+        assertEquals("Not expected error type", ErrorType.PROTOCOL, errors.get(0).getErrorType());
+        assertEquals("Not expected error tag", ErrorTags.RESOURCE_DENIED_TRANSPORT, errors.get(0).getErrorTag());
     }
 
     /**
@@ -264,7 +268,6 @@ public class ParserIdentifierTest {
             () -> ParserIdentifier.toInstanceIdentifier("yang-ext:mount", SCHEMA_CONTEXT, Optional.empty()));
         assertEquals("Not expected error type", ErrorType.APPLICATION, ex.getErrors().get(0).getErrorType());
         assertEquals("Not expected error tag", ErrorTag.OPERATION_FAILED, ex.getErrors().get(0).getErrorTag());
-        assertEquals("Not expected error status code", 500, ex.getErrors().get(0).getErrorTag().getStatusCode());
     }
 
     /**
@@ -295,9 +298,8 @@ public class ParserIdentifierTest {
         RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME));
         assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
             ex.getErrors().get(0).getErrorTag());
-        assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
     }
 
     /**
@@ -310,9 +312,8 @@ public class ParserIdentifierTest {
         RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME));
         assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
             ex.getErrors().get(0).getErrorTag());
-        assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
     }
 
     /**
@@ -344,9 +345,8 @@ public class ParserIdentifierTest {
             () -> ParserIdentifier.makeQNameFromIdentifier(
                     MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME));
         assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
             ex.getErrors().get(0).getErrorTag());
-        assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
     }
 
     /**
@@ -359,9 +359,8 @@ public class ParserIdentifierTest {
         RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> ParserIdentifier.makeQNameFromIdentifier(MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME));
         assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
             ex.getErrors().get(0).getErrorTag());
-        assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
     }
 
     /**
@@ -383,9 +382,8 @@ public class ParserIdentifierTest {
         RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> ParserIdentifier.makeQNameFromIdentifier(""));
         assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
             ex.getErrors().get(0).getErrorTag());
-        assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
     }
 
     /**
@@ -399,9 +397,8 @@ public class ParserIdentifierTest {
         RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "//" + TEST_MODULE_REVISION));
         assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
             ex.getErrors().get(0).getErrorTag());
-        assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
     }
 
     /**
@@ -422,12 +419,10 @@ public class ParserIdentifierTest {
         final Module module = exportContext.getModule();
         assertNotNull("Export context should contains test module", module);
 
-        assertEquals("Returned not expected module name",
-                TEST_MODULE_NAME, module.getName());
+        assertEquals("Returned not expected module name", TEST_MODULE_NAME, module.getName());
         assertEquals("Returned not expected module revision",
                 Revision.ofNullable(TEST_MODULE_REVISION), module.getRevision());
-        assertEquals("Returned not expected module namespace",
-                TEST_MODULE_NAMESPACE, module.getNamespace().toString());
+        assertEquals("Returned not expected module namespace", TEST_MODULE_NAMESPACE, module.getNamespace().toString());
     }
 
     /**
@@ -456,9 +451,8 @@ public class ParserIdentifierTest {
             () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
                     SCHEMA_CONTEXT, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null, sourceProvider));
         assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
             ex.getErrors().get(0).getErrorTag());
-        assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
     }
 
     /**
@@ -511,9 +505,8 @@ public class ParserIdentifierTest {
                 sourceProvider));
 
         assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
             ex.getErrors().get(0).getErrorTag());
-        assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
     }
 
     /**
index efa7f15ad7bd9ceb57b4565f5b6dc58cc471c311..df3986521de1d28a016e20f2166bd5fd11c6276c 100644 (file)
@@ -19,7 +19,7 @@ import java.util.Collections;
 import java.util.List;
 import org.junit.Test;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.Revision;
 
@@ -50,8 +50,7 @@ public class RestconfValidationTest {
             () -> ParserIdentifier.validateAndGetRevision(Collections.emptyIterator()));
 
         assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals(RestconfError.ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
-        assertEquals(400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -84,8 +83,7 @@ public class RestconfValidationTest {
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> ParserIdentifier.validateAndGetModulName(Collections.emptyIterator()));
         assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals(RestconfError.ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
-        assertEquals(400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -99,8 +97,7 @@ public class RestconfValidationTest {
             () -> ParserIdentifier.validateAndGetModulName(Iterators.singletonIterator(
                 "01-not-parsable-as-name-on-firts-char")));
         assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals(RestconfError.ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
-        assertEquals(400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -114,8 +111,7 @@ public class RestconfValidationTest {
             () -> ParserIdentifier.validateAndGetModulName(Iterators.singletonIterator(
                 "not-parsable-as-name-after-first-char*")));
         assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals(RestconfError.ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
-        assertEquals(400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -127,8 +123,7 @@ public class RestconfValidationTest {
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> ParserIdentifier.validateAndGetModulName(Iterators.singletonIterator("xMl-module-name")));
         assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals(RestconfError.ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
-        assertEquals(400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -140,7 +135,6 @@ public class RestconfValidationTest {
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> ParserIdentifier.validateAndGetModulName(Iterators.singletonIterator("")));
         assertEquals(ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals(RestconfError.ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
-        assertEquals(400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
     }
 }
index 31217280cd74a4d666c50c6a9d0e41cc61201c91..273b9e63d95b16bd2b6f844c89f73f049e7e4464 100644 (file)
@@ -23,8 +23,8 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -399,7 +399,7 @@ public class YangInstanceIdentifierDeserializerTest {
         RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:contA/leafB"));
         assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", RestconfError.ErrorTag.DATA_MISSING,
+        assertEquals("Not expected error tag", ErrorTag.DATA_MISSING,
             ex.getErrors().get(0).getErrorTag());
     }
 
@@ -414,7 +414,7 @@ public class YangInstanceIdentifierDeserializerTest {
             () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
                 "deserializer-test:list-no-key/disabled=false"));
         assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", RestconfError.ErrorTag.DATA_MISSING,
+        assertEquals("Not expected error tag", ErrorTag.DATA_MISSING,
             ex.getErrors().get(0).getErrorTag());
     }
 
@@ -478,9 +478,8 @@ public class YangInstanceIdentifierDeserializerTest {
             () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
                     "deserializer-test:list-multiple-keys=%3Afoo/string-value"));
         assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", RestconfError.ErrorTag.MISSING_ATTRIBUTE,
+        assertEquals("Not expected error tag", ErrorTag.MISSING_ATTRIBUTE,
             ex.getErrors().get(0).getErrorTag());
-        assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
     }
 
     /**
@@ -534,9 +533,8 @@ public class YangInstanceIdentifierDeserializerTest {
         RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
             () -> YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT, "deserializer-test:leaf-list-0="));
         assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
-        assertEquals("Not expected error tag", RestconfError.ErrorTag.MISSING_ATTRIBUTE,
+        assertEquals("Not expected error tag", ErrorTag.MISSING_ATTRIBUTE,
             ex.getErrors().get(0).getErrorTag());
-        assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
     }
 
     /**