/** Reset the channel mock and set basic method call expectations */ void resetChannel() { reset(channel); expect(channel.newPromise()).andAnswer(new IAnswer<ChannelPromise>() { @Override public ChannelPromise answer() throws Throwable { return new DefaultChannelPromise(channel); } }).anyTimes(); eventLoop = new TestEventLoop(); expect(channel.eventLoop()).andReturn(eventLoop).anyTimes(); expect(channel.pipeline()).andReturn(pipeline).anyTimes(); expect(channel.remoteAddress()).andReturn(null).anyTimes(); }
@Before public void setUp() throws Exception { factory = OFFactories.getFactory(OFVersion.OF_13); switchId = DatapathId.of(1); timer = new HashedWheelTimer(); channel = EasyMock.createMock(Channel.class); IDebugCounterService debugCounterService = new DebugCounterServiceImpl(); debugCounterService.registerModule(OFConnectionCounters.COUNTER_MODULE); conn = new OFConnection(switchId, factory, channel, OFAuxId.MAIN, debugCounterService, timer); eventLoop = new TestEventLoop(); expect(channel.eventLoop()).andReturn(eventLoop).anyTimes(); }
/** Reset the channel mock and set basic method call expectations */ void resetChannel() { reset(channel); expect(channel.newPromise()).andAnswer(new IAnswer<ChannelPromise>() { @Override public ChannelPromise answer() throws Throwable { return new DefaultChannelPromise(channel); } }).anyTimes(); eventLoop = new TestEventLoop(); expect(channel.eventLoop()).andReturn(eventLoop).anyTimes(); expect(channel.pipeline()).andReturn(pipeline).anyTimes(); expect(channel.remoteAddress()).andReturn(InetSocketAddress.createUnresolved("1.1.1.1", 80)).anyTimes(); }
@Before public void setUp() throws Exception { setUpFeaturesReply(); switchManager = createMock(IOFSwitchManager.class); connectionListener = createMock(IOFConnectionListener.class); newConnectionListener = createMock(INewOFConnectionListener.class); newConnection = new Capture<IOFConnectionBackend>(); newFeaturesReply = new Capture<OFFeaturesReply>(); eventLoop = new TestEventLoop(); ctx = createMock(ChannelHandlerContext.class); channel = createMock(Channel.class); timer = new HashedWheelTimer(); exceptionEventCapture = new Capture<Throwable>(CaptureType.ALL); pipeline = createMock(ChannelPipeline.class); writeCapture = new Capture<List<OFMessage>>(CaptureType.ALL); seenXids = null; // TODO: should mock IDebugCounterService and make sure // the expected counters are updated. debugCounterService = new DebugCounterServiceImpl(); debugCounterService.registerModule(OFConnectionCounters.COUNTER_MODULE); SwitchManagerCounters counters = new SwitchManagerCounters(debugCounterService); expect(switchManager.getCounters()).andReturn(counters).anyTimes(); replay(switchManager); handler = new OFChannelHandler(switchManager, newConnectionListener, pipeline, debugCounterService, /* 62 is OF versions 1.0 thru 1.4 in decimal */ timer, Collections.singletonList(U32.of(62)), OFFactories.getFactory(OFVersion.OF_14)); verify(switchManager); reset(switchManager); resetChannel(); // replay controller. Reset it if you need more specific behavior replay(switchManager); // Mock ctx and channelStateEvent expect(ctx.channel()).andReturn(channel).anyTimes(); expect(ctx.fireExceptionCaught(capture(exceptionEventCapture))).andReturn(ctx).anyTimes(); replay(ctx); /* Setup an exception event capture on the channel. Right now * we only expect exception events to be send up the channel. * However, it's easy to extend to other events if we need it */ expect(pipeline.get(OFMessageDecoder.class)).andReturn(new OFMessageDecoder()).anyTimes(); replay(pipeline); }
@Before public void setUp() throws Exception { setUpFeaturesReply(); switchManager = createMock(IOFSwitchManager.class); connectionListener = createMock(IOFConnectionListener.class); newConnectionListener = createMock(INewOFConnectionListener.class); newConnection = new Capture<IOFConnectionBackend>(); newFeaturesReply = new Capture<OFFeaturesReply>(); eventLoop = new TestEventLoop(); ctx = createMock(ChannelHandlerContext.class); channel = createMock(Channel.class); timer = new HashedWheelTimer(); exceptionEventCapture = new Capture<Throwable>(CaptureType.ALL); pipeline = createMock(ChannelPipeline.class); writeCapture = new Capture<List<OFMessage>>(CaptureType.ALL); seenXids = null; // TODO: should mock IDebugCounterService and make sure // the expected counters are updated. debugCounterService = new DebugCounterServiceImpl(); debugCounterService.registerModule(OFConnectionCounters.COUNTER_MODULE); SwitchManagerCounters counters = new SwitchManagerCounters(debugCounterService); expect(switchManager.getCounters()).andReturn(counters).anyTimes(); replay(switchManager); handler = new OFChannelHandler(switchManager, newConnectionListener, pipeline, debugCounterService, timer, Collections.singletonList(U32.of(0)), OFFactories.getFactory(OFVersion.OF_14)); verify(switchManager); reset(switchManager); resetChannel(); // replay controller. Reset it if you need more specific behavior replay(switchManager); // Mock ctx and channelStateEvent expect(ctx.channel()).andReturn(channel).anyTimes(); expect(ctx.fireExceptionCaught(capture(exceptionEventCapture))).andReturn(ctx).anyTimes(); replay(ctx); /* Setup an exception event capture on the channel. Right now * we only expect exception events to be send up the channel. * However, it's easy to extend to other events if we need it */ expect(pipeline.get(OFMessageDecoder.class)).andReturn(new OFMessageDecoder()).anyTimes(); replay(pipeline); }