blob: eba7447ca645df1c3500fedcb6fd600d6709a3a5 [file] [log] [blame]
Teru68076a42013-06-27 14:57:49 -07001package net.onrc.onos.ofcontroller.core;
2
3import static org.junit.Assert.*;
4
5import net.onrc.onos.graph.GraphDBConnection;
6import net.onrc.onos.graph.GraphDBOperation;
7import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
8import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
9import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
10import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
11import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
12import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
13import org.easymock.EasyMock;
14import org.junit.After;
15import org.junit.Before;
16import org.junit.Test;
17import org.junit.runner.RunWith;
18import org.powermock.api.easymock.PowerMock;
19import org.powermock.core.classloader.annotations.PrepareForTest;
20import org.slf4j.LoggerFactory;
21import org.powermock.modules.junit4.PowerMockRunner;
22
23import com.thinkaurelius.titan.core.TitanFactory;
24import com.thinkaurelius.titan.core.TitanGraph;
25
26//Add Powermock preparation
27@RunWith(PowerMockRunner.class)
28@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
29public class INetMapTopologyObjectsIFlowEntryTest {
30
31 //The test network is ./titan/schema/test-network.xml
32
33 protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
34
35 String conf;
36 private GraphDBConnection conn = null;
37 private GraphDBOperation ope = null;
38 private TitanGraph titanGraph = null;
39 private IFlowEntry flowEntry = null;
40
41 @Before
42 public void setUp() throws Exception {
43 conf = "/dummy/path/to/db";
44
45 // Make mock cassandra DB
46 // Replace TitanFactory.open() to return mock DB
47 TestDatabaseManager.deleteTestDatabase();
48 titanGraph = TestDatabaseManager.getTestDatabase();
49 //TestDatabaseManager.populateTestData(titanGraph);
50 PowerMock.mockStatic(TitanFactory.class);
51 EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
52 PowerMock.replay(TitanFactory.class);
53
54 conn = GraphDBConnection.getInstance(conf);
55 ope = new GraphDBOperation(conn);
56
57 flowEntry = ope.newFlowEntry();
58 }
59
60 @After
61 public void tearDown() throws Exception {
62 titanGraph.shutdown();
63 TestDatabaseManager.deleteTestDatabase();
64 }
65
66 /**
67 * Desc:
68 * Test method for set and get FlowEntryId.
69 * Condition:
70 * N/A
71 * Expect:
72 * 1. Should set FlowEntryId.
73 * 2. Should get FlowEntryId.
74 */
75 @Test
76 public void testSetGetFlowEntryId() {
77 String flowEntryId = "xx";
78 flowEntry.setFlowEntryId(flowEntryId);
79 assertEquals(flowEntry.getFlowEntryId(), flowEntryId);
80 }
81
82 /**
83 * Desc:
84 * Test method for set and get SwitchDpid.
85 * Condition:
86 * N/A
87 * Expect:
88 * 1. Should set SwitchDpid.
89 * 2. Should get SwitchDpid.
90 */
91 @Test
92 public void testSetGetSwitchDpid() {
93 String switchDpid = "00:00:00:00:00:11";
94 flowEntry.setSwitchDpid(switchDpid);
95 assertEquals(flowEntry.getSwitchDpid(), switchDpid);
96 }
97
98 /**
99 * Desc:
100 * Test method for set and get UserState.
101 * Condition:
102 * N/A
103 * Expect:
104 * 1. Should set UserState.
105 * 2. Should get UserState.
106 */
107 @Test
108 public void testSetGetUserState() {
109 String userStete = "good";
110 flowEntry.setUserState(userStete);
111 assertEquals(flowEntry.getUserState(), userStete);
112 }
113
114 /**
115 * Desc:
116 * Test method for set and get SwitchState.
117 * Condition:
118 * N/A
119 * Expect:
120 * 1. Should set SwitchState.
121 * 2. Should get SwitchState.
122 */
123 @Test
124 public void testSetGetSwitchState() {
125 String switchStete = "ACTIVE";
126 flowEntry.setSwitchState(switchStete);
127 assertEquals(flowEntry.getSwitchState(), switchStete);
128 }
129
130 /**
131 * Desc:
132 * Test method for set and get ErrorStateType.
133 * Condition:
134 * N/A
135 * Expect:
136 * 1. Should set ErrorStateType.
137 * 2. Should get ErrorStateType.
138 */
139 @Test
140 public void testSetGetErrorStateType() {
141 String errorSteteType = "error";
142 flowEntry.setErrorStateType(errorSteteType);
143 assertEquals(flowEntry.getErrorStateType(), errorSteteType);
144 }
145
146 /**
147 * Desc:
148 * Test method for set and get ErrorStateCode.
149 * Condition:
150 * N/A
151 * Expect:
152 * 1. Should set ErrorStateCode.
153 * 2. Should get ErrorStateCode.
154 */
155 @Test
156 public void testSetGetErrorStateCode() {
157 String errorSteteCode = "error";
158 flowEntry.setErrorStateCode(errorSteteCode);
159 assertEquals(flowEntry.getErrorStateCode(), errorSteteCode);
160 }
161
162 /**
163 * Desc:
164 * Test method for set and get MatchInPort.
165 * Condition:
166 * N/A
167 * Expect:
168 * 1. Should set MatchInPort.
169 * 2. Should get MatchInPort.
170 */
171 @Test
172 public void testSetGetMatchInPort() {
173 Short inPort = 1;
174 flowEntry.setMatchInPort(inPort);
175 assertEquals(flowEntry.getMatchInPort(), inPort);
176 }
177
178 /**
179 * Desc:
180 * Test method for set and get MatchEthernetFrameType.
181 * Condition:
182 * N/A
183 * Expect:
184 * 1. Should set MatchEthernetFrameType.
185 * 2. Should get MatchEthernetFrameType.
186 */
187 @Test
188 public void testSetGetMatchEthernetFrameType() {
189 Short matchEthernetFrameType = 1;
190 flowEntry.setMatchEthernetFrameType(matchEthernetFrameType);
191 assertEquals(flowEntry.getMatchEthernetFrameType(), matchEthernetFrameType);
192 }
193
194 /**
195 * Desc:
196 * Test method for set and get MatchSrcMac.
197 * Condition:
198 * N/A
199 * Expect:
200 * 1. Should set MatchSrcMac.
201 * 2. Should get MatchSrcMac.
202 */
203 @Test
204 public void testSetGetMatchSrcMac() {
205 String matchSrcMac = "00:00:00:00:00:11";
206 flowEntry.setMatchSrcMac(matchSrcMac);
207 assertEquals(flowEntry.getMatchSrcMac(), matchSrcMac);
208 }
209
210 /**
211 * Desc:
212 * Test method for set and get MatchDstMac.
213 * Condition:
214 * N/A
215 * Expect:
216 * 1. Should set MatchDstMac.
217 * 2. Should get MatchDstMac.
218 */
219 @Test
220 public void testSetGetMatchDstMac() {
221 String matchDstMac = "00:00:00:00:00:11";
222 flowEntry.setMatchDstMac(matchDstMac);
223 assertEquals(flowEntry.getMatchDstMac(), matchDstMac);
224 }
225
226 /**
227 * Desc:
228 * Test method for set and get SrcIPv4Net.
229 * Condition:
230 * N/A
231 * Expect:
232 * 1. Should set SrcIPv4Net.
233 * 2. Should get SrcIPv4Net.
234 */
235 @Test
236 public void testSetGetMatchSrcIPv4Net() {
237 String srcIPv4Net = "192.168.0.1";
238 flowEntry.setMatchSrcIPv4Net(srcIPv4Net);
239 assertEquals(flowEntry.getMatchSrcIPv4Net(), srcIPv4Net);
240 }
241
242 /**
243 * Desc:
244 * Test method for set and get MatchDstIPv4Net.
245 * Condition:
246 * N/A
247 * Expect:
248 * 1. Should set MatchDstIPv4Net.
249 * 2. Should get MatchDstIPv4Net.
250 */
251 @Test
252 public void testSetGetMatchDstIPv4Net() {
253 String dstIPv4Net = "192.168.0.1";
254 flowEntry.setMatchDstIPv4Net(dstIPv4Net);
255 assertEquals(flowEntry.getMatchDstIPv4Net(), dstIPv4Net);
256 }
257
258 /**
259 * Desc:
260 * Test method for set and get ActionOutput.
261 * Condition:
262 * N/A
263 * Expect:
264 * 1. Should set ActionOutput.
265 * 2. Should get ActionOutput.
266 */
267 @Test
268 public void testSetGetActionOutput() {
269 Short actionOutput = 1;
270 flowEntry.setActionOutput(actionOutput);
271 assertEquals(flowEntry.getActionOutput(), actionOutput);
272 }
273
274 /**
275 * Desc:
276 * Test method for set and get FlowPath.
277 * Condition:
278 * N/A
279 * Expect:
280 * 1. Should set FlowPath.
281 * 2. Should get FlowPath.
282 */
283 @Test
284 public void testSetGetFlowPath() {
285 IFlowPath fp = ope.newFlowPath();
286 String flowId = "xx";
287 fp.setFlowId(flowId);
288 flowEntry.setFlow(fp);
289 IFlowPath fp2 = flowEntry.getFlow();
290 assertEquals(fp2.getFlowId(), flowId);
291 }
292
293 /**
294 * Desc:
295 * Test method for set and get Switch.
296 * Condition:
297 * N/A
298 * Expect:
299 * 1. Should set Switch.
300 * 2. Should get Switch.
301 */
302 @Test
303 public void testSetGetSwitch() {
304 String dpid = "00:00:00:00:00:22";
305 ISwitchObject sw1 = ope.newSwitch(dpid);
306 flowEntry.setSwitch(sw1);
307 ISwitchObject sw2 = flowEntry.getSwitch();
308 assertEquals(sw2, sw1);
309 }
310
311 /**
312 * Desc:
313 * Test method for set and get InPort.
314 * Condition:
315 * N/A
316 * Expect:
317 * 1. Should set InPort.
318 * 2. Should get InPort.
319 */
320 @Test
321 public void testSetGetInPort() {
322 String dpid = "00:00:00:00:00:22";
323 Short portNum = 4;
324 IPortObject port1 = ope.newPort(dpid, portNum);
325 flowEntry.setInPort(port1);
326 IPortObject port2 = flowEntry.getInPort();
327 assertEquals(port2, port1);
328 }
329
330 /**
331 * Desc:
332 * Test method for set and get OutPort.
333 * Condition:
334 * N/A
335 * Expect:
336 * 1. Should set OutPort.
337 * 2. Should get OutPort.
338 */
339 @Test
340 public void testSetGetOutPort() {
341 String dpid = "00:00:00:00:00:22";
342 Short portNum = 4;
343 IPortObject port1 = ope.newPort(dpid, portNum);
344 flowEntry.setOutPort(port1);
345 IPortObject port2 = flowEntry.getOutPort();
346 assertEquals(port2, port1);
347 }
348}