Search in sources :

Example 16 with NetworkId

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

the class VirtualNetworkWebResourceTest method testGetVirtualHostsEmptyArray.

// Tests for Virtual Hosts
/**
 * Tests the result of the REST API GET when there are no virtual hosts.
 */
@Test
public void testGetVirtualHostsEmptyArray() {
    NetworkId networkId = networkId4;
    expect(mockVnetService.getVirtualHosts(networkId)).andReturn(ImmutableSet.of()).anyTimes();
    replay(mockVnetService);
    WebTarget wt = target();
    String location = "vnets/" + networkId.toString() + "/hosts";
    String response = wt.path(location).request().get(String.class);
    assertThat(response, is("{\"hosts\":[]}"));
    verify(mockVnetService);
}
Also used : 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 17 with NetworkId

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

the class VirtualNetworkWebResourceTest method testDeleteVirtualDevice.

/**
 * Tests removing a virtual device with DELETE request.
 */
@Test
public void testDeleteVirtualDevice() {
    NetworkId networkId = networkId3;
    DeviceId deviceId = devId2;
    mockVnetAdminService.removeVirtualDevice(networkId, deviceId);
    expectLastCall();
    replay(mockVnetAdminService);
    WebTarget wt = target().property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
    String reqLocation = "vnets/" + networkId.toString() + "/devices/" + deviceId.toString();
    Response response = wt.path(reqLocation).request(MediaType.APPLICATION_JSON_TYPE).delete();
    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
    verify(mockVnetAdminService);
}
Also used : Response(javax.ws.rs.core.Response) DeviceId(org.onosproject.net.DeviceId) 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 18 with NetworkId

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

the class VirtualNetworkWebResourceTest method testPostVirtualDeviceNullJsonStream.

/**
 * Tests adding of a null virtual device using POST via JSON stream.
 */
@Test
public void testPostVirtualDeviceNullJsonStream() {
    NetworkId networkId = networkId3;
    replay(mockVnetAdminService);
    WebTarget wt = target();
    try {
        String reqLocation = "vnets/" + networkId.toString() + "/devices";
        wt.path(reqLocation).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(null), String.class);
        fail("POST of null virtual device did not throw an exception");
    } catch (BadRequestException ex) {
        assertThat(ex.getMessage(), containsString("HTTP 400 Bad Request"));
    }
    verify(mockVnetAdminService);
}
Also used : 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 19 with NetworkId

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

the class VirtualNetworkWebResourceTest method testDeleteVirtualPort.

/**
 * Tests removing a virtual port with DELETE request.
 */
@Test
public void testDeleteVirtualPort() {
    NetworkId networkId = networkId3;
    DeviceId deviceId = devId2;
    PortNumber portNum = portNumber(2);
    mockVnetAdminService.removeVirtualPort(networkId, deviceId, portNum);
    expectLastCall();
    replay(mockVnetAdminService);
    WebTarget wt = target().property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
    String reqLocation = "vnets/" + networkId.toString() + "/devices/" + deviceId.toString() + "/ports/" + portNum.toLong();
    Response response = wt.path(reqLocation).request(MediaType.APPLICATION_JSON_TYPE).delete();
    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
    verify(mockVnetAdminService);
}
Also used : Response(javax.ws.rs.core.Response) DeviceId(org.onosproject.net.DeviceId) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) PortNumber(org.onosproject.net.PortNumber) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Example 20 with NetworkId

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

the class VirtualNetworkWebResourceTest method testDeleteVirtualHost.

/**
 * Tests removing a virtual host with DELETE request.
 */
@Test
public void testDeleteVirtualHost() {
    NetworkId networkId = networkId3;
    mockVnetAdminService.removeVirtualHost(networkId, hId1);
    expectLastCall();
    replay(mockVnetAdminService);
    WebTarget wt = target().property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
    InputStream jsonStream = VirtualNetworkWebResourceTest.class.getResourceAsStream("post-virtual-host.json");
    String reqLocation = "vnets/" + networkId.toString() + "/hosts";
    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)

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