2 * Copyright (c) 2015 Huawei, 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.nemo.renderer.openflow.physicalnetwork;
10 import static org.mockito.Mockito.doReturn;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.verify;
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;
21 * Created by zhangmeng on 2015/11/19.
23 public class OFLinkListenerTest {
24 private final PhysicalNetworkAdapter mockAdapter = mock(PhysicalNetworkAdapter.class);
25 private OFLinkListener listener;
28 public void setUp() throws Exception {
29 listener = new OFLinkListener(mockAdapter);
32 @SuppressWarnings("unchecked")
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();
39 Link mockLink = mock(Link.class);
40 doReturn(mockLink).when(mockModification).getDataAfter();
41 doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType();
43 listener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification));
45 verify(mockAdapter).ofLinkAdded(mockLink);