use of org.onosproject.net.DefaultPort in project onos by opennetworkinglab.
the class DeviceEventTest method withTime.
@Override
@Test
public void withTime() {
Device device = createDevice();
Port port = new DefaultPort(device, PortNumber.portNumber(123), true);
DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device, port, 123L);
validateEvent(event, DeviceEvent.Type.DEVICE_ADDED, device, 123L);
assertEquals("incorrect port", port, event.port());
}
use of org.onosproject.net.DefaultPort in project onos by opennetworkinglab.
the class DevicesResourceTest method testDeviceAndPorts.
/**
* Tests the result of a rest api GET for the ports of a single device.
*/
@Test
public void testDeviceAndPorts() {
String deviceIdString = "testdevice";
DeviceId deviceId = did(deviceIdString);
Device device = device(deviceIdString);
Port port1 = new DefaultPort(device, portNumber(1), true);
Port port2 = new DefaultPort(device, portNumber(2), true);
Port port3 = new DefaultPort(device, portNumber(3), true);
List<Port> ports = ImmutableList.of(port1, port2, port3);
expect(mockDeviceService.getDevice(deviceId)).andReturn(device).once();
expect(mockDeviceService.getPorts(deviceId)).andReturn(ports).once();
replay(mockDeviceService);
expect(mockDriverService.getDriver(deviceId)).andReturn(driver).anyTimes();
replay(mockDriverService);
WebTarget wt = target();
String response = wt.path("devices/" + deviceId + "/ports").request().get(String.class);
JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesDevice(device));
JsonArray jsonPorts = result.get("ports").asArray();
assertThat(jsonPorts.size(), is(3));
for (int portIndex = 0; portIndex < jsonPorts.size(); portIndex++) {
JsonObject jsonPort = jsonPorts.get(portIndex).asObject();
assertThat(jsonPort.get("port").asString(), is(Integer.toString(portIndex + 1)));
assertThat(jsonPort.get("isEnabled").asBoolean(), is(true));
assertThat(jsonPort.get("type").asString(), equalTo("copper"));
assertThat(jsonPort.get("portSpeed").asLong(), is(1000L));
}
}
Aggregations