}
final CountDownLatch waiter = new CountDownLatch(1);
+ final ResultOperation result = new ResultOperation();
Futures.addCallback(future, new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
- handlerLoggerDelete(null);
+ LOG.trace("Successfuly delete data.");
waiter.countDown();
}
@Override
public void onFailure(final Throwable t) {
waiter.countDown();
- handlerLoggerDelete(t);
+ result.setFailed(t);
}
});
LOG.warn(msg);
throw new RestconfDocumentedException(msg, e);
}
-
+ if (result.failed() != null) {
+ final Throwable t = result.failed();
+ final String errMsg = "Error while deleting data";
+ LOG.info(errMsg, t);
+ throw new RestconfDocumentedException(errMsg, RestconfError.ErrorType.APPLICATION,
+ RestconfError.ErrorTag.OPERATION_FAILED, t);
+ }
return Response.status(Status.OK).build();
}
- protected void handlerLoggerDelete(final Throwable t) {
- if (t != null) {
- final String errMsg = "Error while deleting data";
- LOG.info(errMsg, t);
- throw new RestconfDocumentedException(errMsg, t);
- } else {
- LOG.trace("Successfuly delete data.");
+ private class ResultOperation {
+ private Throwable t = null;
+
+ public void setFailed(final Throwable t) {
+ this.t = t;
+ }
+
+ public Throwable failed() {
+ return this.t;
}
}
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
response = target(uri).request(MediaType.APPLICATION_XML).delete();
assertEquals(500, response.getStatus());
}
+
+ @Test
+ public void deleteFailTest() throws Exception {
+ final String uri = "/config/test-interface:interfaces";
+ final Exception exception = new TransactionCommitFailedException("failed test");
+ final CheckedFuture future = Futures.immediateFailedCheckedFuture(exception);
+ when(brokerFacade.commitConfigurationDataDelete(any(YangInstanceIdentifier.class))).thenReturn(future);
+ final Response response = target(uri).request(MediaType.APPLICATION_XML).delete();
+ assertEquals(500, response.getStatus());
+ }
}