Fix warnings in AbstractDOMShardTreeChangePublisher
[mdsal.git] / dom / mdsal-dom-broker / src / test / java / org / opendaylight / mdsal / dom / broker / ShardedDOMReadTransactionAdapterTest.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
9 package org.opendaylight.mdsal.dom.broker;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import com.google.common.base.Optional;
15 import com.google.common.collect.Maps;
16 import com.google.common.util.concurrent.CheckedFuture;
17 import java.util.Collection;
18 import java.util.Collections;
19 import java.util.Map;
20 import javax.annotation.Nonnull;
21 import org.junit.After;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
25 import org.opendaylight.mdsal.common.api.ReadFailedException;
26 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
27 import org.opendaylight.mdsal.dom.api.DOMDataTreeListener;
28 import org.opendaylight.mdsal.dom.api.DOMDataTreeLoopException;
29 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
30 import org.opendaylight.mdsal.dom.api.DOMDataTreeService;
31 import org.opendaylight.mdsal.dom.broker.util.TestModel;
32 import org.opendaylight.yangtools.concepts.ListenerRegistration;
33 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
34 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
35
36 public class ShardedDOMReadTransactionAdapterTest {
37
38     private ShardedDOMReadTransactionAdapter readTx;
39
40     @Before
41     public void setUp() {
42         readTx = new ShardedDOMReadTransactionAdapter("TEST-TX", new TestTreeService());
43     }
44
45     @Test
46     public void testGetIdentifier() {
47         assertEquals("TEST-TX", readTx.getIdentifier());
48     }
49
50     @Test
51     public void testRead() throws Exception {
52         final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readResult =
53                 readTx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
54         assertTrue(readTx.exists(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH).checkedGet());
55         assertEquals(readResult.checkedGet().get(), TestUtils.TEST_CONTAINER);
56     }
57
58     @After
59     public void close() throws Exception {
60         readTx.close();
61     }
62
63     private static class TestTreeService implements DOMDataTreeService {
64
65         @Nonnull
66         @Override
67         public <T extends DOMDataTreeListener> ListenerRegistration<T>
68             registerListener(@Nonnull final T listener, @Nonnull final Collection<DOMDataTreeIdentifier> subtrees,
69                          final boolean allowRxMerges,
70                          @Nonnull final Collection<DOMDataTreeProducer> producers) throws DOMDataTreeLoopException {
71             final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> subtree = Maps.newHashMap();
72             subtree.put(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH),
73                     TestUtils.TEST_CONTAINER);
74
75             listener.onDataTreeChanged(Collections.singleton(
76                     DataTreeCandidates.fromNormalizedNode(TestModel.TEST_PATH, TestUtils.TEST_CONTAINER)), subtree);
77
78             return new ListenerRegistration<T>() {
79                 @Override
80                 public void close() {
81                     // NOOP
82                 }
83
84                 @Override
85                 public T getInstance() {
86                     return listener;
87                 }
88             };
89         }
90
91         @Nonnull
92         @Override
93         public DOMDataTreeProducer createProducer(@Nonnull final Collection<DOMDataTreeIdentifier> subtrees) {
94             return null;
95         }
96     }
97 }