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
16 import org.opendaylight.nemo.tool.sandbox.models.Cache;
\r
17 import org.opendaylight.nemo.tool.sandbox.models.Connector;
\r
18 import org.opendaylight.nemo.tool.sandbox.models.Network;
\r
20 import org.junit.runner.RunWith;
\r
21 import org.powermock.api.mockito.PowerMockito;
\r
22 import org.powermock.api.support.membermodification.MemberMatcher;
\r
23 import org.powermock.api.support.membermodification.MemberModifier;
\r
24 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
25 import org.powermock.modules.junit4.PowerMockRunner;
\r
26 import org.opendaylight.nemo.tool.sandbox.CmdExecutor;
\r
28 import org.json.JSONArray;
\r
29 import org.json.JSONException;
\r
30 import org.json.JSONObject;
\r
31 import org.opendaylight.nemo.tool.sandbox.CmdExecutor;
\r
32 import org.opendaylight.nemo.tool.sandbox.utils.Config;
\r
33 import org.slf4j.Logger;
\r
34 import org.slf4j.LoggerFactory;
\r
39 * Created by Thomas Liu on 2016/1/14.
\r
41 @RunWith(PowerMockRunner.class)
\r
42 @PrepareForTest({CmdExecutor.class})
\r
43 public class NetworkTest extends TestCase {
\r
44 private Network networkTest;
\r
47 public void setUp() throws Exception {
\r
48 networkTest = new Network();
\r
53 public void testAddHost() throws Exception {
\r
54 networkTest.addHost(new Cache("src1","1"));
\r
55 networkTest.addHost(new Cache("dst2","1"));
\r
59 public void testAddSwitch() throws Exception {
\r
60 networkTest.addSwitch(new Switch("dst1", 1L));
\r
61 networkTest.addSwitch(new Switch("src2", 1L));
\r
62 networkTest.addSwitch(new Switch("src3", 1L));
\r
63 networkTest.addSwitch(new Switch("dst3", 1L));
\r
67 public void testAddLink() throws Exception {
\r
68 networkTest.addLink(new Link(new Connector("src1", 1), new Connector("dst1", 2)));
\r
69 networkTest.addLink(new Link(new Connector("src2", 1), new Connector("dst2", 2)));
\r
70 networkTest.addLink(new Link(new Connector("src3", 1), new Connector("dst3", 2)));
\r
75 public void testExecute() throws Exception {
\r
76 PowerMockito.mockStatic(CmdExecutor.class);
\r
77 PowerMockito.when(CmdExecutor.open()).thenReturn(true);
\r
78 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
79 PowerMockito.doNothing().when(CmdExecutor.class);
\r
80 CmdExecutor.close();
\r
81 Assert.assertNotNull(networkTest.execute("cache", "command"));
\r
86 public void testInstall() throws Exception {
\r
88 networkTest.install();
\r
93 public void testUninstall() throws Exception {
\r
94 PowerMockito.mockStatic(CmdExecutor.class);
\r
95 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
96 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
97 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
98 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
99 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
100 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
102 networkTest.uninstall();
\r
107 public void testEchoConfig() throws Exception {
\r
108 PowerMockito.mockStatic(CmdExecutor.class);
\r
109 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
110 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
111 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
112 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
113 PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");
\r
115 networkTest.echoConfig();
\r
117 //test hostJsonNode()
\r
124 public void testInnerLinkJsonNode() throws Exception {
\r
126 Assert.assertNotNull(networkTest.innerLinkJsonNode());
\r