use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class DistributedVirtualNetworkStore method addNetwork.
@Override
public VirtualNetwork addNetwork(TenantId tenantId) {
checkState(tenantIdSet.contains(tenantId), "The tenant has not been registered. " + tenantId.id());
VirtualNetwork virtualNetwork = new DefaultVirtualNetwork(genNetworkId(), tenantId);
// TODO update both maps in one transaction.
networkIdVirtualNetworkMap.put(virtualNetwork.id(), virtualNetwork);
Set<NetworkId> networkIdSet = tenantIdNetworkIdSetMap.get(tenantId);
if (networkIdSet == null) {
networkIdSet = new HashSet<>();
}
networkIdSet.add(virtualNetwork.id());
tenantIdNetworkIdSetMap.put(tenantId, networkIdSet);
return virtualNetwork;
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class VirtualNetworkWebResourceTest method testGetVirtualDevicesEmptyArray.
// Tests for Virtual Device
/**
* Tests the result of the REST API GET when there are no virtual devices.
*/
@Test
public void testGetVirtualDevicesEmptyArray() {
NetworkId networkId = networkId4;
expect(mockVnetService.getVirtualDevices(networkId)).andReturn(ImmutableSet.of()).anyTimes();
replay(mockVnetService);
WebTarget wt = target();
String location = "vnets/" + networkId.toString() + "/devices";
String response = wt.path(location).request().get(String.class);
assertThat(response, is("{\"devices\":[]}"));
verify(mockVnetService);
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class VirtualNetworkWebResourceTest method testGetVirtualHostsArray.
/**
* Tests the result of the REST API GET when virtual hosts are defined.
*/
@Test
public void testGetVirtualHostsArray() {
NetworkId networkId = networkId3;
final Set<VirtualHost> vhostSet = ImmutableSet.of(vhost1, vhost2);
expect(mockVnetService.getVirtualHosts(networkId)).andReturn(vhostSet).anyTimes();
replay(mockVnetService);
WebTarget wt = target();
String location = "vnets/" + networkId.toString() + "/hosts";
String response = wt.path(location).request().get(String.class);
assertThat(response, containsString("{\"hosts\":["));
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
assertThat(result.names().get(0), is("hosts"));
final JsonArray vnetJsonArray = result.get("hosts").asArray();
assertThat(vnetJsonArray, notNullValue());
assertEquals("Virtual hosts array is not the correct size.", vhostSet.size(), vnetJsonArray.size());
vhostSet.forEach(vhost -> assertThat(vnetJsonArray, hasVhost(vhost)));
verify(mockVnetService);
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class VirtualNetworkWebResourceTest method testPostVirtualLinkNullJsonStream.
/**
* Tests adding of a null virtual link using POST via JSON stream.
*/
@Test
public void testPostVirtualLinkNullJsonStream() {
NetworkId networkId = networkId3;
replay(mockVnetAdminService);
WebTarget wt = target();
try {
String reqLocation = "vnets/" + networkId.toString() + "/links";
wt.path(reqLocation).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(null), String.class);
fail("POST of null virtual link did not throw an exception");
} catch (BadRequestException ex) {
assertThat(ex.getMessage(), containsString("HTTP 400 Bad Request"));
}
verify(mockVnetAdminService);
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class VirtualNetworkWebResourceTest method testGetVirtualLinksEmptyArray.
// Tests for Virtual Links
/**
* Tests the result of the REST API GET when there are no virtual links.
*/
@Test
public void testGetVirtualLinksEmptyArray() {
NetworkId networkId = networkId4;
expect(mockVnetService.getVirtualLinks(networkId)).andReturn(ImmutableSet.of()).anyTimes();
replay(mockVnetService);
WebTarget wt = target();
String location = "vnets/" + networkId.toString() + "/links";
String response = wt.path(location).request().get(String.class);
assertThat(response, is("{\"links\":[]}"));
verify(mockVnetService);
}
Aggregations