Add nemo-renderers partical test files 24/30424/1
authorsaomenmen <zhangmroy@163.com>
Tue, 1 Dec 2015 09:16:39 +0000 (17:16 +0800)
committersaomenmen <zhangmroy@163.com>
Tue, 1 Dec 2015 09:17:44 +0000 (17:17 +0800)
Change-Id: Ic4e63bbb232c59e14062dd54996d1819b74bcfd1
Signed-off-by: saomenmen <zhangmroy@163.com>
nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/FlowTableManagerTest.java [new file with mode: 0644]
nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/DataBrokerAdapterTest.java
nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhyConfigLoaderTest.java [new file with mode: 0644]

diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/FlowTableManagerTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/FlowTableManagerTest.java
new file mode 100644 (file)
index 0000000..59a3aa4
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.nemo.renderer.openflow;
+
+import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import com.google.common.base.Optional;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.nemo.renderer.openflow.FlowTableManager;
+import org.opendaylight.nemo.renderer.openflow.FlowUtils;
+import org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNetwork;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalNodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.VirtualNetworks;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.VirtualNetwork;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.VirtualNetworkKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.IntentVnMappingResults;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.VnPnMappingResults;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.UserIntentVnMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.UserIntentVnMappingKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.UserVnPnMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.VirtualNetworkId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import com.google.common.util.concurrent.CheckedFuture;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+import com.google.common.base.Optional;
+import java.util.Set;
+import static org.mockito.Mockito.*;
+/**
+ * Created by zhangmeng on 2015/12/1.
+ */
+public class FlowTableManagerTest extends TestCase {
+    private FlowTableManager flowTableManager;
+    private DataBroker dataProvider;
+    private PacketProcessingService packetProcessingService;
+    private PhyConfigLoader phyConfigLoader;
+    @Before
+    public void setUp() throws Exception {
+        dataProvider = mock(DataBroker.class);
+        packetProcessingService = mock(PacketProcessingService.class);
+        phyConfigLoader = mock(PhyConfigLoader.class);
+
+        flowTableManager = new FlowTableManager(dataProvider,packetProcessingService,phyConfigLoader);
+    }
+    @Test
+    public void testGetFlowUtils() throws Exception {
+        FlowUtils flowUtils;
+
+        Class<FlowTableManager> class1 = FlowTableManager.class;
+        Method method = class1.getDeclaredMethod("getFlowUtils");
+        method.setAccessible(true);
+
+        flowUtils = (FlowUtils) method.invoke(flowTableManager);
+        Assert.assertTrue(flowUtils != null);
+    }
+
+    @Test
+    public void testClose() throws Exception {
+        flowTableManager.close();
+        Assert.assertTrue(flowTableManager != null);
+    }
+
+    @Test
+    public void testGetUser()throws  Exception{
+        UserId userId = mock(UserId.class);
+        ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);
+        CheckedFuture checkedFuture = mock(CheckedFuture.class);
+        Optional<User> result = mock(Optional.class);
+        User user = mock(User.class);
+        User user1 ;
+
+        Class<FlowTableManager> class1 = FlowTableManager.class;
+        Method method = class1.getDeclaredMethod("getUser",new Class[]{UserId.class});
+        method.setAccessible(true);
+
+        when(dataProvider.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
+        when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(checkedFuture);
+        when(checkedFuture.get()).thenReturn(result);
+        when(result.isPresent())
+                .thenReturn(false)
+                .thenReturn(true);
+        when(result.get()).thenReturn(user);
+
+        //branch 1
+        user1 = (User)method.invoke(flowTableManager,userId);
+        Assert.assertTrue(user1 == null);
+
+        //branch2
+        user1 = (User)method.invoke(flowTableManager,userId);
+        Assert.assertTrue(user1 != null);
+
+    }
+
+    @Test
+    public void testGetVirtualNetwork()throws  Exception{
+        UserId userId = mock(UserId.class);
+        ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);
+        CheckedFuture checkedFuture = mock(CheckedFuture.class);
+        Optional<VirtualNetwork> result = mock(Optional.class);
+        VirtualNetwork virtualNetwork = mock(VirtualNetwork.class);
+        VirtualNetwork virtualNetwork1 ;
+
+        Class<FlowTableManager> class1 = FlowTableManager.class;
+        Method method = class1.getDeclaredMethod("getVirtualNetwork", new Class[]{UserId.class});
+        method.setAccessible(true);
+
+        when(userId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222"));
+        when(dataProvider.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
+        when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(checkedFuture);
+        when(checkedFuture.get()).thenReturn(result);
+        when(result.isPresent())
+                .thenReturn(false)
+                .thenReturn(true);
+        when(result.get()).thenReturn(virtualNetwork);
+
+        //branch 1
+        virtualNetwork1 = (VirtualNetwork) method.invoke(flowTableManager,userId);
+        Assert.assertTrue(virtualNetwork1 == null);
+
+        //branch 2
+        virtualNetwork1 = (VirtualNetwork) method.invoke(flowTableManager,userId);
+        Assert.assertTrue(virtualNetwork1 != null);
+    }
+
+    @Test
+    public void testGetUserIntentVnMapping()throws  Exception{
+        UserId userId = mock(UserId.class);
+        ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);
+        CheckedFuture checkedFuture = mock(CheckedFuture.class);
+        Optional<UserIntentVnMapping> result = mock(Optional.class);
+        UserIntentVnMapping vnMapping;
+//        InstanceIdentifier instanceIdentifier
+
+        Class<FlowTableManager> class1 = FlowTableManager.class;
+        Method method = class1.getDeclaredMethod("getUserIntentVnMapping",new Class[]{UserId.class});
+        method.setAccessible(true);
+
+        when(dataProvider.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
+        when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(checkedFuture);
+        when(checkedFuture.get()).thenReturn(result);
+        when(result.isPresent())
+                .thenReturn(false)
+                .thenReturn(true);
+        when(result.get()).thenReturn(mock(UserIntentVnMapping.class));
+
+        //branch1
+        vnMapping = (UserIntentVnMapping) method.invoke(flowTableManager,userId);
+        Assert.assertTrue(vnMapping == null);
+
+        //branch2
+        vnMapping = (UserIntentVnMapping) method.invoke(flowTableManager,userId);
+        Assert.assertTrue(vnMapping != null);
+    }
+}
\ No newline at end of file
index 9fdd1462a9e2a862310bec031abaee9a57f25050..4339cfb9c7ba6a19c342a8b962c7c0239a01e271 100644 (file)
@@ -1,5 +1,13 @@
-package org.opendaylight.nemo.renderer.openflow.physicalnetwork;
+/*
+ * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.nemo.renderer.openflow.phtysicalnetwork;
 import junit.framework.TestCase;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -27,6 +35,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.lang.reflect.Method;
+import java.nio.channels.ClosedSelectorException;
+import java.util.Objects;
 
 import static org.mockito.Mockito.*;
 /**
@@ -42,32 +52,143 @@ public class DataBrokerAdapterTest extends TestCase {
     }
 
     @Test
-    public void testAddPhysicalHost() throws Exception {
+    public void testGetPhysicalHostIdentifier() throws Exception {
         PhysicalHostKey physicalHostKey = mock(PhysicalHostKey.class);
         Class<DataBrokerAdapter> class1 = DataBrokerAdapter.class;
         Method method  = class1.getDeclaredMethod("getPhysicalHostIdentifier", new Class[]{PhysicalHostKey.class});
 
         method.setAccessible(true);
-        Object result = method.invoke(dataBrokerAdapter,new Object[]{physicalHostKey = mock(PhysicalHostKey.class)});
+        Object object =
+                method.invoke(dataBrokerAdapter, new Object[]{physicalHostKey = mock(PhysicalHostKey.class)});
+        Assert.assertTrue(object != null);
     }
 
     @Test
-    public void testAddPhysicalNode() throws Exception {
+    public void testGetPhysicalNodeIdentifier() throws Exception {
+        PhysicalNodeKey physicalNodeKey = mock(PhysicalNodeKey.class);
+        Class<DataBrokerAdapter> class1 = DataBrokerAdapter.class;
+        Method method = class1.getDeclaredMethod("getPhysicalNodeIdentifier",new Class[]{PhysicalNodeKey.class});
+
+        method.setAccessible(true);
+        Object object = method.invoke(dataBrokerAdapter,physicalNodeKey);
+        Assert.assertTrue(object != null);
 
     }
 
     @Test
-    public void testRemovePhysicalNode() throws Exception {
+    public void testGetPhysicalLinkIdentifier() throws Exception {
+        PhysicalLinkKey physicalLinkKey  = mock(PhysicalLinkKey.class);
+        Class<DataBrokerAdapter> class1 = DataBrokerAdapter.class;
+        Method method = class1.getDeclaredMethod("getPhysicalLinkIdentifier",new Class[]{PhysicalLinkKey.class});
 
+        method.setAccessible(true);
+        Object object = method.invoke(dataBrokerAdapter,physicalLinkKey);
+        Assert.assertTrue(object != null);
     }
 
+    @Test
+    public void testAddPhysicalHost() throws Exception {
+        final PhysicalHost physicalHost = mock(PhysicalHost.class);
+        WriteTransaction writeTransaction = mock(WriteTransaction.class);
+        PhysicalHostKey physicalHostKey = mock(PhysicalHostKey.class);
+        CheckedFuture checkedFuture = mock(CheckedFuture.class);
+
+        Class<DataBrokerAdapter> class1 = DataBrokerAdapter.class;
+        Method method = class1.getDeclaredMethod("addPhysicalHost",new Class[]{PhysicalHost.class});
+        method.setAccessible(true);
+
+        when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+        when(physicalHost.getKey()).thenReturn(physicalHostKey);
+        when(writeTransaction.submit()).thenReturn(checkedFuture);
+
+        method.invoke(dataBrokerAdapter, physicalHost);
+
+        verify(dataBroker).newWriteOnlyTransaction();
+        verify(physicalHost).getKey();
+        verify(writeTransaction).submit();
+    }
+    @Test
+    public void testAddPhysicalNode() throws Exception {
+        final PhysicalNode physicalNode = mock(PhysicalNode.class);
+        WriteTransaction writeTransaction = mock(WriteTransaction.class);
+        PhysicalNodeKey physicalNodeKey = mock(PhysicalNodeKey.class);
+        CheckedFuture checkedFuture = mock(CheckedFuture.class);
+
+        Class<DataBrokerAdapter> class1 = DataBrokerAdapter.class;
+        Method method = class1.getDeclaredMethod("addPhysicalNode",new Class[]{PhysicalNode.class});
+        method.setAccessible(true);
+
+        when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+        when(physicalNode.getKey()).thenReturn(physicalNodeKey);
+        when(writeTransaction.submit()).thenReturn(checkedFuture);
+
+//        boolean b = false;
+        Assert.assertNotNull(method.invoke(dataBrokerAdapter, physicalNode));
+
+        verify(dataBroker).newWriteOnlyTransaction();
+        verify(physicalNode).getKey();
+        verify(writeTransaction).submit();
+
+    }
+    @Test
+    public void testRemovePhysicalNode() throws Exception {
+        final PhysicalNodeKey nodeKey = mock(PhysicalNodeKey.class);
+        WriteTransaction writeTransaction = mock(WriteTransaction.class);
+        CheckedFuture checkedFuture = mock(CheckedFuture.class);
+
+        Class<DataBrokerAdapter> class1 = DataBrokerAdapter.class;
+        Method method = class1.getDeclaredMethod("removePhysicalNode",new Class[]{PhysicalNodeKey.class});
+        method.setAccessible(true);
+
+        when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+        when(writeTransaction.submit()).thenReturn(checkedFuture);
+
+        Assert.assertNotNull(method.invoke(dataBrokerAdapter, nodeKey));
+
+        verify(dataBroker).newWriteOnlyTransaction();
+        verify(writeTransaction).submit();
+
+    }
     @Test
     public void testAddPhysicalLink() throws Exception {
+        final PhysicalLink physicalLink = mock(PhysicalLink.class);
+        WriteTransaction writeTransaction = mock(WriteTransaction.class);
+        CheckedFuture checkedFuture = mock(CheckedFuture.class);
+        PhysicalLinkKey physicalLinkKey = mock(PhysicalLinkKey.class);
 
+        Class<DataBrokerAdapter> class1 = DataBrokerAdapter.class;
+        Method method = class1.getDeclaredMethod("addPhysicalLink",new Class[]{PhysicalLink.class});
+        method.setAccessible(true);
+
+        when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+        when(physicalLink.getKey()).thenReturn(physicalLinkKey);
+        when(writeTransaction.submit()).thenReturn(checkedFuture);
+
+        method.invoke(dataBrokerAdapter, physicalLink);
+
+        verify(dataBroker).newWriteOnlyTransaction();
+        verify(physicalLink).getKey();
+        verify(writeTransaction).submit();
     }
 
     @Test
     public void testRemovePhysicalLink() throws Exception {
+        final PhysicalLinkKey physicalLinkKey = mock(PhysicalLinkKey.class);
+        WriteTransaction writeTransaction = mock(WriteTransaction.class);
+        CheckedFuture checkedFuture = mock(CheckedFuture.class);
+
+        Class<DataBrokerAdapter> class1 = DataBrokerAdapter.class;
+        Method method = class1.getDeclaredMethod("removePhysicalLink", new Class[]{PhysicalLinkKey.class});
+        method.setAccessible(true);
+
+        when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+        when(writeTransaction.submit()).thenReturn(checkedFuture);
+
+        method.invoke(dataBrokerAdapter, physicalLinkKey);
+
+        verify(dataBroker).newWriteOnlyTransaction();
+        verify(writeTransaction).submit();
 
     }
+
 }
\ No newline at end of file
diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhyConfigLoaderTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhyConfigLoaderTest.java
new file mode 100644 (file)
index 0000000..4a9a14f
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.nemo.renderer.openflow.physicalnetwork;
+
+import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoader;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNodeInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalPortInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.attribute.instance.AttributeValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.host.instance.IpAddressesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPortBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.Attribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.crypto.Data;
+import java.io.IOException;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import static org.mockito.Mockito.*;
+/**
+ * Created by zhangmeng on 2015/11/30.
+ */
+public class PhyConfigLoaderTest extends TestCase {
+    private PhyConfigLoader phyConfigLoader;
+    private DataBroker dataBroker;
+    @Before
+    public void setUp() throws Exception {
+        dataBroker = mock(DataBroker.class);
+        phyConfigLoader = new PhyConfigLoader(dataBroker);
+    }
+
+    @Test
+    public void testGetExternalNetworkMac() throws Exception {
+        Table<PhysicalNodeId, PhysicalPortId, MacAddress> table;
+        table = phyConfigLoader.getExternalNetworkMac();
+        Assert.assertTrue(table != null);
+    }
+
+    @Test
+    public void testGetPhysicalNode() throws Exception {
+        PhysicalNodeId physicalNodeId = mock(PhysicalNodeId.class);
+        PhysicalNode physicalNode ;
+
+        Class<PhyConfigLoader> class1 = PhyConfigLoader.class;
+        Method method = class1.getDeclaredMethod("getPhysicalNode",new Class[]{PhysicalNodeId.class});
+        method.setAccessible(true);
+
+        physicalNode = (PhysicalNode) method.invoke(phyConfigLoader,physicalNodeId);
+
+        Assert.assertTrue( physicalNode == null);
+    }
+
+    @Test
+    public void testGetPhysicalPort() throws Exception {
+        PhysicalPortId physicalPortId = mock(PhysicalPortId.class);
+        PhysicalPort physicalPort;
+
+        Class<PhyConfigLoader> class1 = PhyConfigLoader.class;
+        Method method = class1.getDeclaredMethod("getPhysicalPort",new Class[]{PhysicalPortId.class});
+        method.setAccessible(true);
+
+        physicalPort = (PhysicalPort) method.invoke(phyConfigLoader,physicalPortId);
+
+        Assert.assertTrue(physicalPort == null);
+    }
+
+    @Test
+    public void testGetPhysicalLink() throws Exception {
+        PhysicalLinkId physicalLinkId = mock(PhysicalLinkId.class);
+        PhysicalLink physicalLink;
+
+        Class<PhyConfigLoader> class1 = PhyConfigLoader.class;
+        Method method = class1.getDeclaredMethod("getPhysicalLink",new Class[]{PhysicalLinkId.class});
+        method.setAccessible(true);
+
+        physicalLink = (PhysicalLink) method.invoke(phyConfigLoader,physicalLinkId);
+
+        Assert.assertTrue(physicalLink == null);
+    }
+
+    @Test
+    public void testClose() throws Exception {
+        phyConfigLoader.close();
+    }
+}
\ No newline at end of file