--- /dev/null
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.common;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableMap;
+import javax.ws.rs.core.Response.Status;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link ErrorTag} mapping to HTTP errors. Aside from the mappings defined by
+ * <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-7">RFC8040 section 7</a>, we also define tags which
+ * map to useful {@link Status} codes.
+ */
+@Beta
+@NonNullByDefault
+public final class ErrorTags {
+ /**
+ * Error reported when the request is valid, but the resource cannot be accessed. This tag typically maps to
+ * {@link Status#SERVICE_UNAVAILABLE}.
+ */
+ // FIXME: redefine as SERVICE_UNAVAILABLE? It would be more obvious
+ public static final ErrorTag RESOURCE_DENIED_TRANSPORT = new ErrorTag("resource-denied-transport");
+
+ private static final Logger LOG = LoggerFactory.getLogger(ErrorTags.class);
+ private static final ImmutableMap<ErrorTag, Status> WELL_KNOWN_ERROR_TAGS = ImmutableMap.<ErrorTag, Status>builder()
+ .put(ErrorTag.IN_USE, Status.CONFLICT)
+ .put(ErrorTag.INVALID_VALUE, Status.BAD_REQUEST)
+ .put(ErrorTag.TOO_BIG, Status.REQUEST_ENTITY_TOO_LARGE)
+ .put(ErrorTag.MISSING_ATTRIBUTE, Status.BAD_REQUEST)
+ .put(ErrorTag.BAD_ATTRIBUTE, Status.BAD_REQUEST)
+ .put(ErrorTag.UNKNOWN_ATTRIBUTE, Status.BAD_REQUEST)
+ .put(ErrorTag.MISSING_ELEMENT, Status.BAD_REQUEST)
+ .put(ErrorTag.BAD_ELEMENT, Status.BAD_REQUEST)
+ .put(ErrorTag.UNKNOWN_ELEMENT, Status.BAD_REQUEST)
+ .put(ErrorTag.UNKNOWN_NAMESPACE, Status.BAD_REQUEST)
+
+ .put(ErrorTag.ACCESS_DENIED, Status.FORBIDDEN)
+ .put(ErrorTag.LOCK_DENIED, Status.CONFLICT)
+ .put(ErrorTag.RESOURCE_DENIED, Status.CONFLICT)
+ .put(ErrorTag.ROLLBACK_FAILED, Status.INTERNAL_SERVER_ERROR)
+ .put(ErrorTag.DATA_EXISTS, Status.CONFLICT)
+ .put(ErrorTag.DATA_MISSING, dataMissingHttpStatus())
+
+ .put(ErrorTag.OPERATION_NOT_SUPPORTED, Status.NOT_IMPLEMENTED)
+ .put(ErrorTag.OPERATION_FAILED, Status.INTERNAL_SERVER_ERROR)
+ .put(ErrorTag.PARTIAL_OPERATION, Status.INTERNAL_SERVER_ERROR)
+ .put(ErrorTag.MALFORMED_MESSAGE, Status.BAD_REQUEST)
+ .put(ErrorTags.RESOURCE_DENIED_TRANSPORT, Status.SERVICE_UNAVAILABLE)
+ .build();
+
+ private ErrorTags() {
+ // Hidden on purpose
+ }
+
+ /**
+ * Return the HTTP {@link Status} corresponding to specified {@link ErrorTag}.
+ *
+ * @param tag Error tag to map
+ * @return HTTP Status
+ * @throws NullPointerException if {@code tag} is null
+ */
+ public static Status statusOf(final ErrorTag tag) {
+ final Status known = WELL_KNOWN_ERROR_TAGS.get(requireNonNull(tag));
+ return known != null ? known : Status.INTERNAL_SERVER_ERROR;
+ }
+
+ private static Status dataMissingHttpStatus() {
+ // Control over the HTTP status reported on "data-missing" conditions. This defaults to disabled,
+ // HTTP status 409 as specified by RFC8040 (and all previous drafts). See the discussion in:
+ // https://www.rfc-editor.org/errata/eid5565
+ // https://mailarchive.ietf.org/arch/msg/netconf/hkVDdHK4xA74NgvXzWP0zObMiyY/
+ final String propName = "org.opendaylight.restconf.eid5565";
+ final String propValue = System.getProperty(propName, "disabled");
+ switch (propValue) {
+ case "enabled":
+ // RFC7231 interpretation: 404 Not Found
+ LOG.info("RESTCONF data-missing condition is reported as HTTP status 404 (Errata 5565)");
+ return Status.NOT_FOUND;
+ case "disabled":
+ break;
+ default:
+ LOG.warn("Unhandled {} value \"{}\", assuming disabled", propName, propValue);
+ }
+
+ // RFC8040 specification: 409 Conflict
+ return Status.CONFLICT;
+ }
+}
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
* @author Thomas Pantelis
*/
public class RestconfDocumentedException extends WebApplicationException {
-
+ private static final Logger LOG = LoggerFactory.getLogger(RestconfDocumentedException.class);
private static final long serialVersionUID = 1L;
private final ImmutableList<RestconfError> errors;
* 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);
}
/**
* 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));
}
/**
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;
}
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;
}
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());
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.
* See also <a href="https://tools.ietf.org/html/draft-bierman-netconf-restconf-02">RESTCONF</a>.
*/
public class RestconfError implements Serializable {
- private static final Logger LOG = LoggerFactory.getLogger(RestconfError.class);
private static final long serialVersionUID = 1L;
- public enum ErrorTag {
- IN_USE("in-use", 409 /* Conflict */),
- INVALID_VALUE("invalid-value", 400 /* Bad Request */),
- TOO_BIG("too-big", 413 /* Request Entity Too Large */),
- MISSING_ATTRIBUTE("missing-attribute", 400 /* Bad Request */),
- BAD_ATTRIBUTE("bad-attribute", 400 /* Bad Request */),
- UNKNOWN_ATTRIBUTE("unknown-attribute", 400 /* Bad Request */),
- MISSING_ELEMENT("missing-element", 400 /* Bad Request */),
- BAD_ELEMENT("bad-element", 400 /* Bad Request */),
- UNKNOWN_ELEMENT("unknown-element", 400 /* Bad Request */),
- UNKNOWN_NAMESPACE("unknown-namespace", 400 /* Bad Request */),
- ACCESS_DENIED("access-denied", 403 /* Forbidden */),
- LOCK_DENIED("lock-denied", 409 /* Conflict */),
- RESOURCE_DENIED("resource-denied", 409 /* Conflict */),
- ROLLBACK_FAILED("rollback-failed", 500 /* INTERNAL_SERVER_ERROR */),
- DATA_EXISTS("data-exists", 409 /* Conflict */),
- DATA_MISSING("data-missing", dataMissingHttpStatus()),
- OPERATION_NOT_SUPPORTED("operation-not-supported", 501 /* Not Implemented */),
- OPERATION_FAILED("operation-failed", 500 /* INTERNAL_SERVER_ERROR */),
- PARTIAL_OPERATION("partial-operation", 500 /* INTERNAL_SERVER_ERROR */),
- MALFORMED_MESSAGE("malformed-message", 400 /* Bad Request */),
- RESOURCE_DENIED_TRANSPORT("resource-denied-transport", 503 /* Service Unavailable */);
-
- private final String tagValue;
- private final int statusCode;
-
- ErrorTag(final String tagValue, final int statusCode) {
- this.tagValue = tagValue;
- this.statusCode = statusCode;
- }
-
- public String getTagValue() {
- return this.tagValue.toLowerCase(Locale.ROOT);
- }
-
- public static ErrorTag valueOfCaseInsensitive(final String value) {
- try {
- return ErrorTag.valueOf(ErrorTag.class, value.toUpperCase(Locale.ROOT).replaceAll("-", "_"));
- } catch (IllegalArgumentException e) {
- return OPERATION_FAILED;
- }
- }
-
- public int getStatusCode() {
- return statusCode;
- }
-
- private static int dataMissingHttpStatus() {
- // Control over the HTTP status reported on "data-missing" conditions. This defaults to disabled,
- // HTTP status 409 as specified by RFC8040 (and all previous drafts). See the discussion in:
- // https://www.rfc-editor.org/errata/eid5565
- // https://mailarchive.ietf.org/arch/msg/netconf/hkVDdHK4xA74NgvXzWP0zObMiyY/
- final String propName = "org.opendaylight.restconf.eid5565";
- final String propValue = System.getProperty(propName, "disabled");
- switch (propValue) {
- case "enabled":
- // RFC7231 interpretation: 404 Not Found
- LOG.info("RESTCONF data-missing condition is reported as HTTP status 404 (Errata 5565)");
- return 404;
- case "disabled":
- break;
- default:
- LOG.warn("Unhandled {} value \"{}\", assuming disabled", propName, propValue);
- }
-
- // RFC8040 specification: 409 Conflict
- return 409;
- }
- }
-
private final ErrorType errorType;
private final ErrorTag errorTag;
private final String errorInfo;
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();
@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 : "")
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;
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;
/**
--- /dev/null
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.common;
+
+import static java.util.Objects.requireNonNull;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+
+@RunWith(Parameterized.class)
+public class ErrorTagsTest {
+ @Parameters(name = "{0} => {1}")
+ public static Iterable<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { "in-use", 409 },
+ { "invalid-value", 400 },
+ { "too-big", 413 },
+ { "missing-attribute", 400 },
+ { "bad-attribute", 400 },
+ { "unknown-attribute", 400 },
+ { "missing-element", 400 },
+ { "bad-element", 400 },
+ { "unknown-element", 400 },
+ { "unknown-namespace", 400 },
+ { "access-denied", 403 },
+ { "lock-denied", 409 },
+ { "resource-denied", 409 },
+ { "rollback-failed", 500 },
+ { "data-exists", 409 },
+ { "data-missing", 409 },
+ { "operation-not-supported", 501 },
+ { "operation-failed", 500 },
+ { "partial-operation", 500 },
+ { "malformed-message", 400 },
+ { "resource-denied-transport", 503 }
+ });
+ }
+
+ private final String tagName;
+ private final int status;
+
+ public ErrorTagsTest(final String tagName, final int status) {
+ this.tagName = requireNonNull(tagName);
+ this.status = status;
+ }
+
+ @Test
+ public void testStatusOf() {
+ assertEquals(status, ErrorTags.statusOf(new ErrorTag(tagName)).getStatusCode());
+ }
+}
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;
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;
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;
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) {
writer.writeEndElement();
writer.writeStartElement("error-tag");
- writer.writeCharacters(restconfError.getErrorTag().getTagValue());
+ writer.writeCharacters(restconfError.getErrorTag().elementBody());
writer.writeEndElement();
// optional node
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;
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;
return Response.status(exception.getStatus()).type(MediaType.TEXT_PLAIN_TYPE).entity(" ").build();
}
- final int status = errors.iterator().next().getErrorTag().getStatusCode();
-
+ final Status status = ErrorTags.statusOf(errors.iterator().next().getErrorTag());
final DataNodeContainer errorsSchemaNode =
(DataNodeContainer) controllerContext.getRestconfModuleErrorsSchemaNode();
-
if (errorsSchemaNode == null) {
return Response.status(status).type(MediaType.TEXT_PLAIN_TYPE).entity(exception.getMessage()).build();
}
final DataSchemaNode errTagSchemaNode = Iterables.getFirst(lsChildDataSchemaNode, null);
checkState(errTagSchemaNode instanceof LeafSchemaNode);
errNodeValues.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) errTagSchemaNode)
- .withValue(error.getErrorTag().getTagValue()).build());
+ .withValue(error.getErrorTag().elementBody()).build());
if (error.getErrorAppTag() != null) {
lsChildDataSchemaNode = ControllerContext.findInstanceDataChildrenByName(
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
import org.opendaylight.restconf.common.util.RestUtil;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchEditOperation;
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.common.util.RestUtil;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchEditOperation;
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.common.patch.PatchStatusEntity;
import org.opendaylight.restconf.common.util.DataChangeScope;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
import org.opendaylight.restconf.common.util.RestUtil;
import org.opendaylight.yangtools.concepts.IllegalArgumentCodec;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
import org.opendaylight.restconf.common.util.SimpleUriInfo;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.OperationFailedException;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
final RpcError[] to = new RpcError[from.size()];
int index = 0;
for (final RestconfError e: from) {
- to[index++] = RpcResultBuilder.newError(e.getErrorType().toLegacy(), e.getErrorTag().getTagValue(),
+ to[index++] = RpcResultBuilder.newError(e.getErrorType().toLegacy(), e.getErrorTag().elementBody(),
e.getErrorMessage());
}
import org.opendaylight.restconf.common.context.WriterParameters;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.errors.RestconfError;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
public final class QueryParametersParser {
final int depth = Integer.parseInt(param);
if (depth < 1) {
throw new RestconfDocumentedException(
- new RestconfError(ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
+ new RestconfError(ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
"Invalid depth parameter: " + depth, null,
"The depth parameter must be an integer > 1 or \"unbounded\""));
}
wpBuilder.setDepth(depth);
} catch (final NumberFormatException e) {
throw new RestconfDocumentedException(e, new RestconfError(
- ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
+ ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
"Invalid depth parameter: " + e.getMessage(), null,
"The depth parameter must be an integer > 1 or \"unbounded\""));
}
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;
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;
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);
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);
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());
}
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;
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);
}
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);
}
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());
}
/**
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());
}
/**
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);
}
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);
}
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);
}
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;
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 {
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());
}
/**
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());
}
/**
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;
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());
}
}
}
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;
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());
}
}
}
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;
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 {
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);
}
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());
}
/**
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());
}
/**
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);
}
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);
}
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);
}
}
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;
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 {
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));
}
/**
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());
}
/**
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());
}
/**
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);
}
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);
}
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));
}
/**
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));
}
}
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;
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;
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;
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;
public void test503() throws Exception {
final RpcError error = RpcResultBuilder.newError(
RpcError.ErrorType.TRANSPORT,
- ErrorTag.RESOURCE_DENIED.getTagValue(),
+ ErrorTag.RESOURCE_DENIED.elementBody(),
"Master is down. Please try again.");
doReturn(immediateFailedFluentFuture(new ReadFailedException("Read from transaction failed", error)))
.when(readTransaction).read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class));
- try {
- brokerFacade.readConfigurationData(this.instanceID, "explicit");
- fail("This test should fail.");
- } catch (final RestconfDocumentedException e) {
- assertEquals("getErrorTag", ErrorTag.RESOURCE_DENIED_TRANSPORT, e.getErrors().get(0).getErrorTag());
- assertEquals("getErrorType", ErrorType.TRANSPORT, e.getErrors().get(0).getErrorType());
- assertEquals("getErrorMessage", "Master is down. Please try again.",
- e.getErrors().get(0).getErrorMessage());
- }
+
+ final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> brokerFacade.readConfigurationData(this.instanceID, "explicit"));
+ final List<RestconfError> errors = ex.getErrors();
+ assertEquals(1, errors.size());
+ assertEquals("getErrorTag", ErrorTags.RESOURCE_DENIED_TRANSPORT, errors.get(0).getErrorTag());
+ assertEquals("getErrorType", ErrorType.TRANSPORT,errors.get(0).getErrorType());
+ assertEquals("getErrorMessage", "Master is down. Please try again.", errors.get(0).getErrorMessage());
}
@Test
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;
}
}
prepareDataForDelete(false);
// try to delete and expect DATA_MISSING error
- try {
- this.brokerFacade.commitConfigurationDataDelete(this.instanceID);
- fail("Delete operation should fail due to missing data");
- } catch (final RestconfDocumentedException e) {
- assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals(ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
- }
+ final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> brokerFacade.commitConfigurationDataDelete(this.instanceID));
+ final List<RestconfError> errors = ex.getErrors();
+ assertEquals(1, errors.size());
+ assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
+ assertEquals(ErrorTag.DATA_MISSING, errors.get(0).getErrorTag());
}
/**
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;
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"));
}
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;
}
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");
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");
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;
}
}
- @Test
- public void testErrorTagValueOf() {
- assertEquals(ErrorTag.IN_USE, ErrorTag.valueOfCaseInsensitive(ErrorTag.IN_USE.getTagValue()));
- }
-
- @Test
- public void testErrorTagValueOfIsLowercase() {
- assertEquals("in-use", ErrorTag.IN_USE.getTagValue());
- }
-
- @Test
- public void testErrorTagStatusCodes() {
- Map<String, Integer> lookUpMap = new HashMap<>();
-
- lookUpMap.put("in-use", 409);
- lookUpMap.put("invalid-value", 400);
- lookUpMap.put("too-big", 413);
- lookUpMap.put("missing-attribute", 400);
- lookUpMap.put("bad-attribute", 400);
- lookUpMap.put("unknown-attribute", 400);
- lookUpMap.put("missing-element", 400);
- lookUpMap.put("bad-element", 400);
- lookUpMap.put("unknown-element", 400);
- lookUpMap.put("unknown-namespace", 400);
- lookUpMap.put("access-denied", 403);
- lookUpMap.put("lock-denied", 409);
- lookUpMap.put("resource-denied", 409);
- lookUpMap.put("rollback-failed", 500);
- lookUpMap.put("data-exists", 409);
- lookUpMap.put("data-missing", 409);
- lookUpMap.put("operation-not-supported", 501);
- lookUpMap.put("operation-failed", 500);
- lookUpMap.put("partial-operation", 500);
- lookUpMap.put("malformed-message", 400);
- lookUpMap.put("resource-denied-transport", 503);
-
- for (ErrorTag tag : ErrorTag.values()) {
- Integer expectedStatusCode = lookUpMap.get(tag.getTagValue());
- assertNotNull("Failed to find " + tag.getTagValue(), expectedStatusCode);
- assertEquals("Status Code does not match", expectedStatusCode, Integer.valueOf(tag.getStatusCode()));
- }
- }
-
@Test
public void testRestConfDocumentedException_NoCause() {
String expectedMessage = "Message";
// 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",
// 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",
// Some fields set - expect error-info set to ErrorSeverity
rpcError = RpcResultBuilder.newError(
- RpcError.ErrorType.RPC, ErrorTag.ACCESS_DENIED.getTagValue(), null, null, null, null);
+ RpcError.ErrorType.RPC, ErrorTag.ACCESS_DENIED.elementBody(), null, null, null, null);
validateRestConfError(null, ErrorType.RPC, ErrorTag.ACCESS_DENIED, null, "<severity>error</severity>",
new RestconfError(rpcError));
- // 'tag' field not mapped to ErrorTag - expect error-tag set to
- // OPERATION_FAILED
- rpcError = RpcResultBuilder.newWarning(
- RpcError.ErrorType.TRANSPORT, "not mapped", null, null, null, null);
+ // 'tag' field not mapped to ErrorTag - expect error-tag set to OPERATION_FAILED
+ rpcError = RpcResultBuilder.newWarning(RpcError.ErrorType.TRANSPORT, "not mapped", null, null, null, null);
- validateRestConfError(null, ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED, null,
+ validateRestConfError(null, ErrorType.TRANSPORT, new ErrorTag("not mapped"), null,
"<severity>warning</severity>", new RestconfError(rpcError));
// No fields set - edge case
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;
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;
RestconfDocumentedException.throwIfYangError(exception);
throw new RestconfDocumentedException("Error parsing input: " + exception.getMessage(), ErrorType.PROTOCOL,
- ErrorTag.MALFORMED_MESSAGE, exception);
+ ErrorTag.MALFORMED_MESSAGE, exception);
}
}
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;
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;
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) {
return DEFAULT_STATUS_CODE;
}
- final Set<Integer> allStatusCodesOfErrorEntries = errors.stream()
- .map(restconfError -> restconfError.getErrorTag().getStatusCode())
+ final Set<Status> allStatusCodesOfErrorEntries = errors.stream()
+ .map(restconfError -> ErrorTags.statusOf(restconfError.getErrorTag()))
// we would like to preserve iteration order in collected entries - hence usage of LinkedHashSet
.collect(Collectors.toCollection(LinkedHashSet::new));
// choosing of the first status code from appended errors, if there are different status codes in error
+ "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();
}
/**
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;
RestconfDocumentedException.throwIfYangError(exception);
throw new RestconfDocumentedException("Error parsing json input: " + exception.getMessage(), ErrorType.PROTOCOL,
- ErrorTag.MALFORMED_MESSAGE, exception);
+ ErrorTag.MALFORMED_MESSAGE, exception);
}
private List<PatchEntity> read(final JsonReader in, final InstanceIdentifierContext<?> path,
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) {
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;
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.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;
@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) {
writer.writeEndElement();
writer.writeStartElement("error-tag");
- writer.writeCharacters(restconfError.getErrorTag().getTagValue());
+ writer.writeCharacters(restconfError.getErrorTag().elementBody());
writer.writeEndElement();
// optional node
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;
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;
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;
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)
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;
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;
break;
default:
throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey(),
- ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
+ ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
}
}
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);
}
}
}
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;
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;
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;
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;
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;
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;
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(
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;
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);
}
}
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;
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;
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);
}
}
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;
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;
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)"));
}
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 {
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()));
}
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)"));
}
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)"));
}
}
.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);
}
}
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;
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;
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;
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("/", "");
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;
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() {
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;
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;
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;
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;
*/
@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);
@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());
}
}
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;
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 {
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")));
}
/**
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")));
}
/**
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());
}
/**
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());
}
/**
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")));
}
/**
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")));
}
/**
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")));
}
/**
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")));
}
}
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;
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 {
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);
}
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);
}
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());
}
/**
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());
}
/**
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);
}
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);
}
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);
}
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);
}
}
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 {
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);
}
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());
}
/**
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.
*/
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")));
}
/**
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")));
}
/**
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")));
}
/**
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")));
}
}
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 {
@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")));
}
/**
*/
@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());
}
/**
*/
@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")));
}
/**
*/
@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")));
}
/**
*/
@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));
}
/**
*/
@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));
}
}
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;
}
protected static <T extends AbstractIdentifierAwareJaxRsProvider<?>> void mockBodyReader(
- final String identifier, final T normalizedNodeProvider,
- final boolean isPost) throws NoSuchFieldException,
- SecurityException, IllegalArgumentException, IllegalAccessException {
+ final String identifier, final T normalizedNodeProvider, final boolean isPost) {
final UriInfo uriInfoMock = mock(UriInfo.class);
final MultivaluedMap<String, String> pathParm = new MultivaluedHashMap<>(1);
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;
} 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());
}
}
assertRangeViolation(() -> xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream));
}
-
}
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;
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;
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.
*/
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);
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);
// 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);
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);
when(this.mockContextHandler.get()).thenReturn(null);
// make test
- assertThrows(NullPointerException.class, () -> this.schemaService.getSchema(TEST_MODULE));
+ assertThrows(NullPointerException.class, () -> schemaService.getSchema(TEST_MODULE));
}
/**
// make test
assertThrows(NullPointerException.class,
- () -> this.schemaService.getSchema(MOUNT_POINT + TEST_MODULE_BEHIND_MOUNT_POINT));
+ () -> schemaService.getSchema(MOUNT_POINT + TEST_MODULE_BEHIND_MOUNT_POINT));
}
/**
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());
}
/**
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());
}
/**
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());
}
/**
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());
}
/**
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());
}
/**
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());
}
/**
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());
}
/**
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());
}
/**
// 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));
}
}
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;
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());
}
}
}
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;
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());
}
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());
}
}
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;
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;
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());
}
/**
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());
}
/**
"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());
}
/**
final MultivaluedHashMap<String, String> parameters = new MultivaluedHashMap<>();
// inserted value is too high
- parameters.put(
- "depth", List.of(String.valueOf(RestconfDataServiceConstant.ReadData.MAX_DEPTH + 1)));
+ parameters.put("depth", List.of(String.valueOf(RestconfDataServiceConstant.ReadData.MAX_DEPTH + 1)));
when(uriInfo.getQueryParameters()).thenReturn(parameters);
- try {
- ReadDataTransactionUtil.parseUriParameters(context, uriInfo);
- fail("Test expected to fail due to not allowed parameter value");
- } catch (final RestconfDocumentedException e) {
- // Bad request
- assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
- assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ReadDataTransactionUtil.parseUriParameters(context, uriInfo));
+ // Bad request
+ assertEquals("Error type is not correct", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+ assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, ex.getErrors().get(0).getErrorTag());
}
/**
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());
}
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());
}
/**
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;
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;
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));
}
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)));
}
/**
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)));
}
/**
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)));
}
/**
*/
@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());
}
/**
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());
}
/**
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());
}
/**
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());
}
/**
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
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;
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;
RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
() -> ParserIdentifier.toInstanceIdentifier("/yang-ext:mount", SCHEMA_CONTEXT,
Optional.of(this.mountPointService)));
- assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
- assertEquals("Not expected error tag", ErrorTag.RESOURCE_DENIED_TRANSPORT, ex.getErrors().get(0).getErrorTag());
+ final List<RestconfError> errors = ex.getErrors();
+ assertEquals(1, errors.size());
+ assertEquals("Not expected error type", ErrorType.PROTOCOL, errors.get(0).getErrorType());
+ assertEquals("Not expected error tag", ErrorTags.RESOURCE_DENIED_TRANSPORT, errors.get(0).getErrorTag());
}
/**
() -> 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());
}
/**
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());
}
/**
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());
}
/**
() -> 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());
}
/**
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());
}
/**
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());
}
/**
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());
}
/**
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());
}
/**
() -> 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());
}
/**
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());
}
/**
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;
() -> 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());
}
/**
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());
}
/**
() -> 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());
}
/**
() -> 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());
}
/**
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());
}
/**
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());
}
}
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;
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());
}
() -> 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());
}
() -> 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());
}
/**
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());
}
/**