21ef8967aecaa2c3d512cbb48146eec01c7c3798
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / databroker / ClientBackedWriteTransactionTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.databroker;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.verify;
13
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.Mock;
18 import org.mockito.junit.MockitoJUnitRunner;
19 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
20 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
23
24 @RunWith(MockitoJUnitRunner.StrictStubs.class)
25 public class ClientBackedWriteTransactionTest extends ClientBackedTransactionTest<ClientBackedWriteTransaction> {
26     private ClientBackedWriteTransaction object;
27
28     @Mock
29     private ClientTransaction delegate;
30     @Mock
31     private NormalizedNode data;
32     @Mock
33     private YangInstanceIdentifier path;
34     @Mock
35     private DOMStoreThreePhaseCommitCohort readyCohort;
36
37     @Before
38     public void setUp() {
39         doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
40         doReturn(readyCohort).when(delegate).ready();
41
42         object = new ClientBackedWriteTransaction(delegate, null);
43     }
44
45     @Override
46     ClientBackedWriteTransaction object() {
47         return object;
48     }
49
50     @Test
51     public void testWrite() {
52         object().write(path, data);
53         verify(delegate).write(path, data);
54     }
55
56     @Test
57     public void testMerge() {
58         object().merge(path, data);
59         verify(delegate).merge(path, data);
60     }
61
62     @Test
63     public void testDelete() {
64         object().delete(path);
65         verify(delegate).delete(path);
66     }
67
68     @Test
69     public void testReady() {
70         final DOMStoreThreePhaseCommitCohort result = object().ready();
71         assertNotNull(result);
72         verify(delegate).ready();
73     }
74 }