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