Search in sources :

Example 1 with RestconfDocumentedException

use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.

the class RestconfDocumentedExceptionMapperTest method testToJsonResponseWithErrorInfo.

@Test
public void testToJsonResponseWithErrorInfo() throws Exception {
    final String errorInfo = "<address>1.2.3.4</address> <session-id>123</session-id>";
    testJsonResponse(new RestconfDocumentedException(new RestconfError(ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", errorInfo)), Status.BAD_REQUEST, ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", new SimpleErrorInfoVerifier(errorInfo));
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 2 with RestconfDocumentedException

use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.

the class RestconfDocumentedExceptionMapperTest method testToXMLResponseWithErrorInfo.

@Test
public void testToXMLResponseWithErrorInfo() throws Exception {
    final String errorInfo = "<address>1.2.3.4</address> <session-id>123</session-id>";
    testXMLResponse(new RestconfDocumentedException(new RestconfError(ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", errorInfo)), Status.BAD_REQUEST, ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", new SimpleErrorInfoVerifier(errorInfo));
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 3 with RestconfDocumentedException

use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.

the class RestconfDocumentedExceptionMapperTest method testToXMLResponseWithMultipleErrors.

@Test
// FIXME : find why it return error-type as RPC no APPLICATION
@Ignore
public void testToXMLResponseWithMultipleErrors() throws Exception {
    final List<RestconfError> errorList = Arrays.asList(new RestconfError(ErrorType.APPLICATION, ErrorTag.LOCK_DENIED, "mock error1"), new RestconfError(ErrorType.RPC, ErrorTag.ROLLBACK_FAILED, "mock error2"));
    stageMockEx(new RestconfDocumentedException("mock", null, errorList));
    final Response resp = target("/operational/foo").request(MediaType.APPLICATION_XML).get();
    final InputStream stream = verifyResponse(resp, MediaType.APPLICATION_XML, Status.CONFLICT);
    final Document doc = parseXMLDocument(stream);
    final NodeList children = getXMLErrorList(doc, 2);
    verifyXMLErrorNode(children.item(0), ErrorType.APPLICATION, ErrorTag.LOCK_DENIED, "mock error1", null, null);
    verifyXMLErrorNode(children.item(1), ErrorType.RPC, ErrorTag.ROLLBACK_FAILED, "mock error2", null, null);
}
Also used : Response(javax.ws.rs.core.Response) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) Document(org.w3c.dom.Document) Ignore(org.junit.Ignore) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 4 with RestconfDocumentedException

use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.

the class InvokeRpcMethodTest method testInvokeRpcWithNoPayloadRpc_FailWithRpcError.

@Test
public void testInvokeRpcWithNoPayloadRpc_FailWithRpcError() {
    final List<RpcError> rpcErrors = Arrays.asList(RpcResultBuilder.newError(RpcError.ErrorType.TRANSPORT, "bogusTag", "foo"), RpcResultBuilder.newWarning(RpcError.ErrorType.RPC, "in-use", "bar", "app-tag", null, null));
    final DOMRpcResult result = new DefaultDOMRpcResult(rpcErrors);
    final QName path = QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast");
    doReturn(immediateFluentFuture(result)).when(brokerFacade).invokeRpc(eq(path), any());
    final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> this.restconfImpl.invokeRpc("toaster:cancel-toast", null, uriInfo));
    // 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"));
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) RpcError(org.opendaylight.yangtools.yang.common.RpcError) Test(org.junit.Test)

Example 5 with RestconfDocumentedException

use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.

the class InvokeRpcMethodTest method testInvokeRpcMethodWithBadMethodName.

@Test
public void testInvokeRpcMethodWithBadMethodName() {
    final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> this.restconfImpl.invokeRpc("toaster:bad-method", null, uriInfo));
    verifyRestconfDocumentedException(ex, 0, ErrorType.RPC, ErrorTag.UNKNOWN_ELEMENT, Optional.empty(), Optional.empty());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) Test(org.junit.Test)

Aggregations

RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)136 Test (org.junit.Test)65 InputStream (java.io.InputStream)30 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)20 RestconfError (org.opendaylight.restconf.common.errors.RestconfError)20 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)19 QName (org.opendaylight.yangtools.yang.common.QName)17 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)17 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)16 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)14 List (java.util.List)13 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)13 ArrayList (java.util.ArrayList)12 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)11 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)9 IOException (java.io.IOException)8 ExecutionException (java.util.concurrent.ExecutionException)8 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)8 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)8