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));
}
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));
}
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));
}
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);
}
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());
}
}
Aggregations