Added test files for nemo-tool
[nemo.git] / nemo-tools / sandbox / src / test / java / org / opendaylight / nemo / tool / sandbox / models / VirtualMachineTest.java
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 (file)
index 0000000..f405927
--- /dev/null
@@ -0,0 +1,68 @@
+/*\r
+ * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.nemo.tool.sandbox.models;\r
+\r
+import junit.framework.TestCase;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import static org.mockito.Mockito.*;\r
+import static org.junit.Assert.*;\r
+\r
+import org.opendaylight.nemo.tool.sandbox.CmdExecutor;\r
+import org.opendaylight.nemo.tool.sandbox.models.VirtualMachine;\r
+\r
+import java.lang.reflect.Method;\r
+import java.lang.reflect.Field;\r
+\r
+import org.junit.runner.RunWith;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.api.support.membermodification.MemberMatcher;\r
+import org.powermock.api.support.membermodification.MemberModifier;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
+import org.opendaylight.nemo.tool.sandbox.CmdExecutor;\r
+\r
+/**\r
+ * Created by Thomas Liu on 2016/1/14.\r
+ */\r
+@RunWith(PowerMockRunner.class)\r
+@PrepareForTest({CmdExecutor.class})\r
+public class VirtualMachineTest extends TestCase {\r
+    String name,uuId;\r
+    Cache cacheTest;\r
+    private VirtualMachine virtualMachineTest;\r
+    private Connector connector;\r
+    private Class class1;\r
+    private Method method;\r
+    @Before\r
+    public void setUp() throws Exception {\r
+        name = new String("name1");\r
+        uuId = new String("11111111-1111-1111-1111-111111111111");\r
+        virtualMachineTest = new VirtualMachine(name,uuId);\r
+        org.opendaylight.nemo.tool.sandbox.models.Connector connector = mock(org.opendaylight.nemo.tool.sandbox.models.Connector.class);\r
+        virtualMachineTest.addConnectors(connector);\r
+        class1 = VirtualMachine.class;\r
+\r
+    }\r
+\r
+    @Test\r
+    public void testGenerateCommands() throws Exception {\r
+        method = class1.getDeclaredMethod("generateCommands",new Class[]{});\r
+        method.setAccessible(true);\r
+        Assert.assertNotNull(method.invoke(virtualMachineTest));\r
+    }\r
+\r
+    @Test\r
+    public void testUninstall() throws Exception {\r
+        PowerMockito.mockStatic(CmdExecutor.class);\r
+        PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
+        virtualMachineTest.uninstall();\r
+\r
+    }\r
+}
\ No newline at end of file