Fix InMemory shard transaction chaining.
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / test / java / org / opendaylight / mdsal / dom / store / inmemory / InMemoryDOMDataTreeShardProducerTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.mdsal.dom.store.inmemory;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Matchers.anyCollectionOf;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.verify;
16 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_IDENTIFIER;
17 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.resetMocks;
18
19 import com.google.common.collect.ImmutableSet;
20 import org.junit.Test;
21 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeSnapshot;
23
24 public class InMemoryDOMDataTreeShardProducerTest {
25
26     @Test
27     public void basicTest() throws Exception {
28         final InMemoryDOMDataTreeShard inMemoryDOMDataTreeShard = mock(InMemoryDOMDataTreeShard.class);
29         final InmemoryDOMDataTreeShardWriteTransaction inmemoryDOMDataTreeShardWriteTransaction =
30                 mock(InmemoryDOMDataTreeShardWriteTransaction.class);
31         final CursorAwareDataTreeSnapshot snapshot = mock(CursorAwareDataTreeSnapshot.class);
32         doReturn(snapshot).when(inMemoryDOMDataTreeShard).takeSnapshot();
33
34         doReturn(inmemoryDOMDataTreeShardWriteTransaction).when(inMemoryDOMDataTreeShard)
35                 .createTransaction(any(String.class), any(InMemoryDOMDataTreeShardProducer.class),
36                         anyCollectionOf((DOMDataTreeIdentifier.class)), any(CursorAwareDataTreeSnapshot.class));
37
38         final InMemoryDOMDataTreeShardProducer inMemoryDOMDataTreeShardProducer =
39                 new InMemoryDOMDataTreeShardProducer(inMemoryDOMDataTreeShard,
40                         ImmutableSet.of(DOM_DATA_TREE_IDENTIFIER));
41
42         assertNotNull(inMemoryDOMDataTreeShardProducer.createTransaction());
43         verify(inMemoryDOMDataTreeShard).createTransaction(
44                 any(String.class),
45                 any(InMemoryDOMDataTreeShardProducer.class),
46                 anyCollectionOf(DOMDataTreeIdentifier.class),
47                 any(CursorAwareDataTreeSnapshot.class));
48         resetMocks();
49     }
50 }