Open Kilda Java Documentation
AbstractVerificationCommandTest.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.floodlight.command.flow;
17 
18 import static org.easymock.EasyMock.expect;
19 import static org.easymock.EasyMock.replay;
20 
30 
31 import net.floodlightcontroller.core.IOFSwitch;
32 import net.floodlightcontroller.core.internal.IOFSwitchService;
33 import net.floodlightcontroller.core.module.FloodlightModuleContext;
34 import net.floodlightcontroller.threadpool.IThreadPoolService;
35 import org.easymock.EasyMock;
36 import org.junit.Before;
37 import org.projectfloodlight.openflow.types.DatapathId;
38 import org.projectfloodlight.openflow.types.U64;
39 
40 public abstract class AbstractVerificationCommandTest {
41  private final String correlationIdTemplate = String.format(
42  "%s-%%d", AbstractVerificationCommandTest.class.getCanonicalName());
43  private int testIndex = 0;
44 
45  protected final DatapathId sourceSwitchId = DatapathId.of(0x00ff000001L);
46  protected final int sourcePort = 15;
47  protected IOFSwitch sourceSwitch = EasyMock.createMock(IOFSwitch.class);
48  protected final DatapathId destSwitchId = DatapathId.of(0x00ff000002L);
49  protected final int destPort = sourcePort + 5;
50  protected IOFSwitch destSwitch = EasyMock.createMock(IOFSwitch.class);
51 
53 
54  protected KafkaMessageProducer kafkaProducerService = EasyMock.createMock(KafkaMessageProducer.class);
55  protected OfBatchService ioService = EasyMock.createMock(OfBatchService.class);
56  protected IOFSwitchService switchService = EasyMock.createMock(IOFSwitchService.class);
58  protected IThreadPoolService threadPoolService = EasyMock.createMock(IThreadPoolService.class);
59 
60  @Before
61  public void setUp() throws Exception {
62  FloodlightModuleContext moduleContext = new FloodlightModuleContext();
63  moduleContext.addService(KafkaMessageProducer.class, kafkaProducerService);
64  moduleContext.addService(OfBatchService.class, ioService);
65  moduleContext.addService(IOFSwitchService.class, switchService);
66  moduleContext.addService(FlowVerificationService.class, flowVerificationService);
67  moduleContext.addService(IThreadPoolService.class, threadPoolService);
68 
69  context = new CommandContext(moduleContext, String.format(correlationIdTemplate, testIndex++));
70 
71  expect(switchService.getSwitch(sourceSwitchId)).andReturn(sourceSwitch).anyTimes();
72  expect(switchService.getActiveSwitch(sourceSwitchId)).andReturn(sourceSwitch).anyTimes();
73  expect(switchService.getSwitch(destSwitchId)).andReturn(destSwitch).anyTimes();
74  expect(switchService.getActiveSwitch(destSwitchId)).andReturn(destSwitch).anyTimes();
75  replay(switchService);
76 
77  expect(sourceSwitch.getLatency()).andReturn(U64.ZERO).anyTimes();
78  expect(destSwitch.getLatency()).andReturn(U64.ZERO).anyTimes();
79  }
80 
82  String flowId = "junit-flow";
83  Flow flow = new Flow(
84  flowId, 1000, false, "unit test flow",
85  new SwitchId(sourceSwitchId.toString()), sourcePort, 0x100,
86  new SwitchId(destSwitchId.toString()), destPort, 0x101);
87  FlowVerificationRequest request = new FlowVerificationRequest(flowId, 1000);
88  return new UniFlowVerificationRequest(request, flow, FlowDirection.FORWARD);
89  }
90 }
net
Definition: plan-b.py:46