Deprecate all MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / test / java / org / opendaylight / controller / md / sal / dom / broker / impl / DOMForwardedWriteTransactionTest.java
1 /*
2  *
3  * This program and the accompanying materials are made available under the
4  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/epl-v10.html
6  */
7 package org.opendaylight.controller.md.sal.dom.broker.impl;
8
9 import static org.junit.Assert.assertTrue;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.doThrow;
13
14 import com.google.common.util.concurrent.CheckedFuture;
15 import java.util.Collections;
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
22 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
23 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
24
25 @Deprecated
26 public class DOMForwardedWriteTransactionTest {
27
28     @Mock
29     private AbstractDOMForwardedTransactionFactory abstractDOMForwardedTransactionFactory;
30
31     @Mock
32     private DOMStoreWriteTransaction domStoreWriteTransaction;
33
34     @Before
35     public void setup() {
36         MockitoAnnotations.initMocks(this);
37     }
38
39     @Test
40     public void readyRuntimeExceptionAndCancel() {
41         RuntimeException thrown = new RuntimeException();
42         doThrow(thrown).when(domStoreWriteTransaction).ready();
43         DOMForwardedWriteTransaction<DOMStoreWriteTransaction> domForwardedWriteTransaction =
44                 new DOMForwardedWriteTransaction<>(
45                         new Object(),
46                         Collections.singletonMap(LogicalDatastoreType.OPERATIONAL, domStoreWriteTransaction),
47                         abstractDOMForwardedTransactionFactory);
48         CheckedFuture<Void, TransactionCommitFailedException> submitFuture = domForwardedWriteTransaction.submit();
49         try {
50             submitFuture.checkedGet();
51             Assert.fail("TransactionCommitFailedException expected");
52         } catch (TransactionCommitFailedException e) {
53             assertTrue(e.getCause() == thrown);
54             domForwardedWriteTransaction.cancel();
55         }
56     }
57
58     @Test
59     public void submitRuntimeExceptionAndCancel() {
60         RuntimeException thrown = new RuntimeException();
61         doReturn(null).when(domStoreWriteTransaction).ready();
62         doThrow(thrown).when(abstractDOMForwardedTransactionFactory).commit(any(), any(), any());
63         DOMForwardedWriteTransaction<DOMStoreWriteTransaction> domForwardedWriteTransaction =
64                 new DOMForwardedWriteTransaction<>(
65                     new Object(),
66                     Collections.singletonMap(LogicalDatastoreType.OPERATIONAL, domStoreWriteTransaction),
67                     abstractDOMForwardedTransactionFactory);
68         CheckedFuture<Void, TransactionCommitFailedException> submitFuture = domForwardedWriteTransaction.submit();
69         try {
70             submitFuture.checkedGet();
71             Assert.fail("TransactionCommitFailedException expected");
72         } catch (TransactionCommitFailedException e) {
73             assertTrue(e.getCause() == thrown);
74             domForwardedWriteTransaction.cancel();
75         }
76     }
77 }