Search in sources :

Example 31 with NetworkId

use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.

the class VirtualNetworkWebResourceTest method testDeleteVirtualLink.

/**
 * Tests removing a virtual link with DELETE request.
 */
@Test
public void testDeleteVirtualLink() {
    NetworkId networkId = networkId3;
    mockVnetAdminService.removeVirtualLink(networkId, cp22, cp11);
    expectLastCall();
    replay(mockVnetAdminService);
    WebTarget wt = target().property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
    InputStream jsonStream = VirtualNetworkWebResourceTest.class.getResourceAsStream("post-virtual-link.json");
    String reqLocation = "vnets/" + networkId.toString() + "/links";
    Response response = wt.path(reqLocation).request().method("DELETE", Entity.json(jsonStream));
    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
    verify(mockVnetAdminService);
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Example 32 with NetworkId

use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.

the class VirtualNetworkWebResourceTest method testPostVirtualPortNullJsonStream.

/**
 * Tests adding of a null virtual port using POST via JSON stream.
 */
@Test
public void testPostVirtualPortNullJsonStream() {
    NetworkId networkId = networkId3;
    DeviceId deviceId = devId2;
    replay(mockVnetAdminService);
    WebTarget wt = target();
    try {
        String reqLocation = "vnets/" + networkId.toString() + "/devices/" + deviceId.toString() + "/ports";
        wt.path(reqLocation).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(null), String.class);
        fail("POST of null virtual port did not throw an exception");
    } catch (BadRequestException ex) {
        assertThat(ex.getMessage(), containsString("HTTP 400 Bad Request"));
    }
    verify(mockVnetAdminService);
}
Also used : DeviceId(org.onosproject.net.DeviceId) BadRequestException(javax.ws.rs.BadRequestException) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Example 33 with NetworkId

use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.

the class VirtualNetworkWebResourceTest method testPostVirtualPort.

/**
 * Tests adding of new virtual port using POST via JSON stream.
 */
@Test
public void testPostVirtualPort() {
    NetworkId networkId = networkId3;
    DeviceId deviceId = devId22;
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    Device physDevice = new DefaultDevice(null, DeviceId.deviceId("dev1"), null, null, null, null, null, null, annotations);
    ConnectPoint cp1 = new ConnectPoint(physDevice.id(), portNumber(1));
    expect(mockVnetAdminService.createVirtualPort(networkId, deviceId, portNumber(22), cp1)).andReturn(vport22);
    replay(mockVnetAdminService);
    WebTarget wt = target();
    InputStream jsonStream = VirtualNetworkWebResourceTest.class.getResourceAsStream("post-virtual-port.json");
    String reqLocation = "vnets/" + networkId.toString() + "/devices/" + deviceId.toString() + "/ports";
    Response response = wt.path(reqLocation).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(jsonStream));
    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_CREATED));
    verify(mockVnetAdminService);
}
Also used : Response(javax.ws.rs.core.Response) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) InputStream(java.io.InputStream) DefaultDevice(org.onosproject.net.DefaultDevice) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) ConnectPoint(org.onosproject.net.ConnectPoint) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Example 34 with NetworkId

use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.

the class VirtualNetworkWebResourceTest method testPostVirtualDevice.

/**
 * Tests adding of new virtual device using POST via JSON stream.
 */
@Test
public void testPostVirtualDevice() {
    NetworkId networkId = networkId3;
    DeviceId deviceId = devId2;
    expect(mockVnetAdminService.createVirtualDevice(networkId, deviceId)).andReturn(vdev2);
    expectLastCall();
    replay(mockVnetAdminService);
    WebTarget wt = target();
    InputStream jsonStream = VirtualNetworkWebResourceTest.class.getResourceAsStream("post-virtual-device.json");
    String reqLocation = "vnets/" + networkId.toString() + "/devices";
    Response response = wt.path(reqLocation).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(jsonStream));
    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_CREATED));
    String location = response.getLocation().getPath();
    assertThat(location, Matchers.startsWith("/" + reqLocation + "/" + vdev2.id().toString()));
    verify(mockVnetAdminService);
}
Also used : Response(javax.ws.rs.core.Response) DeviceId(org.onosproject.net.DeviceId) InputStream(java.io.InputStream) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Example 35 with NetworkId

use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.

the class VirtualNetworkWebResourceTest method testPostVirtualLink.

/**
 * Tests adding of new virtual link using POST via JSON stream.
 */
@Test
public void testPostVirtualLink() {
    NetworkId networkId = networkId3;
    expect(mockVnetAdminService.createVirtualLink(networkId, cp22, cp11)).andReturn(vlink1);
    replay(mockVnetAdminService);
    WebTarget wt = target();
    InputStream jsonStream = VirtualNetworkWebResourceTest.class.getResourceAsStream("post-virtual-link.json");
    String reqLocation = "vnets/" + networkId.toString() + "/links";
    Response response = wt.path(reqLocation).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(jsonStream));
    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_CREATED));
    String location = response.getLocation().getPath();
    assertThat(location, Matchers.startsWith("/" + reqLocation));
    verify(mockVnetAdminService);
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Aggregations

NetworkId (org.onosproject.incubator.net.virtual.NetworkId)50 DeviceId (org.onosproject.net.DeviceId)23 Test (org.junit.Test)21 WebTarget (javax.ws.rs.client.WebTarget)20 Matchers.containsString (org.hamcrest.Matchers.containsString)20 HostResourceTest (org.onosproject.rest.resources.HostResourceTest)20 LinksResourceTest (org.onosproject.rest.resources.LinksResourceTest)20 ResourceTest (org.onosproject.rest.resources.ResourceTest)20 Activate (org.osgi.service.component.annotations.Activate)11 Logger (org.slf4j.Logger)11 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)11 Set (java.util.Set)10 Component (org.osgi.service.component.annotations.Component)10 Deactivate (org.osgi.service.component.annotations.Deactivate)10 HashSet (java.util.HashSet)9 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)9 ConnectPoint (org.onosproject.net.ConnectPoint)9 PortNumber (org.onosproject.net.PortNumber)9 Reference (org.osgi.service.component.annotations.Reference)9 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)9