From: saomenmen Date: Mon, 11 Jan 2016 08:12:44 +0000 (+0800) Subject: Added test files for nemo-tool X-Git-Tag: release/boron~18^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=ce695475991f7c85cb9126698d7f91e61e1899ff;p=nemo.git Added test files for nemo-tool Change-Id: I4d1b5292763c63668ce4b9b1152bc4137f2c4762 Signed-off-by: saomenmen --- diff --git a/nemo-tools/sandbox/pom.xml b/nemo-tools/sandbox/pom.xml index e8adf01..a53d517 100644 --- a/nemo-tools/sandbox/pom.xml +++ b/nemo-tools/sandbox/pom.xml @@ -30,9 +30,28 @@ and is available at http://www.eclipse.org/legal/epl-v10.html 1.0-SNAPSHOT 262 20090211 + 1.5.2 + + org.powermock + powermock-core + ${powermock.version} + test + + + org.powermock + powermock-module-junit4 + ${powermock.version} + test + + + org.powermock + powermock-api-mockito + ${powermock.version} + test + org.slf4j slf4j-log4j12 diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/CliTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/CliTest.java new file mode 100644 index 0000000..8503373 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/CliTest.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 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.tool.sandbox; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import asg.cliche.Command; +import asg.cliche.Shell; +import asg.cliche.ShellDependent; +import static org.mockito.Mockito.*; +/** + * Created by zhangmeng on 2016/1/14. + */ +public class CliTest extends TestCase { + private Cli cli; + @Before + public void setUp() throws Exception { + cli = new Cli(); + } + + @Test + public void testCliSetShell() throws Exception { + Shell shell = mock(Shell.class); + cli.cliSetShell(shell); + } + + @Test + public void testInstall() throws Exception { + cli.install(); + } + + @Test + public void testUninstall() throws Exception { + cli.uninstall(); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/CmdExecutorTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/CmdExecutorTest.java new file mode 100644 index 0000000..32ab69e --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/CmdExecutorTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2016 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.tool.sandbox; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.awt.color.CMMException; + +import static org.junit.Assert.*; +import ch.ethz.ssh2.Connection; +import ch.ethz.ssh2.Session; +import ch.ethz.ssh2.StreamGobbler; +import org.junit.runner.RunWith; +import org.opendaylight.nemo.tool.sandbox.utils.Config; +import org.opendaylight.nemo.tool.sandbox.utils.FileUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import static org.mockito.Mockito.*; +/** + * Created by zhangmeng on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest(ch.ethz.ssh2.Connection.class) +public class CmdExecutorTest extends TestCase { + private CmdExecutor cmdExecutor; + private Class class1; + private Field field_sshConnection; + @Before + public void setUp() throws Exception { + class1 = CmdExecutor.class; + field_sshConnection = class1.getDeclaredField("sshConnection"); + field_sshConnection.setAccessible(true); + + cmdExecutor = new CmdExecutor(); + } + + @Test + public void testOpen() throws Exception { + String command = "cd ~"; + Session session = mock(Session.class); + Connection sshConnection = mock(Connection.class); + + Assert.assertTrue(CmdExecutor.open() == false); + PowerMockito.whenNew(Connection.class).withArguments(any(String.class)).thenReturn(sshConnection); + when(sshConnection.authenticateWithPassword(any(String.class), any(String.class))).thenReturn(true); + Assert.assertTrue(CmdExecutor.open() == false); +// Assert.assertTrue(field_sshConnection.get(class1) == sshConnection); +// verify(sshConnection).authenticateWithPassword(any(String.class), any(String.class)); + + field_sshConnection.set(class1, sshConnection); + when(sshConnection.openSession()).thenReturn(session); + doNothing().when(session).execCommand(command); + when(session.getStdout()).thenReturn(mock(InputStream.class)); + Assert.assertTrue(CmdExecutor.sshExecute(command) != null); + verify(session).getStdout(); + CmdExecutor.queryInterfaceMac("eth0"); + CmdExecutor.queryInterfaceMac("1","eth0"); + + CmdExecutor.close(); + } + + @Test + public void testgetMacFromResult() throws Exception { + Method method = class1.getDeclaredMethod("getMacFromResult",new Class[]{ + String.class + }); + method.setAccessible(true); + Assert.assertTrue(method.invoke(class1,"HWaddr") != null); + } + +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/EasyCliTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/EasyCliTest.java new file mode 100644 index 0000000..fe9d689 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/EasyCliTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 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.tool.sandbox; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import asg.cliche.Shell; +import asg.cliche.ShellFactory; + +import java.io.IOException; +import java.lang.reflect.Field; +import static org.mockito.Mockito.*; + +/** + * Created by zhangmeng on 2016/1/14. + */ +public class EasyCliTest extends TestCase { + private EasyCli easyCli; + @Before + public void setUp() throws Exception { + easyCli = new EasyCli("1","2","3"); + } + + @Test + public void testAdd() throws Exception { + easyCli.add("4"); + } + + @Test + public void testRun() throws Exception { + Field field = EasyCli.class.getDeclaredField("shell"); + field.setAccessible(true); + + Shell shell = mock(Shell.class); + + field.set(easyCli,shell); + doNothing().when(shell).commandLoop(); + easyCli.run(); + verify(shell).commandLoop(); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/SandBoxManagerTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/SandBoxManagerTest.java new file mode 100644 index 0000000..f534982 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/SandBoxManagerTest.java @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2016 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.tool.sandbox; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import org.json.JSONObject; +import org.junit.runner.RunWith; +import org.opendaylight.nemo.tool.sandbox.models.*; +import org.opendaylight.nemo.tool.sandbox.utils.PropertyLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; +/** + * Created by zhangmeng on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest(CmdExecutor.class) +public class SandBoxManagerTest extends TestCase { + private SandBoxManager sandBoxManager; + private Method method; + @Before + public void setUp() throws Exception { + sandBoxManager = SandBoxManager.getInstance(); + } + + @Test + public void testGetInstance() throws Exception { + sandBoxManager = SandBoxManager.getInstance(); + } + + @Test + public void testGets() throws Exception { + Field field = SandBoxManager.class.getDeclaredField("network"); + field.setAccessible(true); + + Network network = mock(Network.class); + JSONObject jsonObject = mock(JSONObject.class); + + //no powermock and network=null + field.set(sandBoxManager, null); + org.junit.Assert.assertTrue(!sandBoxManager.createNetwork(null)); + org.junit.Assert.assertTrue(!sandBoxManager.createNetwork()); + org.junit.Assert.assertTrue(sandBoxManager.getHosts() == null); + org.junit.Assert.assertTrue(sandBoxManager.getExternals() == null); + org.junit.Assert.assertTrue(sandBoxManager.getSwitches() == null); + org.junit.Assert.assertTrue(sandBoxManager.getLinks() == null); + org.junit.Assert.assertTrue(sandBoxManager.destroyNetwork()); + + field.set(sandBoxManager, network); + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.open()).thenReturn(true); + when(network.hostJsonNode()).thenReturn(jsonObject); + when(network.externalJsonNode()).thenReturn(jsonObject); + when(network.nodeJsonNode()).thenReturn(jsonObject); + when(network.innerLinkJsonNode()).thenReturn(jsonObject); + when(network.execute(any(String.class), any(String.class))).thenReturn("test"); + org.junit.Assert.assertTrue(sandBoxManager.execute("1","1").equals("test")); + org.junit.Assert.assertTrue(sandBoxManager.getHosts() != null); + org.junit.Assert.assertTrue(sandBoxManager.getExternals() != null); + org.junit.Assert.assertTrue(sandBoxManager.getSwitches() != null); + org.junit.Assert.assertTrue(sandBoxManager.getLinks() != null); + + org.junit.Assert.assertTrue(sandBoxManager.createNetwork(PropertyLoader.readLines("/Network", "Network file does not exist."))); + org.junit.Assert.assertTrue(sandBoxManager.createNetwork()); + org.junit.Assert.assertTrue(sandBoxManager.destroyNetwork()); + } + @Test + public void testGetNodeType() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("getNodeType",new Class[]{String.class}); + method.setAccessible(true); + + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Switch") == NodeType.SWITCH); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Router") == NodeType.ROUTER); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Cache") == NodeType.CACHE); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Firewall") == NodeType.FIREWALL); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Vm") == NodeType.VM); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,"1") == NodeType.UNKNOWN); + + } + + @Test + public void testHandleLink() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("handleLink",new Class[]{String.class}); + method.setAccessible(true); + + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "12") == null); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,"1,2,3,4,5") != null); + } + + @Test + public void testSaveConnector() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("saveConnector",new Class[]{ + Connector.class, + Map.class + }); + method.setAccessible(true); + + Connector connector = mock(Connector.class); + Map> connectorMap = mock(Map.class); + + when(connector.getNodeName()).thenReturn("test"); + when(connectorMap.containsKey(any(String.class))) + .thenReturn(true) + .thenReturn(false); + when(connectorMap.get(any(String.class))).thenReturn(mock(List.class)); + method.invoke(sandBoxManager, connector, connectorMap); + method.invoke(sandBoxManager, connector, connectorMap); + verify(connectorMap,times(2)).containsKey(any(String.class)); + } + + @Test + public void testParserHost() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("parserHost",new Class[]{ + String[].class, + Map.class, + Host.class + }); + method.setAccessible(true); + + String[] args = {"1","2","3","1:2"}; + Map> connectorMap = mock(Map.class); + Host host = mock(Host.class); + Connector connector = mock(Connector.class); + List connectors = new ArrayList(); + + connectors.add(connector); + + when(host.getName()).thenReturn("test"); + when(connectorMap.get(host.getName())).thenReturn(connectors); + + method.invoke(sandBoxManager, args, connectorMap, host); + verify(host,times(2)).getName(); + } + + @Test + public void testHandleFirewall() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("handleFirewall",new Class[]{ + String.class, + Map.class + }); + method.setAccessible(true); + + String line = "test"; + Map> connectorMap = mock(Map.class); + + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) == null); + line = "1,2,3,1:2"; + when(connectorMap.get(any(String.class))).thenReturn(null); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) != null); + } + + @Test + public void testHandleCache() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("handleCache",new Class[]{ + String.class, + Map.class + }); + method.setAccessible(true); + + String line = "test"; + Map> connectorMap = mock(Map.class); + + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) == null); + line = "1,2,3,1:2"; + when(connectorMap.get(any(String.class))).thenReturn(null); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) != null); + + } + + @Test + public void testHandleVirtualMachine() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("handleVirtualMachine",new Class[]{ + String.class, + Map.class + }); + method.setAccessible(true); + + String line = "test"; + Map> connectorMap = mock(Map.class); + + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) == null); + line = "1,2,3,1:2"; + when(connectorMap.get(any(String.class))).thenReturn(null); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) != null); + } + + @Test + public void testHandleSwitch() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("handleSwitch",new Class[]{ + String.class, + Map.class + }); + method.setAccessible(true); + + List connectorList = new ArrayList(); + Connector connector = mock(Connector.class); + String line = "test"; + Map> connectorMap = mock(Map.class); + + connectorList.add(connector); + + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, line, connectorMap) == null); + line = "Router,2,3"; + when(connectorMap.get(any(String.class))).thenReturn(connectorList); + org.junit.Assert.assertTrue(method.invoke(sandBoxManager, line, connectorMap) != null); + + } + + @Test + public void testGenerateNetwork() throws Exception { + method = SandBoxManager.class.getDeclaredMethod("generateNetwork",new Class[]{List.class}); + method.setAccessible(true); + + List list = new ArrayList(); + list.add("Switch"); + method.invoke(sandBoxManager, list); + list.clear(); + list.add("Vm"); + method.invoke(sandBoxManager, list); + list.clear(); + list.add("Cache"); + method.invoke(sandBoxManager, list); + list.clear(); + list.add("Firewall"); + method.invoke(sandBoxManager, list); + + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/CacheTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/CacheTest.java new file mode 100644 index 0000000..37b58b8 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/CacheTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016 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.tool.sandbox.models; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; + +import java.lang.reflect.Method; +import java.lang.reflect.Field; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({CmdExecutor.class}) +public class CacheTest extends TestCase { + String name,uuId; + Cache cacheTest; + private Method method; + private Class class1; + private Connector connector; + + + @Before + public void setUp() throws Exception { + name = new String("name1"); + uuId = new String("11111111-1111-1111-1111-111111111111"); + cacheTest = new Cache(name,uuId); + class1 = Cache.class; + org.opendaylight.nemo.tool.sandbox.models.Connector connector = mock(org.opendaylight.nemo.tool.sandbox.models.Connector.class); + cacheTest.addConnectors(connector); + } + + @Test + public void testGenerateCommands() throws Exception { + method = class1.getDeclaredMethod("generateCommands",new Class[]{}); + method.setAccessible(true); + Assert.assertNotNull(method.invoke(cacheTest)); + } + + @Test + public void testUninstall() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + cacheTest.uninstall(); + + } + +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/ConnectorTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/ConnectorTest.java new file mode 100644 index 0000000..d7fe784 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/ConnectorTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016 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.tool.sandbox.models; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.nemo.tool.sandbox.models.Connector; + +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +import static org.junit.Assert.*; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +public class ConnectorTest extends TestCase { + private int order; + private String nodeName; + private Connector connectorTest; + + @Before + public void setUp() throws Exception { + order = 10; + nodeName = "connector"; + connectorTest = new Connector(nodeName,order); + + } + + @Test + public void testGetConnectorName() throws Exception { + Assert.assertNotNull(connectorTest.getConnectorName()); + } + + @Test + public void testGetOrder() throws Exception { + Assert.assertNotNull(connectorTest.getOrder()); + } + + @Test + public void testGetNodeName() throws Exception { + Assert.assertNotNull(connectorTest.getNodeName()); + } + + @Test + public void testEquals() throws Exception { + Assert.assertNotNull(connectorTest.equals(this)); + + } + + @Test + public void testHashCode() throws Exception { + Assert.assertNotNull(connectorTest.hashCode()); + } + + @Test + public void testToString() throws Exception { + Assert.assertNotNull(connectorTest.toString()); + } + + @Test + public void testCompareTo() throws Exception { + Assert.assertNotNull(connectorTest.compareTo(new Connector("connector2",5))); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/FirewallTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/FirewallTest.java new file mode 100644 index 0000000..6d2ad88 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/FirewallTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016 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.tool.sandbox.models; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; +import org.opendaylight.nemo.tool.sandbox.models.Firewall; + +import java.lang.reflect.Method; +import java.lang.reflect.Field; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({CmdExecutor.class}) +public class FirewallTest extends TestCase { + + String name,uuId; + Firewall firewallTest; + private Method method; + private Class class1; + private Connector connector; + + @Before + public void setUp() throws Exception { + name = new String("name1"); + uuId = new String("11111111-1111-1111-1111-111111111111"); + firewallTest = new Firewall(name,uuId); + class1 = Firewall.class; + org.opendaylight.nemo.tool.sandbox.models.Connector connector = mock(org.opendaylight.nemo.tool.sandbox.models.Connector.class); + firewallTest.addConnectors(connector); + + } + + @Test + public void testGenerateCommands() throws Exception { + method = class1.getDeclaredMethod("generateCommands",new Class[]{}); + method.setAccessible(true); + Assert.assertNotNull(method.invoke(firewallTest)); + + } + + @Test + public void testUninstall() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + firewallTest.uninstall(); + + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/LinkTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/LinkTest.java new file mode 100644 index 0000000..2faf1a5 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/LinkTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2016 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.tool.sandbox.models; +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; +import org.opendaylight.nemo.tool.sandbox.models.Connector; + +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({CmdExecutor.class}) +public class LinkTest extends TestCase { + + private Connector srcInterface; + private Connector dstInterface; + private Link likeTest; + + @Before + public void setUp() throws Exception { + srcInterface = new Connector("src",1); + dstInterface = new Connector("dst",2); + likeTest = new Link(srcInterface,dstInterface); + + } + + @Test + public void testGetSrcConnector() throws Exception { + Assert.assertNotNull(likeTest.getSrcConnector()); + } + + @Test + public void testGetDstConnector() throws Exception { + Assert.assertNotNull(likeTest.getDstConnector()); + } + + @Test + public void testInstall() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + likeTest.install(); + } + + @Test + public void testUninstall() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + likeTest.uninstall(); + } + + @Test + public void testEquals() throws Exception { + Assert.assertNotNull(likeTest.equals(this)); + } + + @Test + public void testHashCode() throws Exception { + Assert.assertNotNull(likeTest.hashCode()); + } + + @Test + public void testToString() throws Exception { + Assert.assertNotNull(likeTest.toString()); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/NetworkTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/NetworkTest.java new file mode 100644 index 0000000..b8b9032 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/NetworkTest.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2016 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.tool.sandbox.models; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; +import org.opendaylight.nemo.tool.sandbox.models.Cache; +import org.opendaylight.nemo.tool.sandbox.models.Connector; +import org.opendaylight.nemo.tool.sandbox.models.Network; + +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; +import org.opendaylight.nemo.tool.sandbox.utils.Config; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + + +/** + * Created by Thomas Liu on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({CmdExecutor.class}) +public class NetworkTest extends TestCase { + private Network networkTest; + + @Before + public void setUp() throws Exception { + networkTest = new Network(); + + } + + @Test + public void testAddHost() throws Exception { + networkTest.addHost(new Cache("src1","1")); + networkTest.addHost(new Cache("dst2","1")); + } + + @Test + public void testAddSwitch() throws Exception { + networkTest.addSwitch(new Switch("dst1", 1L)); + networkTest.addSwitch(new Switch("src2", 1L)); + networkTest.addSwitch(new Switch("src3", 1L)); + networkTest.addSwitch(new Switch("dst3", 1L)); + } + + @Test + public void testAddLink() throws Exception { + networkTest.addLink(new Link(new Connector("src1", 1), new Connector("dst1", 2))); + networkTest.addLink(new Link(new Connector("src2", 1), new Connector("dst2", 2))); + networkTest.addLink(new Link(new Connector("src3", 1), new Connector("dst3", 2))); + + } + + @Test + public void testExecute() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.open()).thenReturn(true); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.doNothing().when(CmdExecutor.class); + CmdExecutor.close(); + Assert.assertNotNull(networkTest.execute("cache", "command")); + + } + + @Test + public void testInstall() throws Exception { + //test traversal + networkTest.install(); + + } + + @Test + public void testUninstall() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + + networkTest.uninstall(); + + } + + @Test + public void testEchoConfig() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + + networkTest.echoConfig(); + + //test hostJsonNode() + + + + } + + @Test + public void testInnerLinkJsonNode() throws Exception { + + Assert.assertNotNull(networkTest.innerLinkJsonNode()); + + + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/RouterTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/RouterTest.java new file mode 100644 index 0000000..8326a78 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/RouterTest.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 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.tool.sandbox.models; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +public class RouterTest extends TestCase { + private String name; + private long dataPathId; + private Router routerTest; + @Before + public void setUp() throws Exception { + + } + + @Test + public void test1() throws Exception { + name = new String("name1"); + dataPathId = 1L; + routerTest = new Router(name,dataPathId); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/SwitchTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/SwitchTest.java new file mode 100644 index 0000000..d94055f --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/SwitchTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2016 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.tool.sandbox.models; + + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +import org.opendaylight.nemo.tool.sandbox.utils.Config; +import org.opendaylight.nemo.tool.sandbox.utils.HexString; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import java.lang.reflect.Method; +import java.lang.reflect.Field; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +public class SwitchTest extends TestCase { + + private String name; + private long dataPathId; + private Switch switchTest; + private Class class1; + private Method method; + + + @Before + public void setUp() throws Exception { + name = new String("name1"); + dataPathId = 1L; + switchTest = new Switch(name,dataPathId); + class1 = Switch.class; + org.opendaylight.nemo.tool.sandbox.models.Connector connector = new org.opendaylight.nemo.tool.sandbox.models.Connector("connectorname",1); + switchTest.addConnectors(connector); + } + + @Test + public void testGetDataPathId() throws Exception { + Assert.assertNotNull(switchTest.getDataPathId()); + } + + @Test + public void testGenerateCommands() throws Exception { + method = class1.getDeclaredMethod("generateCommands",new Class[]{}); + method.setAccessible(true); + Assert.assertNotNull(method.invoke(switchTest)); + + } + + @Test + public void testToString() throws Exception { + Assert.assertNotNull(switchTest.toString()); + + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/VirtualMachineTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/VirtualMachineTest.java new file mode 100644 index 0000000..f405927 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/models/VirtualMachineTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016 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.tool.sandbox.models; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; +import org.opendaylight.nemo.tool.sandbox.models.VirtualMachine; + +import java.lang.reflect.Method; +import java.lang.reflect.Field; + +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.opendaylight.nemo.tool.sandbox.CmdExecutor; + +/** + * Created by Thomas Liu on 2016/1/14. + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({CmdExecutor.class}) +public class VirtualMachineTest extends TestCase { + String name,uuId; + Cache cacheTest; + private VirtualMachine virtualMachineTest; + private Connector connector; + private Class class1; + private Method method; + @Before + public void setUp() throws Exception { + name = new String("name1"); + uuId = new String("11111111-1111-1111-1111-111111111111"); + virtualMachineTest = new VirtualMachine(name,uuId); + org.opendaylight.nemo.tool.sandbox.models.Connector connector = mock(org.opendaylight.nemo.tool.sandbox.models.Connector.class); + virtualMachineTest.addConnectors(connector); + class1 = VirtualMachine.class; + + } + + @Test + public void testGenerateCommands() throws Exception { + method = class1.getDeclaredMethod("generateCommands",new Class[]{}); + method.setAccessible(true); + Assert.assertNotNull(method.invoke(virtualMachineTest)); + } + + @Test + public void testUninstall() throws Exception { + PowerMockito.mockStatic(CmdExecutor.class); + PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null"); + virtualMachineTest.uninstall(); + + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/CreateRequestTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/CreateRequestTest.java new file mode 100644 index 0000000..d95bbd0 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/CreateRequestTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 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.tool.sandbox.northbound; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangmeng on 2016/1/14. + */ +public class CreateRequestTest extends TestCase { + private CreateRequest createRequest; + @Before + public void setUp() throws Exception { + + } + + @Test + public void testInit()throws Exception{ + createRequest = new CreateRequest(); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/ExecuteRequestTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/ExecuteRequestTest.java new file mode 100644 index 0000000..35d9a50 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/ExecuteRequestTest.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 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.tool.sandbox.northbound; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangmeng on 2016/1/14. + */ +public class ExecuteRequestTest extends TestCase { + private ExecuteRequest executeRequest; + @Before + public void setUp() throws Exception { + executeRequest = new ExecuteRequest(); + } + + @Test + public void testGet_Set() throws Exception { + Assert.assertTrue(executeRequest.getHostName() == null); + executeRequest.setHostName("test"); + Assert.assertTrue(executeRequest.getHostName().equals("test")); + + Assert.assertTrue(executeRequest.getCommand() == null); + executeRequest.setCommand("command"); + Assert.assertTrue(executeRequest.getCommand().equals("command")); + + //test to string + Assert.assertTrue(executeRequest.toString().equals("ExecuteRequest{" + + "hostName='" + "test" + '\'' + + ", command='" + "command" + '\'' + + '}')); + } + +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/RestServerTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/RestServerTest.java new file mode 100644 index 0000000..25e6c4c --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/RestServerTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 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.tool.sandbox.northbound; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; +import org.glassfish.jersey.server.ResourceConfig; + +import java.io.Reader; +import java.net.URI; +/** + * Created by zhangmeng on 2016/1/14. + */ +public class RestServerTest extends TestCase { + private RestServer restServer; + @Before + public void setUp() throws Exception { + restServer = new RestServer(); + } + + @Test + public void testStart() throws Exception { +// RestServer.start("s1"); + } + + @Test + public void testStop() throws Exception { + RestServer.stop(); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/SandboxNorthboundTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/SandboxNorthboundTest.java new file mode 100644 index 0000000..d15f0cb --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/northbound/SandboxNorthboundTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2016 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.tool.sandbox.northbound; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import org.codehaus.enunciate.jaxrs.ResponseCode; +import org.codehaus.enunciate.jaxrs.StatusCodes; +import org.codehaus.enunciate.jaxrs.TypeHint; +import org.junit.runner.RunWith; +import org.opendaylight.nemo.tool.sandbox.SandBoxManager; + +import javax.ws.rs.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; +import java.util.ArrayList; +import java.util.List; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.api.support.membermodification.MemberModifier; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import static org.mockito.Mockito.*; +/** + * Created by zhangmeng on 2016/1/14. + */ + +public class SandboxNorthboundTest extends TestCase { + private SandboxNorthbound sandboxNorthbound; + @Before + public void setUp() throws Exception { + sandboxNorthbound = new SandboxNorthbound(); + } + + @Test + public void testCreate() throws Exception { + ExecuteRequest executeRequest = new ExecuteRequest(); + Assert.assertTrue(sandboxNorthbound.create(null,"test") != null); + Assert.assertTrue(sandboxNorthbound.create(null,executeRequest) != null); + } + + @Test + public void testDestroy() throws Exception { + Assert.assertTrue(sandboxNorthbound.destroy(null) != null); + } + + @Test + public void testGetXml() throws Exception { + Assert.assertTrue(sandboxNorthbound.getXml() != null); + } + + @Test + public void testGetHosts() throws Exception { + Assert.assertTrue(sandboxNorthbound.getHosts() == null); + } + + @Test + public void testGetSwitches() throws Exception { + Assert.assertTrue(sandboxNorthbound.getSwitches() != null); + } + + @Test + public void testGetLinks() throws Exception { + Assert.assertTrue(sandboxNorthbound.getLinks() != null); + } + + @Test + public void testGetExternals() throws Exception { + Assert.assertTrue(sandboxNorthbound.getExternals() == null); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/ConfigTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/ConfigTest.java new file mode 100644 index 0000000..4d665b9 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/ConfigTest.java @@ -0,0 +1,40 @@ +/* + * 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.tool.sandbox.utils; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangmeng on 2016/1/14. + */ +public class ConfigTest extends TestCase { + private Config config; + @Before + public void setUp() throws Exception { + config = new Config(); + } + + @Test + public void testAll() throws Exception{ + Assert.assertTrue(Config.getControllerSocket() != null); + Assert.assertTrue(Config.isPrintProcess() == false); + Assert.assertTrue(Config.getHostName() != null); + Assert.assertTrue(Config.getHostUser() != null); + Assert.assertTrue(Config.getHostPassword() != null); + Assert.assertTrue(Config.getConfigPath() != null); + Assert.assertTrue(Config.getConfigHostsFileName() != null); + Assert.assertTrue(Config.getConfigExternalsFileName() != null); + Assert.assertTrue(Config.getConfigLinksFileName() != null); + Assert.assertTrue(Config.getConfigNodesFileName() != null); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/FileUtilsTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/FileUtilsTest.java new file mode 100644 index 0000000..5030142 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/FileUtilsTest.java @@ -0,0 +1,30 @@ +/* + * 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.tool.sandbox.utils; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangmeng on 2016/1/14. + */ +public class FileUtilsTest extends TestCase { + private FileUtils fileUtils; + @Before + public void setUp() throws Exception { + fileUtils = new FileUtils(); + } + + @Test + public void testWrite() throws Exception { + FileUtils.write("home","test"); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/HexStringTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/HexStringTest.java new file mode 100644 index 0000000..7c7bf7d --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/HexStringTest.java @@ -0,0 +1,37 @@ +/* + * 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.tool.sandbox.utils; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangmeng on 2016/1/14. + */ +public class HexStringTest extends TestCase { + private HexString hexString; + @Test + public void testToHexString() throws Exception { + Assert.assertTrue(HexString.toHexString(1L,6) != null); + Assert.assertTrue(HexString.toHexString(1L) != null); + } + + @Test + public void testFromHexString() throws Exception { + Assert.assertTrue(HexString.fromHexString("22:32") != null); + } + + @Test + public void testToLong() throws Exception { +// System.out.println(HexString.toLong("11:22")); + Assert.assertTrue(HexString.toLong("11:22") != 0); + } +} \ No newline at end of file diff --git a/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/PropertyLoaderTest.java b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/PropertyLoaderTest.java new file mode 100644 index 0000000..281ad43 --- /dev/null +++ b/nemo-tools/sandbox/src/test/java/org/opendaylight/nemo/tool/sandbox/utils/PropertyLoaderTest.java @@ -0,0 +1,40 @@ +/* + * 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.tool.sandbox.utils; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +/** + * Created by zhangmeng on 2016/1/14. + */ +public class PropertyLoaderTest extends TestCase { + private PropertyLoader propertyLoader; + @Before + public void setUp() throws Exception { + propertyLoader = new PropertyLoader(); + } + + @Test + public void testLoadProperties() throws Exception { + PropertyLoader.loadProperties("home","no file!"); + } + + @Test + public void testReadLines() throws Exception { + PropertyLoader.readLines("home","no file!"); + } +} \ No newline at end of file