Search in sources :

Example 26 with DefaultPort

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());
}
Also used : Device(org.onosproject.net.Device) DefaultDevice(org.onosproject.net.DefaultDevice) DefaultPort(org.onosproject.net.DefaultPort) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) AbstractEventTest(org.onosproject.event.AbstractEventTest) Test(org.junit.Test)

Example 27 with DefaultPort

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));
    }
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) JsonObject(com.eclipsesource.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString) WebTarget(javax.ws.rs.client.WebTarget) DefaultPort(org.onosproject.net.DefaultPort) Test(org.junit.Test)

Aggregations

DefaultPort (org.onosproject.net.DefaultPort)27 Test (org.junit.Test)19 Port (org.onosproject.net.Port)15 Device (org.onosproject.net.Device)12 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)10 DefaultDevice (org.onosproject.net.DefaultDevice)8 DeviceEvent (org.onosproject.net.device.DeviceEvent)8 PortNumber (org.onosproject.net.PortNumber)7 Annotations (org.onosproject.net.Annotations)6 ConnectPoint (org.onosproject.net.ConnectPoint)5 DeviceId (org.onosproject.net.DeviceId)4 ProviderId (org.onosproject.net.provider.ProviderId)4 Iterator (java.util.Iterator)3 Frequency (org.onlab.util.Frequency)3 HostId (org.onosproject.net.HostId)3 PortDescription (org.onosproject.net.device.PortDescription)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Supplier (com.google.common.base.Supplier)2 Sets (com.google.common.collect.Sets)2