Open Kilda Java Documentation
VerificationListenCommandTest.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.anyObject;
19 import static org.easymock.EasyMock.capture;
20 import static org.easymock.EasyMock.eq;
21 import static org.easymock.EasyMock.expect;
22 import static org.easymock.EasyMock.expectLastCall;
23 import static org.easymock.EasyMock.newCapture;
24 import static org.easymock.EasyMock.replay;
25 import static org.easymock.EasyMock.reset;
26 import static org.easymock.EasyMock.verify;
27 
35 
36 import org.easymock.Capture;
37 import org.easymock.CaptureType;
38 import org.easymock.EasyMock;
39 import org.junit.After;
40 import org.junit.Assert;
41 import org.junit.Before;
42 import org.junit.Test;
43 import org.projectfloodlight.openflow.protocol.ver12.OFFactoryVer12;
44 import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
45 
46 import java.util.concurrent.ScheduledExecutorService;
47 
49  @Before
50  @Override
51  public void setUp() throws Exception {
52  super.setUp();
53  ScheduledExecutorService scheduler = EasyMock.createMock(ScheduledExecutorService.class);
54  expect(threadPoolService.getScheduledExecutor()).andReturn(scheduler).anyTimes();
55  replay(threadPoolService);
56 
57  expect(destSwitch.getOFFactory()).andReturn(new OFFactoryVer13()).anyTimes();
58  replay(destSwitch);
59  }
60 
61  @After
62  public void tearDown() {
64  }
65 
66  @Test(expected = InsufficientCapabilitiesException.class)
67  public void lackCapabilities() throws Exception {
68  reset(destSwitch);
69  expect(destSwitch.getOFFactory()).andReturn(new OFFactoryVer12()).anyTimes();
70  replay(destSwitch);
71 
73  try {
74  new VerificationListenCommand(context, request);
75  } finally {
76  verify(destSwitch);
77  }
78  }
79 
80  @Test
81  public void run() throws Exception {
84 
86  expectLastCall().once();
88 
89  subject.run();
90 
92  }
93 
94  @Test
95  public void packetIn() throws Exception {
98 
99  replay(sourceSwitch);
101  Assert.assertFalse("False positive VerificationData match", subject.packetIn(destSwitch, shouldSkip));
102 
103  kafkaProducerService.postMessage(eq(Topic.FLOW), anyObject());
104  expectLastCall().once();
105  replay(kafkaProducerService);
106 
107  VerificationData shouldMatch = VerificationData.of(request);
108  Assert.assertTrue("False negative VerificationData match", subject.packetIn(destSwitch, shouldMatch));
109 
110  verify(kafkaProducerService);
111  }
112 
113  @Test
114  public void timeout() throws Exception {
117 
119  expectLastCall().once();
120  replay(flowVerificationService);
121 
122  Capture<InfoMessage> outputCapture = newCapture(CaptureType.LAST);
123 
124  kafkaProducerService.postMessage(eq(Topic.FLOW), capture(outputCapture));
125  expectLastCall().once();
126  replay(kafkaProducerService);
127 
129  subject);
130  timeout.run();
131 
133 
134  InfoMessage output = outputCapture.getValue();
136 
137  Assert.assertEquals(response.getError(), FlowVerificationErrorCode.TIMEOUT);
138  }
139 }
static VerificationData of(DecodedJWT token)
void postMessage(final String topic, final Message message)
static final String FLOW
Definition: Topic.java:25