@Before public void setUp() { coreService = createMock(CoreService.class); expect(coreService.registerApplication(appId.name())).andReturn(appId).anyTimes(); replay(coreService); provider.cfgService = new ComponentConfigAdapter(); provider.coreService = coreService; provider.providerRegistry = hostRegistry; provider.topologyService = topoService; provider.packetService = packetService; provider.deviceService = deviceService; provider.hostService = hostService; provider.activate(CTX_FOR_NO_REMOVE); provider.eventHandler = MoreExecutors.newDirectExecutorService(); }
@Test public void removeHostByDeviceOffline() { provider.modified(CTX_FOR_REMOVE); testProcessor.process(new TestArpPacketContext(DEV1)); testProcessor.process(new TestArpPacketContext(DEV4)); Device device = new DefaultDevice( ProviderId.NONE, deviceId(DEV1), SWITCH, "m", "h", "s", "n", new ChassisId(0L)); deviceService.listener.event(new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device)); assertEquals("incorrect remove count", 1, providerService.removeCount); device = new DefaultDevice( ProviderId.NONE, deviceId(DEV4), SWITCH, "m", "h", "s", "n", new ChassisId(0L)); deviceService.listener.event(new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device)); assertEquals("incorrect remove count", 2, providerService.removeCount); }
@Test public void removeHostByDevicePortDown() { provider.modified(CTX_FOR_REMOVE); testProcessor.process(new TestArpPacketContext(DEV1)); testProcessor.process(new TestArpPacketContext(DEV4)); Device device = new DefaultDevice( ProviderId.NONE, deviceId(DEV1), SWITCH, "m", "h", "s", "n", new ChassisId(0L)); deviceService.listener.event( new DeviceEvent(PORT_UPDATED, device, new DefaultPort(device, portNumber(INPORT), false))); assertEquals("incorrect remove count", 1, providerService.removeCount); device = new DefaultDevice( ProviderId.NONE, deviceId(DEV4), SWITCH, "m", "h", "s", "n", new ChassisId(0L)); deviceService.listener.event( new DeviceEvent(PORT_UPDATED, device, new DefaultPort(device, portNumber(INPORT), false))); assertEquals("incorrect remove count", 2, providerService.removeCount); }
@After public void tearDown() { provider.deactivate(); provider.coreService = null; provider.providerRegistry = null; }