2 * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.nemo.tool.sandbox.models;
\r
10 import junit.framework.TestCase;
\r
11 import org.junit.Assert;
\r
12 import org.junit.Before;
\r
13 import org.junit.Test;
\r
14 import static org.mockito.Mockito.*;
\r
15 import static org.junit.Assert.*;
\r
17 import org.opendaylight.nemo.tool.sandbox.CmdExecutor;
\r
18 import org.opendaylight.nemo.tool.sandbox.models.VirtualMachine;
\r
20 import java.lang.reflect.Method;
\r
21 import java.lang.reflect.Field;
\r
23 import org.junit.runner.RunWith;
\r
24 import org.powermock.api.mockito.PowerMockito;
\r
25 import org.powermock.api.support.membermodification.MemberMatcher;
\r
26 import org.powermock.api.support.membermodification.MemberModifier;
\r
27 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
28 import org.powermock.modules.junit4.PowerMockRunner;
\r
29 import org.opendaylight.nemo.tool.sandbox.CmdExecutor;
\r
32 * Created by Thomas Liu on 2016/1/14.
\r
34 @RunWith(PowerMockRunner.class)
\r
35 @PrepareForTest({CmdExecutor.class})
\r
36 public class VirtualMachineTest extends TestCase {
\r
39 private VirtualMachine virtualMachineTest;
\r
40 private Connector connector;
\r
41 private Class class1;
\r
42 private Method method;
\r
44 public void setUp() throws Exception {
\r
45 name = new String("name1");
\r
46 uuId = new String("11111111-1111-1111-1111-111111111111");
\r
47 virtualMachineTest = new VirtualMachine(name,uuId);
\r
48 org.opendaylight.nemo.tool.sandbox.models.Connector connector = mock(org.opendaylight.nemo.tool.sandbox.models.Connector.class);
\r
49 virtualMachineTest.addConnectors(connector);
\r
50 class1 = VirtualMachine.class;
\r
55 public void testGenerateCommands() throws Exception {
\r
56 method = class1.getDeclaredMethod("generateCommands",new Class[]{});
\r
57 method.setAccessible(true);
\r
58 Assert.assertNotNull(method.invoke(virtualMachineTest));
\r
62 public void testUninstall() throws Exception {
\r
63 PowerMockito.mockStatic(CmdExecutor.class);
\r
64 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
65 virtualMachineTest.uninstall();
\r