Merge "Updating features archetype to talk about user-facing features."
[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 static org.mockito.Matchers.anyObject;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.mock;
16 import static org.mockito.Mockito.times;
17 import static org.mockito.Mockito.verify;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
22 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
23 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
24 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransaction;
25 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27
28 public class TransactionChainProxyTest {
29     ActorContext actorContext = mock(ActorContext.class);
30     SchemaContext schemaContext = mock(SchemaContext.class);
31
32     @Before
33     public void setUp() {
34         doReturn(schemaContext).when(actorContext).getSchemaContext();
35     }
36
37     @SuppressWarnings("resource")
38     @Test
39     public void testNewReadOnlyTransaction() throws Exception {
40
41      DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newReadOnlyTransaction();
42          Assert.assertTrue(dst instanceof DOMStoreReadTransaction);
43
44     }
45
46     @SuppressWarnings("resource")
47     @Test
48     public void testNewReadWriteTransaction() throws Exception {
49         DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newReadWriteTransaction();
50         Assert.assertTrue(dst instanceof DOMStoreReadWriteTransaction);
51
52     }
53
54     @SuppressWarnings("resource")
55     @Test
56     public void testNewWriteOnlyTransaction() throws Exception {
57         DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newWriteOnlyTransaction();
58         Assert.assertTrue(dst instanceof DOMStoreWriteTransaction);
59
60     }
61
62     @Test
63     public void testClose() throws Exception {
64         ActorContext context = mock(ActorContext.class);
65
66         new TransactionChainProxy(context).close();
67
68         verify(context, times(1)).broadcast(anyObject());
69     }
70
71     @Test
72     public void testTransactionChainsHaveUniqueId(){
73         TransactionChainProxy one = new TransactionChainProxy(mock(ActorContext.class));
74         TransactionChainProxy two = new TransactionChainProxy(mock(ActorContext.class));
75
76         Assert.assertNotEquals(one.getTransactionChainId(), two.getTransactionChainId());
77     }
78 }