26b875011c436b49f15e2737b31b6d1a68461bf9
[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 org.junit.Assert;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.mockito.Mock;
14 import org.mockito.Mockito;
15 import org.mockito.MockitoAnnotations;
16 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
17 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20
21 public class ClientBackedWriteTransactionTest extends ClientBackedTransactionTest<ClientBackedWriteTransaction> {
22     private ClientBackedWriteTransaction object;
23
24     @Mock
25     private ClientTransaction delegate;
26     @Mock
27     private NormalizedNode data;
28     @Mock
29     private YangInstanceIdentifier path;
30     @Mock
31     private DOMStoreThreePhaseCommitCohort readyCohort;
32
33     @Before
34     public void setUp() throws Exception {
35         MockitoAnnotations.initMocks(this);
36
37         Mockito.doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
38         Mockito.doReturn(readyCohort).when(delegate).ready();
39
40         object = new ClientBackedWriteTransaction(delegate);
41     }
42
43     @Override
44     ClientBackedWriteTransaction object() throws Exception {
45         return object;
46     }
47
48     @Test
49     public void testWrite() throws Exception {
50         object().write(path, data);
51         Mockito.verify(delegate).write(path, data);
52     }
53
54     @Test
55     public void testMerge() throws Exception {
56         object().merge(path, data);
57         Mockito.verify(delegate).merge(path, data);
58     }
59
60     @Test
61     public void testDelete() throws Exception {
62         object().delete(path);
63         Mockito.verify(delegate).delete(path);
64     }
65
66     @Test
67     public void testReady() throws Exception {
68         final org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort result = object().ready();
69         Assert.assertNotNull(result);
70         Mockito.verify(delegate).ready();
71     }
72 }