5fa60fe2594bdd80df7a83f44923901da52f4300
[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.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.verify;
15 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_IDENTIFIER;
16 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.resetMocks;
17
18 import com.google.common.collect.ImmutableMap;
19 import com.google.common.collect.ImmutableSet;
20 import org.junit.Test;
21 import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeSnapshot;
22
23 public class InMemoryDOMDataTreeShardProducerTest {
24
25     @Test
26     public void basicTest() throws Exception {
27         final InMemoryDOMDataTreeShard inMemoryDOMDataTreeShard = mock(InMemoryDOMDataTreeShard.class);
28         final InmemoryDOMDataTreeShardWriteTransaction inmemoryDOMDataTreeShardWriteTransaction =
29                 mock(InmemoryDOMDataTreeShardWriteTransaction.class);
30         final CursorAwareDataTreeSnapshot snapshot = mock(CursorAwareDataTreeSnapshot.class);
31         doReturn(snapshot).when(inMemoryDOMDataTreeShard).takeSnapshot();
32
33         doReturn(inmemoryDOMDataTreeShardWriteTransaction).when(inMemoryDOMDataTreeShard)
34                 .createTransaction(any(String.class), any(InMemoryDOMDataTreeShardProducer.class),
35                         any(CursorAwareDataTreeSnapshot.class));
36
37         final InMemoryDOMDataTreeShardProducer inMemoryDOMDataTreeShardProducer =
38                 new InMemoryDOMDataTreeShardProducer(inMemoryDOMDataTreeShard,
39                         ImmutableSet.of(DOM_DATA_TREE_IDENTIFIER),
40                         new InMemoryShardDataModificationFactory(DOM_DATA_TREE_IDENTIFIER, ImmutableMap.of(),
41                                 ImmutableMap.of()));
42
43         assertNotNull(inMemoryDOMDataTreeShardProducer.createTransaction());
44         verify(inMemoryDOMDataTreeShard).createTransaction(
45                 any(String.class),
46                 any(InMemoryDOMDataTreeShardProducer.class),
47                 any(CursorAwareDataTreeSnapshot.class));
48         resetMocks();
49     }
50 }