From: Robert Varga Date: Mon, 26 Jul 2021 21:08:07 +0000 (+0200) Subject: Remove RestconfError.ErrorTag X-Git-Tag: v2.0.4~13 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=cd6157a02dc35ccdc37a3929cfc891e99d1bf29b;p=netconf.git Remove RestconfError.ErrorTag 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 --- 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 index 0000000000..952218aa7e --- /dev/null +++ b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/ErrorTags.java @@ -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 + * RFC8040 section 7, 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 WELL_KNOWN_ERROR_TAGS = ImmutableMap.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; + } +} diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfDocumentedException.java b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfDocumentedException.java index 66ead84da2..d09003857a 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfDocumentedException.java +++ b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfDocumentedException.java @@ -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 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()); diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfError.java b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfError.java index db193ddd9c..d9f701564b 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfError.java +++ b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfError.java @@ -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 RESTCONF. */ 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 : "") diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/RestconfSchemaUtil.java b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/RestconfSchemaUtil.java index 64110daf73..7e266c7d49 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/RestconfSchemaUtil.java +++ b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/RestconfSchemaUtil.java @@ -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; diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/validation/RestconfValidationUtils.java b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/validation/RestconfValidationUtils.java index cac528f642..987ce42c84 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/validation/RestconfValidationUtils.java +++ b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/validation/RestconfValidationUtils.java @@ -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 index 0000000000..a05f2566ed --- /dev/null +++ b/restconf/restconf-common/src/test/java/org/opendaylight/restconf/common/ErrorTagsTest.java @@ -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 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()); + } +} diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaRetrievalServiceImpl.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaRetrievalServiceImpl.java index 801b16bffb..70b09bf97b 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaRetrievalServiceImpl.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaRetrievalServiceImpl.java @@ -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; diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java index cda7ab7135..69ea71d569 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java @@ -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; diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java index d0686046cf..f17666c59e 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java @@ -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; diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/PatchJsonBodyWriter.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/PatchJsonBodyWriter.java index cdca49d7ca..63586af75b 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/PatchJsonBodyWriter.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/PatchJsonBodyWriter.java @@ -100,7 +100,7 @@ public class PatchJsonBodyWriter implements MessageBodyWriter writer.writeEndElement(); writer.writeStartElement("error-tag"); - writer.writeCharacters(restconfError.getErrorTag().getTagValue()); + writer.writeCharacters(restconfError.getErrorTag().elementBody()); writer.writeEndElement(); // optional node diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfDocumentedExceptionMapper.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfDocumentedExceptionMapper.java index 22fa6c71f6..2aaea2b91c 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfDocumentedExceptionMapper.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfDocumentedExceptionMapper.java @@ -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 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\"")); } diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java index 503fc62b62..77bb5f0635 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java @@ -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; diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/AbstractBodyReaderTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/AbstractBodyReaderTest.java index 677ef51eca..a9a8ce1431 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/AbstractBodyReaderTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/AbstractBodyReaderTest.java @@ -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()); } diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPatchBodyReader.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPatchBodyReader.java index d1c23ed6bd..f2a6c41531 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPatchBodyReader.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPatchBodyReader.java @@ -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); } diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPatchBodyReaderMountPoint.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPatchBodyReaderMountPoint.java index c3bee822fd..4ad1a6599a 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPatchBodyReaderMountPoint.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPatchBodyReaderMountPoint.java @@ -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()); } /** diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReader.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReader.java index 6eea15d81e..de8b21e07f 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReader.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReader.java @@ -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()); } } } diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReaderMountPoint.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReaderMountPoint.java index 8ad7d0a8c1..a66e3e7872 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReaderMountPoint.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReaderMountPoint.java @@ -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()); } } } diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReader.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReader.java index 9e3f54cd82..8b37ba4ee5 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReader.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReader.java @@ -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); } } diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReaderMountPoint.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReaderMountPoint.java index cb791543d0..614f36ed02 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReaderMountPoint.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReaderMountPoint.java @@ -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)); } } diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/input/to/cnsn/test/RestPutListDataTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/input/to/cnsn/test/RestPutListDataTest.java index 39d297e7bd..f9b34838b8 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/input/to/cnsn/test/RestPutListDataTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/input/to/cnsn/test/RestPutListDataTest.java @@ -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; diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java index c39251394b..65f446fed1 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java @@ -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 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 errors = ex.getErrors(); + assertEquals(1, errors.size()); + assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType()); + assertEquals(ErrorTag.DATA_MISSING, errors.get(0).getErrorTag()); } /** diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java index b744008d3d..b470f3933c 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java @@ -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")); } diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java index fffd64e060..4abf3abe1a 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java @@ -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"); diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfErrorTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfErrorTest.java index faddeca599..e986a56cc2 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfErrorTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfErrorTest.java @@ -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 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, "error", 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, "warning", new RestconfError(rpcError)); // No fields set - edge case diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java index 3b6cb71b41..1101905f1e 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java index 6ea9c5a90f..e5574facdb 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java @@ -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); } } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java index 3e28d04324..41ef125f2d 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java index 9f6619c897..ebc7c5eda6 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java @@ -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 allStatusCodesOfErrorEntries = errors.stream() - .map(restconfError -> restconfError.getErrorTag().getStatusCode()) + final Set 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(); } /** diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReader.java index 40c12b2b06..8135e8d90d 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReader.java @@ -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 read(final JsonReader in, final InstanceIdentifierContext path, diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchStatusBodyWriter.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchStatusBodyWriter.java index f000f7c133..d4bb1c0eaf 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchStatusBodyWriter.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchStatusBodyWriter.java @@ -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) { diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java index 59be92ce53..75b8bac83a 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReader.java @@ -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) { diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchStatusBodyWriter.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchStatusBodyWriter.java index 8b279360bf..768041dfdf 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchStatusBodyWriter.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchStatusBodyWriter.java @@ -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 diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java index 69274fcb8a..4e2c5a9aff 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java index 67a85b4586..74e1188858 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java @@ -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); } } } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataStreamServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataStreamServiceImpl.java index 9f90352a40..0862e2eab2 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataStreamServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataStreamServiceImpl.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java index cb6283be6f..76f2b1fc42 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java index 8b34d287cb..4e12ba40a6 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java index c9f6b6b000..31562f11e6 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfTransaction.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfTransaction.java index 522b3b52ca..c5cc67f8c4 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfTransaction.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfTransaction.java @@ -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( diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java index 84702fed22..f346892e03 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureCallbackTx.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureCallbackTx.java index 48163eb83f..5ed9290f1f 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureCallbackTx.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureCallbackTx.java @@ -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); } } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtil.java index 8b15b8bb4d..2449f48a46 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtil.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java index 869fd79d6c..31c787aa8a 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java @@ -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); } } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java index 316a048175..37b360b16e 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/ReadDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/ReadDataTransactionUtil.java index 875438290a..a109731dc9 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/ReadDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/ReadDataTransactionUtil.java @@ -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); } } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java index a0bee88262..71a5333b92 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameter.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameter.java index b5c6cdc6da..20b966e032 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameter.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameter.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java index ae8e1995a2..22c73f62ab 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java @@ -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("/", ""); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java index 275b91a59c..c8647a675d 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializer.java @@ -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() { diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java index bea3dfe82f..5b3e4fdcb5 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierSerializer.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java index 962950a267..af0bb0d0d2 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java @@ -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()); } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapperTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapperTest.java index b92901f1d3..c537e6cc46 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapperTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapperTest.java @@ -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; diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java index 505a4b41cc..9673a4b504 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java @@ -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"))); } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java index 1a478219d8..91a409d763 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java @@ -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); } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java index 3eb8f43f68..54a355e421 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java @@ -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"))); } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java index cc29eadd53..60571fa66a 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java @@ -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)); } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java index 2832e2ebd0..a721718d76 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java @@ -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 > 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 pathParm = new MultivaluedHashMap<>(1); diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java index abc193ba79..2a182e4205 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java @@ -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)); } - } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfSchemaServiceTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfSchemaServiceTest.java index e8eec5df89..33ba82bbb7 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfSchemaServiceTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfSchemaServiceTest.java @@ -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)); } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtilTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtilTest.java index 419853552d..163f834c9a 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtilTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtilTest.java @@ -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()); } } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtilTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtilTest.java index 03e6618953..0b7ed3e2a3 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtilTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtilTest.java @@ -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()); } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/ReadDataTransactionUtilTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/ReadDataTransactionUtilTest.java index be1e939bae..9a7ebc65a6 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/ReadDataTransactionUtilTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/ReadDataTransactionUtilTest.java @@ -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 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()); } /** diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameterTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameterTest.java index e5fd6b7aca..375485ba57 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameterTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserFieldsParameterTest.java @@ -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 diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifierTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifierTest.java index c782be9bb0..1c4f8fec60 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifierTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifierTest.java @@ -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 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()); } /** diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/RestconfValidationTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/RestconfValidationTest.java index efa7f15ad7..df3986521d 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/RestconfValidationTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/RestconfValidationTest.java @@ -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()); } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java index 31217280cd..273b9e63d9 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java @@ -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()); } /**