Convert DataChangeListeners to DataTreeChangeListeners
[nemo.git] / nemo-renderers / openflow-renderer / src / test / java / org / opendaylight / nemo / renderer / openflow / physicalnetwork / OFLinkListenerTest.java
1 /*
2  * Copyright (c) 2015 Huawei, 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.nemo.renderer.openflow.physicalnetwork;
9
10 import static org.mockito.Mockito.doReturn;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.verify;
13
14 import java.util.Collections;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
18 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
20 /**
21  * Created by zhangmeng on 2015/11/19.
22  */
23 public class OFLinkListenerTest {
24     private final PhysicalNetworkAdapter mockAdapter = mock(PhysicalNetworkAdapter.class);
25     private OFLinkListener listener;
26
27     @Before
28     public void setUp() throws Exception {
29         listener = new OFLinkListener(mockAdapter);
30     }
31
32     @SuppressWarnings("unchecked")
33     @Test
34     public void testOnDataTreeChanged() throws Exception {
35         DataTreeModification<Link> mockDataTreeModification = mock(DataTreeModification.class);
36         DataObjectModification<Link> mockModification = mock(DataObjectModification.class);
37         doReturn(mockModification).when(mockDataTreeModification).getRootNode();
38
39         Link mockLink = mock(Link.class);
40         doReturn(mockLink).when(mockModification).getDataAfter();
41         doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType();
42
43         listener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification));
44
45         verify(mockAdapter).ofLinkAdded(mockLink);
46     }
47 }