2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.dom.store.inmemory;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.Matchers.any;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.mock;
16 import static org.opendaylight.controller.md.sal.dom.store.impl.TestModel.createTestContext;
17 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_IDENTIFIER;
18 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_SHARD_PRODUCER;
19 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.resetMocks;
21 import com.google.common.collect.ImmutableList;
22 import com.google.common.util.concurrent.MoreExecutors;
23 import java.util.Collection;
24 import org.junit.After;
25 import org.junit.Test;
26 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
27 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
28 import org.opendaylight.yangtools.yang.common.QName;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
31 public class InMemoryDOMDataTreeShardTest {
34 public void basicTest() throws Exception {
35 InMemoryDOMDataTreeShard inMemoryDOMDataTreeShard =
36 InMemoryDOMDataTreeShard.create(DOM_DATA_TREE_IDENTIFIER,
37 MoreExecutors.newDirectExecutorService(), 1);
39 final DOMDataTreeIdentifier domDataTreeIdentifier =
40 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
41 YangInstanceIdentifier.of(QName.create("Test")));
43 WriteableDOMDataTreeShard domDataTreeShard = mock(WriteableDOMDataTreeShard.class);
44 doReturn("testTreeShard").when(domDataTreeShard).toString();
45 doReturn(DOM_DATA_TREE_SHARD_PRODUCER).when(domDataTreeShard).createProducer(any());
47 assertFalse(inMemoryDOMDataTreeShard.getChildShards().containsValue(domDataTreeShard));
48 inMemoryDOMDataTreeShard.onChildAttached(DOM_DATA_TREE_IDENTIFIER, domDataTreeShard);
49 assertTrue(inMemoryDOMDataTreeShard.getChildShards().containsValue(domDataTreeShard));
50 inMemoryDOMDataTreeShard.onChildAttached(domDataTreeIdentifier, domDataTreeShard);
52 Collection<DOMDataTreeIdentifier> prefixes = ImmutableList.of(DOM_DATA_TREE_IDENTIFIER);
53 assertEquals(prefixes.toString(), inMemoryDOMDataTreeShard.createProducer(prefixes).getPrefixes().toString());
55 inMemoryDOMDataTreeShard.onGlobalContextUpdated(createTestContext());
56 inMemoryDOMDataTreeShard.createTransaction(prefixes);
58 inMemoryDOMDataTreeShard.onChildDetached(DOM_DATA_TREE_IDENTIFIER, domDataTreeShard);
59 assertFalse(inMemoryDOMDataTreeShard.getChildShards().containsKey(DOM_DATA_TREE_IDENTIFIER));
62 @Test(expected = UnsupportedOperationException.class)
63 public void createTransactionWithException() throws Exception {
64 final DOMDataTreeIdentifier domDataTreeIdentifier =
65 new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
67 final InMemoryDOMDataTreeShard inMemoryDOMDataTreeShard =
68 InMemoryDOMDataTreeShard.create(domDataTreeIdentifier,
69 MoreExecutors.newDirectExecutorService(), 1);
71 final InmemoryDOMDataTreeShardWriteTransaction inmemoryDOMDataTreeShardWriteTransaction =
72 mock(InmemoryDOMDataTreeShardWriteTransaction.class);
74 inMemoryDOMDataTreeShard.createTransaction(inmemoryDOMDataTreeShardWriteTransaction);