b8b9032fd4275e55b066dacab5dc7c296c024344
[nemo.git] / nemo-tools / sandbox / src / test / java / org / opendaylight / nemo / tool / sandbox / models / NetworkTest.java
1 /*\r
2  * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved.\r
3  *\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
7  */\r
8 package org.opendaylight.nemo.tool.sandbox.models;\r
9 \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
19 \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
27 \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
35 \r
36 \r
37 \r
38 /**\r
39  * Created by Thomas Liu on 2016/1/14.\r
40  */\r
41 @RunWith(PowerMockRunner.class)\r
42 @PrepareForTest({CmdExecutor.class})\r
43 public class NetworkTest extends TestCase {\r
44     private Network networkTest;\r
45 \r
46     @Before\r
47     public void setUp() throws Exception {\r
48         networkTest = new Network();\r
49 \r
50     }\r
51 \r
52     @Test\r
53     public void testAddHost() throws Exception {\r
54         networkTest.addHost(new Cache("src1","1"));\r
55         networkTest.addHost(new Cache("dst2","1"));\r
56     }\r
57 \r
58     @Test\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
64     }\r
65 \r
66     @Test\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
71 \r
72     }\r
73 \r
74     @Test\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
82 \r
83     }\r
84 \r
85     @Test\r
86     public void testInstall() throws Exception {\r
87         //test traversal\r
88         networkTest.install();\r
89 \r
90     }\r
91 \r
92     @Test\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
101 \r
102         networkTest.uninstall();\r
103 \r
104     }\r
105 \r
106     @Test\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
114 \r
115         networkTest.echoConfig();\r
116 \r
117         //test hostJsonNode()\r
118 \r
119 \r
120 \r
121     }\r
122 \r
123     @Test\r
124     public void testInnerLinkJsonNode() throws Exception {\r
125 \r
126         Assert.assertNotNull(networkTest.innerLinkJsonNode());\r
127 \r
128 \r
129     }\r
130 }