X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=nemo-tools%2Fsandbox%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnemo%2Ftool%2Fsandbox%2Fmodels%2FVirtualMachineTest.java;fp=nemo-tools%2Fsandbox%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnemo%2Ftool%2Fsandbox%2Fmodels%2FVirtualMachineTest.java;h=f405927fc6ed3ee4658d1b62991b3978ca641acc;hb=ce695475991f7c85cb9126698d7f91e61e1899ff;hp=0000000000000000000000000000000000000000;hpb=91df278fc26e0186a962e5029b200703d24a204a;p=nemo.git 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