Bug 5947: additional tests for dom-broker and inmemory-datastore #4 87/45787/8
authorPeter Nosal <peter.nosal@pantheon.tech>
Mon, 19 Sep 2016 07:47:14 +0000 (09:47 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 23 Sep 2016 13:02:30 +0000 (13:02 +0000)
Change-Id: I43af7e4dae33e8d7a5fd9c8c4c58afe747f3f7c3
Signed-off-by: Peter Nosal <peter.nosal@pantheon.tech>
dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/AbstractDOMForwardedCompositeTransactionTest.java [new file with mode: 0644]
dom/mdsal-dom-inmemory-datastore/src/test/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStoreFactoryTest.java

diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/AbstractDOMForwardedCompositeTransactionTest.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/AbstractDOMForwardedCompositeTransactionTest.java
new file mode 100644 (file)
index 0000000..0cc86cd
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.dom.broker;
+
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import org.junit.Test;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransaction;
+
+public class AbstractDOMForwardedCompositeTransactionTest {
+
+    private static final DOMStoreTransaction FAIL_TX1 = mock(DOMStoreTransaction.class);
+    private static final DOMStoreTransaction FAIL_TX2 = mock(DOMStoreTransaction.class);
+
+    @Test(expected = IllegalStateException.class)
+    public void closeSubtransactionsTest() throws Exception {
+        doThrow(UnsupportedOperationException.class).when(FAIL_TX1).close();
+        doThrow(UnsupportedOperationException.class).when(FAIL_TX2).close();
+
+        final AbstractDOMForwardedCompositeTransaction domForwardedCompositeTransaction =
+                new DOMForwardedCompositeTransactionTestImpl("testIdent",
+                        ImmutableMap.of("testKey1", FAIL_TX1, "testKey2", FAIL_TX2));
+
+        domForwardedCompositeTransaction.closeSubtransactions();
+    }
+
+    private class DOMForwardedCompositeTransactionTestImpl
+            extends AbstractDOMForwardedCompositeTransaction<String, DOMStoreTransaction> {
+
+        private DOMForwardedCompositeTransactionTestImpl(Object identifier,
+                                                         Map<String, DOMStoreTransaction> backingTxs) {
+            super(identifier, backingTxs);
+        }
+    }
+}
\ No newline at end of file
index e2fc19d11ae80ed488e4ee2b925496997f539ab7..2cfae2198c3a296ba03732d1108cea7a492bd12e 100644 (file)
@@ -10,8 +10,10 @@ package org.opendaylight.mdsal.dom.store.inmemory;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.atLeast;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
@@ -45,6 +47,8 @@ public class InMemoryDOMDataStoreFactoryTest {
         doNothing().when(autoCloseable).close();
         inMemoryDOMDataStore.setCloseable(autoCloseable);
         inMemoryDOMDataStore.close();
-        verify(autoCloseable).close();
+        doThrow(UnsupportedOperationException.class).when(autoCloseable).close();
+        inMemoryDOMDataStore.close();
+        verify(autoCloseable, atLeast(2)).close();
     }
 }
\ No newline at end of file