@Test public void testGetVirtualNetworksByNonExistentTenantId() { String tenantIdName = "NON_EXISTENT_TENANT_ID"; expect(mockVnetAdminService.getTenantIds()).andReturn(ImmutableSet.of(tenantId3)).anyTimes(); replay(mockVnetAdminService); expect(mockVnetService.getVirtualNetworks(anyObject())).andReturn(ImmutableSet.of()).anyTimes(); replay(mockVnetService); WebTarget wt = target(); try { wt.path("vnets/" + tenantIdName) .request() .get(String.class); fail("Get of a non-existent virtual network did not throw an exception"); } catch (NotFoundException ex) { assertThat(ex.getMessage(), containsString("HTTP 404 Not Found")); } verify(mockVnetService); verify(mockVnetAdminService); }
@GET @Produces(MediaType.APPLICATION_JSON) public Response getVirtualNetworks() { Set<TenantId> tenantIds = vnetAdminService.getTenantIds(); List<VirtualNetwork> allVnets = tenantIds.stream() .map(tenantId -> vnetService.getVirtualNetworks(tenantId)) .flatMap(Collection::stream) .collect(Collectors.toList()); return ok(encodeArray(VirtualNetwork.class, "vnets", allVnets)).build(); }
VirtualNetworkWebResource extends AbstractWebResource { @GET @Produces(MediaType.APPLICATION_JSON) public Response getVirtualNetworks() { Set<TenantId> tenantIds = vnetAdminService.getTenantIds(); List<VirtualNetwork> allVnets = tenantIds.stream() .map(tenantId -> vnetService.getVirtualNetworks(tenantId)) .flatMap(Collection::stream) .collect(Collectors.toList()); return ok(encodeArray(VirtualNetwork.class, "vnets", allVnets)).build(); } }
VirtualNetworkWebResource extends AbstractWebResource { @GET @Produces(MediaType.APPLICATION_JSON) public Response getVirtualNetworks() { Set<TenantId> tenantIds = vnetAdminService.getTenantIds(); List<VirtualNetwork> allVnets = tenantIds.stream() .map(tenantId -> vnetService.getVirtualNetworks(tenantId)) .flatMap(Collection::stream) .collect(Collectors.toList()); return ok(encodeArray(VirtualNetwork.class, "vnets", allVnets)).build(); }  }
VirtualNetworkWebResource extends AbstractWebResource { @GET @Produces(MediaType.APPLICATION_JSON) public Response getVirtualNetworks() { Set<TenantId> tenantIds = vnetAdminService.getTenantIds(); List<VirtualNetwork> allVnets = tenantIds.stream() .map(tenantId -> vnetService.getVirtualNetworks(tenantId)) .flatMap(Collection::stream) .collect(Collectors.toList()); return ok(encodeArray(VirtualNetwork.class, "vnets", allVnets)).build(); }  @GET @Produces(MediaType.APPLICATION_JSON) Response getVirtualNetworks(); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{tenantId}") Response getVirtualNetworkById(@PathParam("tenantId") String tenantId); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response createVirtualNetwork(InputStream stream); @DELETE @Path("{networkId}") Response removeVirtualNetwork(@PathParam("networkId") long networkId); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{networkId}/devices") Response getVirtualDevices(@PathParam("networkId") long networkId); @POST @Path("{networkId}/devices") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response createVirtualDevice(@PathParam("networkId") long networkId,
                                        InputStream stream); @DELETE @Path("{networkId}/devices/{deviceId}") Response removeVirtualDevice(@PathParam("networkId") long networkId,
                                        @PathParam("deviceId") String deviceId); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{networkId}/devices/{deviceId}/ports") Response getVirtualPorts(@PathParam("networkId") long networkId,
                                    @PathParam("deviceId") String deviceId); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{networkId}/devices/{deviceId}/ports") Response createVirtualPort(@PathParam("networkId") long networkId,
                                      @PathParam("deviceId") String virtDeviceId,
                                      InputStream stream); @DELETE @Path("{networkId}/devices/{deviceId}/ports/{portNum}") Response removeVirtualPort(@PathParam("networkId") long networkId,
                                      @PathParam("deviceId") String deviceId,
                                      @PathParam("portNum") long portNum); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{networkId}/links") Response getVirtualLinks(@PathParam("networkId") long networkId); @POST @Path("{networkId}/links") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response createVirtualLink(@PathParam("networkId") long networkId,
                                      InputStream stream); @DELETE @Path("{networkId}/links") @Consumes(MediaType.APPLICATION_JSON) Response removeVirtualLink(@PathParam("networkId") long networkId,
                                      InputStream stream); }
VirtualNetworkWebResource extends AbstractWebResource { @GET @Produces(MediaType.APPLICATION_JSON) public Response getVirtualNetworks() { Set<TenantId> tenantIds = vnetAdminService.getTenantIds(); List<VirtualNetwork> allVnets = tenantIds.stream() .map(tenantId -> vnetService.getVirtualNetworks(tenantId)) .flatMap(Collection::stream) .collect(Collectors.toList()); return ok(encodeArray(VirtualNetwork.class, "vnets", allVnets)).build(); }  @GET @Produces(MediaType.APPLICATION_JSON) Response getVirtualNetworks(); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{tenantId}") Response getVirtualNetworkById(@PathParam("tenantId") String tenantId); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response createVirtualNetwork(InputStream stream); @DELETE @Path("{networkId}") Response removeVirtualNetwork(@PathParam("networkId") long networkId); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{networkId}/devices") Response getVirtualDevices(@PathParam("networkId") long networkId); @POST @Path("{networkId}/devices") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response createVirtualDevice(@PathParam("networkId") long networkId,
                                        InputStream stream); @DELETE @Path("{networkId}/devices/{deviceId}") Response removeVirtualDevice(@PathParam("networkId") long networkId,
                                        @PathParam("deviceId") String deviceId); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{networkId}/devices/{deviceId}/ports") Response getVirtualPorts(@PathParam("networkId") long networkId,
                                    @PathParam("deviceId") String deviceId); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{networkId}/devices/{deviceId}/ports") Response createVirtualPort(@PathParam("networkId") long networkId,
                                      @PathParam("deviceId") String virtDeviceId,
                                      InputStream stream); @DELETE @Path("{networkId}/devices/{deviceId}/ports/{portNum}") Response removeVirtualPort(@PathParam("networkId") long networkId,
                                      @PathParam("deviceId") String deviceId,
                                      @PathParam("portNum") long portNum); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{networkId}/links") Response getVirtualLinks(@PathParam("networkId") long networkId); @POST @Path("{networkId}/links") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response createVirtualLink(@PathParam("networkId") long networkId,
                                      InputStream stream); @DELETE @Path("{networkId}/links") @Consumes(MediaType.APPLICATION_JSON) Response removeVirtualLink(@PathParam("networkId") long networkId,
                                      InputStream stream);  }