Bug 6037 - Check if delete request was successful 05/42705/11
authorIvan Hrasko <ihrasko@cisco.com>
Thu, 28 Jul 2016 12:45:09 +0000 (14:45 +0200)
committerIvan Hrasko <ihrasko@cisco.com>
Tue, 2 Aug 2016 14:44:08 +0000 (14:44 +0000)
- solution for old restconf
- checking if data to delete exists, if not return error 404
- use callbacks for transactions

Change-Id: I0f4c11cb3dd9c7fc560a4fee06df0d398c0c4f61
Signed-off-by: Ivan Hrasko <ihrasko@cisco.com>
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java

index 45ce55169111d4b0e8b6704282deb3e849f3e7a8..b915987285d4f20d4e669fa215c9f3306611b3df 100644 (file)
@@ -21,11 +21,11 @@ import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
 import javax.annotation.Nullable;
 import javax.ws.rs.core.Response.Status;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
@@ -326,14 +326,14 @@ public class BrokerFacade {
     public CheckedFuture<Void, TransactionCommitFailedException> commitConfigurationDataDelete(
             final YangInstanceIdentifier path) {
         checkPreconditions();
-        return deleteDataViaTransaction(this.domDataBroker.newWriteOnlyTransaction(), CONFIGURATION, path);
+        return deleteDataViaTransaction(this.domDataBroker.newReadWriteTransaction(), CONFIGURATION, path);
     }
 
     public CheckedFuture<Void, TransactionCommitFailedException> commitConfigurationDataDelete(
             final DOMMountPoint mountPoint, final YangInstanceIdentifier path) {
         final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
         if (domDataBrokerService.isPresent()) {
-            return deleteDataViaTransaction(domDataBrokerService.get().newWriteOnlyTransaction(), CONFIGURATION, path);
+            return deleteDataViaTransaction(domDataBrokerService.get().newReadWriteTransaction(), CONFIGURATION, path);
         }
         final String errMsg = "DOM data broker service isn't available for mount point " + path;
         LOG.warn(errMsg);
@@ -369,21 +369,21 @@ public class BrokerFacade {
             final LogicalDatastoreType datastore, final YangInstanceIdentifier path) {
         LOG.trace("Read {} via Restconf: {}", datastore.name(), path);
         final ListenableFuture<Optional<NormalizedNode<?, ?>>> listenableFuture = transaction.read(datastore, path);
-        final ReadDataResult readData = new ReadDataResult();
+        final ReadDataResult<NormalizedNode<?, ?>> readData = new ReadDataResult<>();
         final CountDownLatch responseWaiter = new CountDownLatch(1);
 
         Futures.addCallback(listenableFuture, new FutureCallback<Optional<NormalizedNode<?, ?>>>() {
 
             @Override
             public void onSuccess(final Optional<NormalizedNode<?, ?>> result) {
-                handlingCallback(null, datastore, path, result, readData);
                 responseWaiter.countDown();
+                handlingCallback(null, datastore, path, result, readData);
             }
 
             @Override
             public void onFailure(final Throwable t) {
-                handlingCallback(t, datastore, path, null, null);
                 responseWaiter.countDown();
+                handlingCallback(t, datastore, path, null, null);
             }
         });
 
@@ -397,22 +397,6 @@ public class BrokerFacade {
         return readData.getResult();
     }
 
-    protected static void handlingCallback(final Throwable t, final LogicalDatastoreType datastore,
-            final YangInstanceIdentifier path, final Optional<NormalizedNode<?, ?>> result,
-            final ReadDataResult readData) {
-        if (t != null) {
-            LOG.warn("Exception by reading {} via Restconf: {}", datastore.name(), path, t);
-            throw new RestconfDocumentedException("Problem to get data from transaction.", t);
-        } else {
-            LOG.debug("Reading result data from transaction.");
-            if (result != null) {
-                if (result.isPresent()) {
-                    readData.setResult(result.get());
-                }
-            }
-        }
-    }
-
     private CheckedFuture<Void, TransactionCommitFailedException> postDataViaTransaction(
             final DOMDataReadWriteTransaction rWTransaction, final LogicalDatastoreType datastore,
             final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
@@ -458,20 +442,90 @@ public class BrokerFacade {
         }
     }
 
-    private void checkItemDoesNotExists(final DOMDataReadWriteTransaction rWTransaction,final LogicalDatastoreType store, final YangInstanceIdentifier path) {
-        final ListenableFuture<Boolean> futureDatastoreData = rWTransaction.exists(store, path);
+    /**
+     * Check if item already exists. Throws error if it does NOT already exist.
+     * @param rWTransaction Current transaction
+     * @param store Used datastore
+     * @param path Path to item to verify its existence
+     */
+    private void checkItemExists(final DOMDataReadWriteTransaction rWTransaction,
+                                 final LogicalDatastoreType store, final YangInstanceIdentifier path) {
+        final CountDownLatch responseWaiter = new CountDownLatch(1);
+        final ReadDataResult<Boolean> readData = new ReadDataResult<>();
+        final CheckedFuture<Boolean, ReadFailedException> future = rWTransaction.exists(store, path);
+
+        Futures.addCallback(future, new FutureCallback<Boolean>() {
+            @Override
+            public void onSuccess(@Nullable final Boolean result) {
+                responseWaiter.countDown();
+                handlingCallback(null, store, path, Optional.of(result), readData);
+            }
+
+            @Override
+            public void onFailure(final Throwable t) {
+                responseWaiter.countDown();
+                handlingCallback(t, store, path, null, null);
+            }
+        });
+
         try {
-            if (futureDatastoreData.get()) {
-                final String errMsg = "Post Configuration via Restconf was not executed because data already exists";
-                LOG.trace("{}:{}", errMsg, path);
-                rWTransaction.cancel();
-                throw new RestconfDocumentedException("Data already exists for path: " + path, ErrorType.PROTOCOL,
-                        ErrorTag.DATA_EXISTS);
+            responseWaiter.await();
+        } catch (final InterruptedException e) {
+            final String msg = "Problem while waiting for response";
+            LOG.warn(msg);
+            throw new RestconfDocumentedException(msg, e);
+        }
+
+        if (!readData.getResult()) {
+            final String errMsg = "Operation via Restconf was not executed because data does not exist";
+            LOG.trace("{}:{}", errMsg, path);
+            rWTransaction.cancel();
+            throw new RestconfDocumentedException("Data does not exist for path: " + path, ErrorType.PROTOCOL,
+                    ErrorTag.DATA_MISSING);
+        }
+    }
+
+    /**
+     * Check if item does NOT already exist. Throws error if it already exists.
+     * @param rWTransaction Current transaction
+     * @param store Used datastore
+     * @param path Path to item to verify its existence
+     */
+    private void checkItemDoesNotExists(final DOMDataReadWriteTransaction rWTransaction,
+                                        final LogicalDatastoreType store, final YangInstanceIdentifier path) {
+        final CountDownLatch responseWaiter = new CountDownLatch(1);
+        final ReadDataResult<Boolean> readData = new ReadDataResult<>();
+        final CheckedFuture<Boolean, ReadFailedException> future = rWTransaction.exists(store, path);
+
+        Futures.addCallback(future, new FutureCallback<Boolean>() {
+            @Override
+            public void onSuccess(@Nullable final Boolean result) {
+                responseWaiter.countDown();
+                handlingCallback(null, store, path, Optional.of(result), readData);
+            }
+
+            @Override
+            public void onFailure(final Throwable t) {
+                responseWaiter.countDown();
+                handlingCallback(t, store, path, null, null);
             }
-        } catch (InterruptedException | ExecutionException e) {
-            LOG.warn("It wasn't possible to get data loaded from datastore at path {}", path, e);
+        });
+
+        try {
+            responseWaiter.await();
+        } catch (final InterruptedException e) {
+            final String msg = "Problem while waiting for response";
+            LOG.warn(msg);
+            throw new RestconfDocumentedException(msg, e);
         }
 
+        if (readData.getResult()) {
+            final String errMsg = "Operation via Restconf was not executed because data already exists";
+            LOG.trace("{}:{}", errMsg, path);
+            rWTransaction.cancel();
+            throw new RestconfDocumentedException("Data already exists for path: " + path, ErrorType.PROTOCOL,
+                    ErrorTag.DATA_EXISTS);
+        }
     }
 
     private CheckedFuture<Void, TransactionCommitFailedException> putDataViaTransaction(
@@ -492,11 +546,12 @@ public class BrokerFacade {
     }
 
     private CheckedFuture<Void, TransactionCommitFailedException> deleteDataViaTransaction(
-            final DOMDataWriteTransaction writeTransaction, final LogicalDatastoreType datastore,
+            final DOMDataReadWriteTransaction readWriteTransaction, final LogicalDatastoreType datastore,
             final YangInstanceIdentifier path) {
         LOG.trace("Delete {} via Restconf: {}", datastore.name(), path);
-        writeTransaction.delete(datastore, path);
-        return writeTransaction.submit();
+        checkItemExists(readWriteTransaction, datastore, path);
+        readWriteTransaction.delete(datastore, path);
+        return readWriteTransaction.submit();
     }
 
     private void deleteDataWithinTransaction(
@@ -524,18 +579,47 @@ public class BrokerFacade {
         this.domDataBroker = domDataBroker;
     }
 
-    private class ReadDataResult {
-        NormalizedNode<?, ?> result = null;
+    /**
+     * Helper class for result of transaction commit callback.
+     * @param <T> Type of result
+     */
+    private final class ReadDataResult<T> {
+        T result = null;
 
-        NormalizedNode<?, ?> getResult() {
+        T getResult() {
             return this.result;
         }
 
-        void setResult(final NormalizedNode<?, ?> result) {
+        void setResult(final T result) {
             this.result = result;
         }
     }
 
+    /**
+     * Set result from transaction commit callback.
+     * @param t Throwable if transaction commit failed
+     * @param datastore Datastore from which data are read
+     * @param path Path from which data are read
+     * @param result Result of read from {@code datastore}
+     * @param readData Result value which will be set
+     * @param <X> Result type
+     */
+    protected final static <X> void handlingCallback(final Throwable t, final LogicalDatastoreType datastore,
+                                                     final YangInstanceIdentifier path, final Optional<X> result,
+                                                     final ReadDataResult<X> readData) {
+        if (t != null) {
+            LOG.warn("Exception by reading {} via Restconf: {}", datastore.name(), path, t);
+            throw new RestconfDocumentedException("Problem to get data from transaction.", t);
+        } else {
+            LOG.debug("Reading result data from transaction.");
+            if (result != null) {
+                if (result.isPresent()) {
+                    readData.setResult(result.get());
+                }
+            }
+        }
+    }
+
     public void registerToListenNotification(final NotificationListenerAdapter listener) {
         checkPreconditions();
 
index 9540fbe48f3704b89a29096eb01fc9a50adb0a9f..be2e5edd6e29978c26e00a5a70227ead01e76469 100644 (file)
@@ -11,10 +11,8 @@ package org.opendaylight.netconf.sal.restconf.impl;
 import com.google.common.base.CharMatcher;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
-import com.google.common.base.Predicates;
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
-import com.google.common.base.Throwables;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -78,7 +76,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.ModifiedNodeDoesNotExistException;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
@@ -930,7 +927,7 @@ public class RestconfImpl implements RestconfService {
         final DOMMountPoint mountPoint = iiWithData.getMountPoint();
         final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
 
-        CheckedFuture<Void, TransactionCommitFailedException> future;
+        final CheckedFuture<Void, TransactionCommitFailedException> future;
         if (mountPoint != null) {
             future = this.broker.commitConfigurationDataDelete(mountPoint, normalizedII);
         } else {
@@ -961,16 +958,12 @@ public class RestconfImpl implements RestconfService {
             LOG.warn(msg);
             throw new RestconfDocumentedException(msg, e);
         }
+
         return Response.status(Status.OK).build();
     }
 
     protected void handlerLoggerDelete(final Throwable t) {
         if (t != null) {
-            final Optional<Throwable> searchedException = Iterables.tryFind(Throwables.getCausalChain(t),
-                    Predicates.instanceOf(ModifiedNodeDoesNotExistException.class));
-            if (searchedException.isPresent()) {
-                throw new RestconfDocumentedException("Data specified for deleting doesn't exist.", ErrorType.APPLICATION, ErrorTag.DATA_MISSING);
-            }
             final String errMsg = "Error while deleting data";
             LOG.info(errMsg, t);
             throw new RestconfDocumentedException(errMsg, t);
index 4308c7ab73f6bec076cc34ff7dad52cf1c86e6b7..670377069872328e06e85e80001698b9a2a51246 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.sal.restconf.impl.test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.inOrder;
@@ -50,6 +51,8 @@ import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.netconf.sal.restconf.impl.PutResult;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
 import org.opendaylight.netconf.sal.streams.listeners.ListenerAdapter;
 import org.opendaylight.netconf.sal.streams.listeners.NotificationListenerAdapter;
 import org.opendaylight.netconf.sal.streams.listeners.Notificator;
@@ -68,46 +71,27 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
  * @author Thomas Pantelis
  */
 public class BrokerFacadeTest {
-
-    @Mock
-    DOMDataBroker domDataBroker;
-
-    @Mock
-    DOMNotificationService domNotification;
-
-    @Mock
-    ConsumerSession context;
-
-    @Mock
-    DOMRpcService mockRpcService;
-
-    @Mock
-    DOMMountPoint mockMountInstance;
-
-    BrokerFacade brokerFacade = BrokerFacade.getInstance();
-
-    NormalizedNode<?, ?> dummyNode = createDummyNode("test:module", "2014-01-09", "interfaces");
-    CheckedFuture<Optional<NormalizedNode<?, ?>>,ReadFailedException> dummyNodeInFuture = wrapDummyNode(this.dummyNode);
-
-    QName qname = TestUtils.buildQName("interfaces","test:module", "2014-01-09");
-
-    SchemaPath type = SchemaPath.create(true, this.qname);
-
-    YangInstanceIdentifier instanceID = YangInstanceIdentifier.builder().node(this.qname).build();
-
-    @Mock
-    DOMDataReadOnlyTransaction rTransaction;
-
-    @Mock
-    DOMDataWriteTransaction wTransaction;
-
-    @Mock
-    DOMDataReadWriteTransaction rwTransaction;
+    @Mock private DOMDataBroker domDataBroker;
+    @Mock private DOMNotificationService domNotification;
+    @Mock private ConsumerSession context;
+    @Mock private DOMRpcService mockRpcService;
+    @Mock private DOMMountPoint mockMountInstance;
+
+    private final BrokerFacade brokerFacade = BrokerFacade.getInstance();
+    private final NormalizedNode<?, ?> dummyNode = createDummyNode("test:module", "2014-01-09", "interfaces");
+    private final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> dummyNodeInFuture =
+            wrapDummyNode(dummyNode);
+    private final QName qname = TestUtils.buildQName("interfaces","test:module", "2014-01-09");
+    private final SchemaPath type = SchemaPath.create(true, qname);
+    private final YangInstanceIdentifier instanceID = YangInstanceIdentifier.builder().node(qname).build();
+
+    @Mock private DOMDataReadOnlyTransaction rTransaction;
+    @Mock private DOMDataWriteTransaction wTransaction;
+    @Mock private DOMDataReadWriteTransaction rwTransaction;
 
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
-        // TODO it is started before every test method
         this.brokerFacade.setDomDataBroker(this.domDataBroker);
         this.brokerFacade.setDomNotificationService(this.domNotification);
         this.brokerFacade.setRpcService(this.mockRpcService);
@@ -119,16 +103,15 @@ public class BrokerFacadeTest {
         ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext("/full-versions/test-module"));
     }
 
-    private CheckedFuture<Optional<NormalizedNode<?, ?>>,ReadFailedException> wrapDummyNode(
+    private CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> wrapDummyNode(
             final NormalizedNode<?, ?> dummyNode) {
-        return  Futures.immediateCheckedFuture(Optional.<NormalizedNode<?, ?>> of(dummyNode));
+        return Futures.immediateCheckedFuture(Optional.<NormalizedNode<?, ?>> of(dummyNode));
     }
 
-    private CheckedFuture<Boolean,ReadFailedException> wrapExistence(final Boolean exists) {
-        return  Futures.immediateCheckedFuture(exists);
+    private CheckedFuture<Boolean, ReadFailedException> wrapExistence(final Boolean exists) {
+        return Futures.immediateCheckedFuture(exists);
     }
 
-
     /**
      * Value of this node shouldn't be important for testing purposes
      */
@@ -170,8 +153,8 @@ public class BrokerFacadeTest {
         final CheckedFuture<DOMRpcResult, DOMRpcException> future = Futures.immediateCheckedFuture(expResult);
         when(this.mockRpcService.invokeRpc(this.type, this.dummyNode)).thenReturn(future);
 
-        final CheckedFuture<DOMRpcResult, DOMRpcException> actualFuture = this.brokerFacade.invokeRpc(
-                this.type, this.dummyNode);
+        final CheckedFuture<DOMRpcResult, DOMRpcException> actualFuture = this.brokerFacade
+                .invokeRpc(this.type, this.dummyNode);
         assertNotNull("Future is null", actualFuture);
         final DOMRpcResult actualResult = actualFuture.get();
         assertSame("invokeRpc", expResult, actualResult);
@@ -191,13 +174,14 @@ public class BrokerFacadeTest {
 
         final Optional<NormalizedNode<?, ?>> optionalMock = mock(Optional.class);
         when(optionalMock.get()).thenReturn(null);
+
         final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture = Futures
                 .immediateCheckedFuture(optionalMock);
-        when(this.rwTransaction.read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class)))
-                .thenReturn(readFuture);
+        when(this.rwTransaction.read(LogicalDatastoreType.CONFIGURATION, this.instanceID)).thenReturn(readFuture);
 
         final PutResult result = this.brokerFacade.commitConfigurationDataPut(mock(SchemaContext.class),
                 this.instanceID, this.dummyNode);
+
         final Future<Void> actualFuture = result.getFutureOfPutData();
 
         assertSame("commitConfigurationDataPut", expFuture, actualFuture);
@@ -213,9 +197,8 @@ public class BrokerFacadeTest {
         @SuppressWarnings("unchecked")
         final CheckedFuture<Void, TransactionCommitFailedException> expFuture = mock(CheckedFuture.class);
 
-        when(this.rwTransaction.exists(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class))).thenReturn(
-            wrapExistence(false));
-
+        when(this.rwTransaction.exists(LogicalDatastoreType.CONFIGURATION, this.instanceID))
+                .thenReturn(wrapExistence(false));
 
         when(this.rwTransaction.submit()).thenReturn(expFuture);
 
@@ -234,55 +217,93 @@ public class BrokerFacadeTest {
     @Test(expected = RestconfDocumentedException.class)
     public void testCommitConfigurationDataPostAlreadyExists() {
         final CheckedFuture<Boolean, ReadFailedException> successFuture = Futures.immediateCheckedFuture(Boolean.TRUE);
-        when(this.rwTransaction.exists(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class))).thenReturn(
-                successFuture);
+        when(this.rwTransaction.exists(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class)))
+                .thenReturn(successFuture);
         try {
             // Schema context is only necessary for ensuring parent structure
-            this.brokerFacade.commitConfigurationDataPost((SchemaContext)null, this.instanceID, this.dummyNode);
+            this.brokerFacade.commitConfigurationDataPost((SchemaContext) null, this.instanceID, this.dummyNode);
         } catch (final RestconfDocumentedException e) {
             assertEquals("getErrorTag", RestconfError.ErrorTag.DATA_EXISTS, e.getErrors().get(0).getErrorTag());
             throw e;
         }
     }
 
+    /**
+     * Positive test of delete operation when data to delete exits. Returned value and order of steps are validated.
+     */
     @Test
-    public void testCommitConfigurationDataDelete() {
+    public void testCommitConfigurationDataDelete() throws Exception {
+        // assume that data to delete exists
+        prepareDataForDelete(true);
+
+        // expected result
         @SuppressWarnings("unchecked")
         final CheckedFuture<Void, TransactionCommitFailedException> expFuture = mock(CheckedFuture.class);
+        when(this.rwTransaction.submit()).thenReturn(expFuture);
 
-        when(this.wTransaction.submit()).thenReturn(expFuture);
-
+        // test
         final CheckedFuture<Void, TransactionCommitFailedException> actualFuture = this.brokerFacade
                 .commitConfigurationDataDelete(this.instanceID);
 
+        // verify result and interactions
         assertSame("commitConfigurationDataDelete", expFuture, actualFuture);
 
-        final InOrder inOrder = inOrder(this.domDataBroker, this.wTransaction);
-        inOrder.verify(this.domDataBroker).newWriteOnlyTransaction();
-        inOrder.verify(this.wTransaction).delete(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class));
-        inOrder.verify(this.wTransaction).submit();
+        // check exists, delete, submit
+        final InOrder inOrder = inOrder(this.domDataBroker, this.rwTransaction);
+        inOrder.verify(this.rwTransaction).exists(LogicalDatastoreType.CONFIGURATION, this.instanceID);
+        inOrder.verify(this.rwTransaction).delete(LogicalDatastoreType.CONFIGURATION, this.instanceID);
+        inOrder.verify(this.rwTransaction).submit();
+    }
+
+    /**
+     * Negative test of delete operation when data to delete does not exist. Error 404 should be returned.
+     */
+    @Test
+    public void testCommitConfigurationDataDeleteNoData() throws Exception {
+        // assume that data to delete does not exist
+        prepareDataForDelete(false);
+
+        // try to delete and expect 404 error
+        try {
+            this.brokerFacade.commitConfigurationDataDelete(this.instanceID);
+            fail("Delete operation should fail due to missing data");
+        } catch (final RestconfDocumentedException e) {
+            assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
+            assertEquals(ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
+            assertEquals(404, e.getErrors().get(0).getErrorTag().getStatusCode());
+        }
+    }
+
+    /**
+     * Prepare conditions to test delete operation. Data to delete exists or does not exist according to value of
+     * {@code assumeDataExists} parameter.
+     * @param assumeDataExists
+     */
+    private void prepareDataForDelete(final boolean assumeDataExists) {
+        when(this.rwTransaction.exists(LogicalDatastoreType.CONFIGURATION, this.instanceID))
+                .thenReturn(Futures.immediateCheckedFuture(new Boolean(assumeDataExists)));
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void testRegisterToListenDataChanges() {
         final ListenerAdapter listener = Notificator.createListener(this.instanceID, "stream");
 
+        @SuppressWarnings("unchecked")
         final ListenerRegistration<DOMDataChangeListener> mockRegistration = mock(ListenerRegistration.class);
 
-        when(this.domDataBroker.registerDataChangeListener(
-                any(LogicalDatastoreType.class), eq(this.instanceID), eq(listener), eq(DataChangeScope.BASE)))
-                .thenReturn(mockRegistration);
+        when(this.domDataBroker.registerDataChangeListener(any(LogicalDatastoreType.class), eq(this.instanceID),
+                eq(listener), eq(DataChangeScope.BASE))).thenReturn(mockRegistration);
 
-        this.brokerFacade.registerToListenDataChanges(LogicalDatastoreType.CONFIGURATION, DataChangeScope.BASE, listener);
+        this.brokerFacade.registerToListenDataChanges(
+                LogicalDatastoreType.CONFIGURATION, DataChangeScope.BASE, listener);
 
-        verify(this.domDataBroker).registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, this.instanceID, listener,
-                DataChangeScope.BASE);
+        verify(this.domDataBroker).registerDataChangeListener(
+                LogicalDatastoreType.CONFIGURATION, this.instanceID, listener, DataChangeScope.BASE);
 
         assertEquals("isListening", true, listener.isListening());
 
-        this.brokerFacade.registerToListenDataChanges(LogicalDatastoreType.CONFIGURATION,
-                DataChangeScope.BASE, listener);
+        this.brokerFacade.registerToListenDataChanges(
+                LogicalDatastoreType.CONFIGURATION, DataChangeScope.BASE, listener);
         verifyNoMoreInteractions(this.domDataBroker);
     }
 
@@ -300,19 +321,19 @@ public class BrokerFacadeTest {
 
         // mock registration
         final ListenerRegistration<NotificationListenerAdapter> registration = mock(ListenerRegistration.class);
-        when(domNotification.registerNotificationListener(listener, listener.getSchemaPath()))
+        when(this.domNotification.registerNotificationListener(listener, listener.getSchemaPath()))
                 .thenReturn(registration);
 
         // test to register listener for the first time
-        brokerFacade.registerToListenNotification(listener);
+        this.brokerFacade.registerToListenNotification(listener);
         assertEquals("Registration was not successful", true, listener.isListening());
 
         // try to register for the second time
-        brokerFacade.registerToListenNotification(listener);
+        this.brokerFacade.registerToListenNotification(listener);
         assertEquals("Registration was not successful", true, listener.isListening());
 
         // registrations should be invoked only once
-        verify(domNotification, times(1)).registerNotificationListener(listener, listener.getSchemaPath());
+        verify(this.domNotification, times(1)).registerNotificationListener(listener, listener.getSchemaPath());
 
         // close and remove test notification listener
         listener.close();