HONEYCOMB-130: Separate v3po plugin from HC infra
[honeycomb.git] / infra / data-impl / src / test / java / io / fd / honeycomb / v3po / data / impl / DataBrokerTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.v3po.data.impl;
18
19 import static org.junit.Assert.assertTrue;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.verify;
22 import static org.mockito.Mockito.when;
23 import static org.mockito.MockitoAnnotations.initMocks;
24
25 import io.fd.honeycomb.v3po.data.ReadableDataManager;
26 import io.fd.honeycomb.v3po.data.ModifiableDataManager;
27 import io.fd.honeycomb.v3po.data.DataModification;
28 import java.util.Map;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mock;
32 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
33 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
34 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
35 import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
36 import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
37 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
38 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
39 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
40 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
41
42 public class DataBrokerTest {
43
44     @Mock
45     private ReadableDataManager operationalData;
46     @Mock
47     private ModifiableDataManager confiDataTree;
48     @Mock
49     private DataModification configSnapshot;
50     private DataBroker broker;
51
52     @Before
53     public void setUp() {
54         initMocks(this);
55         when(confiDataTree.newModification()).thenReturn(configSnapshot);
56         broker = DataBroker.create(confiDataTree, operationalData);
57     }
58
59     @Test
60     public void testNewReadWriteTransaction() {
61         final DOMDataReadWriteTransaction readWriteTx = broker.newReadWriteTransaction();
62         final YangInstanceIdentifier path = mock(YangInstanceIdentifier.class);
63         readWriteTx.read(LogicalDatastoreType.CONFIGURATION, path);
64
65         // verify that read and write transactions use the same config snapshot
66         verify(configSnapshot).read(path);
67         verify(confiDataTree).newModification();
68     }
69
70     @Test
71     public void testNewWriteOnlyTransaction() {
72         final DOMDataWriteTransaction writeTx = broker.newWriteOnlyTransaction();
73
74         // verify that write transactions use config snapshot
75         verify(confiDataTree).newModification();
76     }
77
78     @Test
79     public void testNewReadOnlyTransaction() {
80         final DOMDataReadOnlyTransaction readTx = broker.newReadOnlyTransaction();
81
82         final YangInstanceIdentifier path = mock(YangInstanceIdentifier.class);
83         readTx.read(LogicalDatastoreType.CONFIGURATION, path);
84
85         // verify that read transactions use config snapshot
86         verify(configSnapshot).read(path);
87     }
88
89     @Test(expected = UnsupportedOperationException.class)
90     public void testRegisterDataChangeListener() {
91         final YangInstanceIdentifier path = mock(YangInstanceIdentifier.class);
92         final DOMDataChangeListener listener = mock(DOMDataChangeListener.class);
93         broker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, path, listener,
94                 AsyncDataBroker.DataChangeScope.BASE);
95     }
96
97     @Test(expected = UnsupportedOperationException.class)
98     public void testCreateTransactionChain() {
99         final TransactionChainListener listener = mock(TransactionChainListener.class);
100         broker.createTransactionChain(listener);
101     }
102
103     @Test
104     public void testGetSupportedExtensions() {
105         final Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> supportedExtensions =
106                 broker.getSupportedExtensions();
107         assertTrue(supportedExtensions.isEmpty());
108     }
109
110
111 }