BUG 1712 - Distributed DataStore does not work properly with Transaction Chains
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / TransactionChainProxyTest.java
1 /*
2  *
3  *  Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  *  This program and the accompanying materials are made available under the
6  *  terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  and is available at http://www.eclipse.org/legal/epl-v10.html
8  *
9  */
10
11 package org.opendaylight.controller.cluster.datastore;
12
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
19 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransaction;
20 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22
23 import static org.mockito.Matchers.anyObject;
24 import static org.mockito.Mockito.doReturn;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28
29 public class TransactionChainProxyTest {
30     ActorContext actorContext = mock(ActorContext.class);
31     SchemaContext schemaContext = mock(SchemaContext.class);
32
33     @Before
34     public void setUp() {
35         doReturn(schemaContext).when(actorContext).getSchemaContext();
36     }
37
38     @SuppressWarnings("resource")
39     @Test
40     public void testNewReadOnlyTransaction() throws Exception {
41
42      DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newReadOnlyTransaction();
43          Assert.assertTrue(dst instanceof DOMStoreReadTransaction);
44
45     }
46
47     @SuppressWarnings("resource")
48     @Test
49     public void testNewReadWriteTransaction() throws Exception {
50         DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newReadWriteTransaction();
51         Assert.assertTrue(dst instanceof DOMStoreReadWriteTransaction);
52
53     }
54
55     @SuppressWarnings("resource")
56     @Test
57     public void testNewWriteOnlyTransaction() throws Exception {
58         DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newWriteOnlyTransaction();
59         Assert.assertTrue(dst instanceof DOMStoreWriteTransaction);
60
61     }
62
63     @Test
64     public void testClose() throws Exception {
65         ActorContext context = mock(ActorContext.class);
66
67         new TransactionChainProxy(context).close();
68
69         verify(context, times(1)).broadcast(anyObject());
70     }
71 }