Search in sources :

Example 1 with RestconfError

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

the class RestconfErrorTest method testRestConfErrorWithRpcError.

@Test
public void testRestConfErrorWithRpcError() {
    // All fields set
    RpcError rpcError = RpcResultBuilder.newError(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", "mock error-info", new RestconfError(rpcError));
    // All fields set except 'info' - expect error-info set to 'cause'
    rpcError = RpcResultBuilder.newError(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", new Contains("mock cause"), new RestconfError(rpcError));
    // Some fields set - expect error-info set to ErrorSeverity
    rpcError = RpcResultBuilder.newError(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);
    validateRestConfError(null, ErrorType.TRANSPORT, new ErrorTag("not mapped"), null, "<severity>warning</severity>", new RestconfError(rpcError));
    // No fields set - edge case
    rpcError = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, null, null, null, null, null);
    validateRestConfError(null, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, null, "<severity>error</severity>", new RestconfError(rpcError));
}
Also used : ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) RpcError(org.opendaylight.yangtools.yang.common.RpcError) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) Test(org.junit.Test)

Example 2 with RestconfError

use of org.opendaylight.restconf.common.errors.RestconfError 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 3 with RestconfError

use of org.opendaylight.restconf.common.errors.RestconfError 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 4 with RestconfError

use of org.opendaylight.restconf.common.errors.RestconfError 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 5 with RestconfError

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

the class InvokeRpcMethodTest method verifyRestconfDocumentedException.

void verifyRestconfDocumentedException(final RestconfDocumentedException restDocumentedException, final int index, final ErrorType expErrorType, final ErrorTag expErrorTag, final Optional<String> expErrorMsg, final Optional<String> expAppTag) {
    final List<RestconfError> errors = restDocumentedException.getErrors();
    assertTrue("RestconfError not found at index " + index, errors.size() > index);
    RestconfError actual = errors.get(index);
    assertEquals("getErrorType", expErrorType, actual.getErrorType());
    assertEquals("getErrorTag", expErrorTag, actual.getErrorTag());
    assertNotNull("getErrorMessage is null", actual.getErrorMessage());
    if (expErrorMsg.isPresent()) {
        assertEquals("getErrorMessage", expErrorMsg.get(), actual.getErrorMessage());
    }
    if (expAppTag.isPresent()) {
        assertEquals("getErrorAppTag", expAppTag.get(), actual.getErrorAppTag());
    }
}
Also used : RestconfError(org.opendaylight.restconf.common.errors.RestconfError)

Aggregations

RestconfError (org.opendaylight.restconf.common.errors.RestconfError)30 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)19 Test (org.junit.Test)16 InputStream (java.io.InputStream)6 JerseyTest (org.glassfish.jersey.test.JerseyTest)4 ErrorTag (org.opendaylight.yangtools.yang.common.ErrorTag)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Response (javax.ws.rs.core.Response)3 ErrorType (org.opendaylight.yangtools.yang.common.ErrorType)3 MediaType (javax.ws.rs.core.MediaType)2 Status (javax.ws.rs.core.Response.Status)2 Ignore (org.junit.Ignore)2 PatchEntity (org.opendaylight.restconf.common.patch.PatchEntity)2 PatchStatusContext (org.opendaylight.restconf.common.patch.PatchStatusContext)2 PatchStatusEntity (org.opendaylight.restconf.common.patch.PatchStatusEntity)2 RpcError (org.opendaylight.yangtools.yang.common.RpcError)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1