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
9 package org.opendaylight.openflowplugin.applications.frsync.impl;
11 import java.util.Collections;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.Matchers;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.runners.MockitoJUnitRunner;
21 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
22 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
23 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
24 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
25 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
26 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
27 import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
28 import org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeCachedDao;
29 import org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeDao;
30 import org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeOdlDao;
31 import org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeSnapshotDao;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import com.google.common.base.Optional;
40 import com.google.common.util.concurrent.Futures;
43 * Test for {@link SimplifiedConfigListener}.
45 @SuppressWarnings("deprecation")
46 @RunWith(MockitoJUnitRunner.class)
47 public class SimplifiedConfigListenerTest {
50 private SyncReactor reactor;
52 private DataBroker db;
54 private DataTreeModification<FlowCapableNode> dataTreeModification;
56 private ReadOnlyTransaction roTx;
58 private DataObjectModification<FlowCapableNode> configModification;
60 private InstanceIdentifier<FlowCapableNode> nodePath;
61 private SimplifiedConfigListener nodeListenerConfig;
64 public void setUp() throws Exception {
65 final FlowCapableNodeSnapshotDao configSnaphot = new FlowCapableNodeSnapshotDao();
66 final FlowCapableNodeSnapshotDao operationalSnaphot = new FlowCapableNodeSnapshotDao();
67 final FlowCapableNodeDao operationalDao = new FlowCapableNodeCachedDao(operationalSnaphot,
68 new FlowCapableNodeOdlDao(db, LogicalDatastoreType.OPERATIONAL));
71 nodeListenerConfig = new SimplifiedConfigListener(reactor, configSnaphot, operationalDao);
72 nodePath = InstanceIdentifier.create(Nodes.class)
73 .child(Node.class, new NodeKey(new NodeId("testNode")))
74 .augmentation(FlowCapableNode.class);
78 public void testDSLogicalType() throws Exception {
79 Assert.assertEquals(LogicalDatastoreType.CONFIGURATION, nodeListenerConfig.dsType());
83 public void testOnDataTreeChanged() throws Exception {
84 final FlowCapableNode configTree = Mockito.mock(FlowCapableNode.class);
85 final FlowCapableNode operationalTree = Mockito.mock(FlowCapableNode.class);
86 final DataTreeIdentifier<FlowCapableNode> dataTreeIdentifier =
87 new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, nodePath);
89 Mockito.when(dataTreeModification.getRootPath()).thenReturn(dataTreeIdentifier);
90 Mockito.when(dataTreeModification.getRootNode()).thenReturn(configModification);
91 Mockito.when(configModification.getDataAfter()).thenReturn(configTree);
92 Mockito.when(db.newReadOnlyTransaction()).thenReturn(roTx);
93 Mockito.doReturn(Futures.immediateCheckedFuture(Optional.of(operationalTree))).when(
94 roTx).read(LogicalDatastoreType.OPERATIONAL, nodePath);
95 Mockito.when(reactor.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(),Matchers.<FlowCapableNode>any(),Matchers.<FlowCapableNode>any()))
96 .thenReturn(Futures.immediateFuture(Boolean.TRUE));
98 nodeListenerConfig.onDataTreeChanged(Collections.singleton(dataTreeModification));
100 Mockito.verify(reactor).syncup(nodePath, configTree, operationalTree);
101 Mockito.verify(roTx).close();