@Test public final void testGetPort() { putDevice(DID1, SW1); putDevice(DID2, SW1); List<PortDescription> pds = Arrays.<PortDescription>asList( new DefaultPortDescription(P1, true), new DefaultPortDescription(P2, false)); deviceStore.updatePorts(PID, DID1, pds); Port port1 = deviceStore.getPort(DID1, P1); assertEquals(P1, port1.number()); assertTrue("Port is enabled", port1.isEnabled()); Port port2 = deviceStore.getPort(DID1, P2); assertEquals(P2, port2.number()); assertFalse("Port is disabled", port2.isEnabled()); Port port3 = deviceStore.getPort(DID1, P3); assertNull("P3 not expected", port3); }
@Test public final void testRemoveDevice() { putDevice(DID1, SW1, A1); List<PortDescription> pds = Arrays.<PortDescription>asList(new DefaultPortDescription(P1, true, A2)); deviceStore.updatePorts(PID, DID1, pds); putDevice(DID2, SW1); assertEquals(2, deviceStore.getDeviceCount()); assertEquals(1, deviceStore.getPorts(DID1).size()); assertAnnotationsEquals(deviceStore.getDevice(DID1).annotations(), A1); assertAnnotationsEquals(deviceStore.getPort(DID1, P1).annotations(), A2); Capture<InternalDeviceEvent> message = new Capture<>(); Capture<MessageSubject> subject = new Capture<>(); Capture<Function<InternalDeviceEvent, byte[]>> encoder = new Capture<>(); resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); DeviceEvent event = deviceStore.removeDevice(DID1); assertEquals(DEVICE_REMOVED, event.type()); assertDevice(DID1, SW1, event.subject()); assertEquals(1, deviceStore.getDeviceCount()); assertEquals(0, deviceStore.getPorts(DID1).size()); verify(clusterCommunicator); // TODO: verify broadcast message assertTrue(message.hasCaptured()); // putBack Device, Port w/o annotation putDevice(DID1, SW1); List<PortDescription> pds2 = Arrays.<PortDescription>asList(new DefaultPortDescription(P1, true)); deviceStore.updatePorts(PID, DID1, pds2); // annotations should not survive assertEquals(2, deviceStore.getDeviceCount()); assertEquals(1, deviceStore.getPorts(DID1).size()); assertAnnotationsEquals(deviceStore.getDevice(DID1).annotations()); assertAnnotationsEquals(deviceStore.getPort(DID1, P1).annotations()); }