@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); }
@POST @Path("{networkId}/devices") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response createVirtualDevice(@PathParam("networkId") long networkId, InputStream stream) { try { ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); final VirtualDevice vdevReq = codec(VirtualDevice.class).decode(jsonTree, this); JsonNode specifiedNetworkId = jsonTree.get("networkId"); if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) { throw new IllegalArgumentException(INVALID_FIELD + "networkId"); } final VirtualDevice vdevRes = vnetAdminService.createVirtualDevice(vdevReq.networkId(), vdevReq.id()); UriBuilder locationBuilder = uriInfo.getBaseUriBuilder() .path("vnets").path(specifiedNetworkId.asText()) .path("devices").path(vdevRes.id().toString()); return Response .created(locationBuilder.build()) .build(); } catch (IOException e) { throw new IllegalArgumentException(e); } }
VirtualNetworkWebResource extends AbstractWebResource { @POST @Path("{networkId}/devices") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response createVirtualDevice(@PathParam("networkId") long networkId, InputStream stream) { try { ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); final VirtualDevice vdevReq = codec(VirtualDevice.class).decode(jsonTree, this); JsonNode specifiedNetworkId = jsonTree.get("networkId"); if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) { throw new IllegalArgumentException(INVALID_FIELD + "networkId"); } final VirtualDevice vdevRes = vnetAdminService.createVirtualDevice(vdevReq.networkId(), vdevReq.id()); UriBuilder locationBuilder = uriInfo.getBaseUriBuilder() .path("vnets").path(specifiedNetworkId.asText()) .path("devices").path(vdevRes.id().toString()); return Response .created(locationBuilder.build()) .build(); } catch (IOException e) { throw new IllegalArgumentException(e); } } }
VirtualNetworkWebResource extends AbstractWebResource { @POST @Path("{networkId}/devices") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response createVirtualDevice(@PathParam("networkId") long networkId, InputStream stream) { try { ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); final VirtualDevice vdevReq = codec(VirtualDevice.class).decode(jsonTree, this); JsonNode specifiedNetworkId = jsonTree.get("networkId"); if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) { throw new IllegalArgumentException(INVALID_FIELD + "networkId"); } final VirtualDevice vdevRes = vnetAdminService.createVirtualDevice(vdevReq.networkId(), vdevReq.id()); UriBuilder locationBuilder = uriInfo.getBaseUriBuilder() .path("vnets").path(specifiedNetworkId.asText()) .path("devices").path(vdevRes.id().toString()); return Response .created(locationBuilder.build()) .build(); } catch (IOException e) { throw new IllegalArgumentException(e); } }  }
VirtualNetworkWebResource extends AbstractWebResource { @POST @Path("{networkId}/devices") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response createVirtualDevice(@PathParam("networkId") long networkId, InputStream stream) { try { ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); final VirtualDevice vdevReq = codec(VirtualDevice.class).decode(jsonTree, this); JsonNode specifiedNetworkId = jsonTree.get("networkId"); if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) { throw new IllegalArgumentException(INVALID_FIELD + "networkId"); } final VirtualDevice vdevRes = vnetAdminService.createVirtualDevice(vdevReq.networkId(), vdevReq.id()); UriBuilder locationBuilder = uriInfo.getBaseUriBuilder() .path("vnets").path(specifiedNetworkId.asText()) .path("devices").path(vdevRes.id().toString()); return Response .created(locationBuilder.build()) .build(); } catch (IOException e) { throw new IllegalArgumentException(e); } }  @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 { @POST @Path("{networkId}/devices") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response createVirtualDevice(@PathParam("networkId") long networkId, InputStream stream) { try { ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); final VirtualDevice vdevReq = codec(VirtualDevice.class).decode(jsonTree, this); JsonNode specifiedNetworkId = jsonTree.get("networkId"); if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) { throw new IllegalArgumentException(INVALID_FIELD + "networkId"); } final VirtualDevice vdevRes = vnetAdminService.createVirtualDevice(vdevReq.networkId(), vdevReq.id()); UriBuilder locationBuilder = uriInfo.getBaseUriBuilder() .path("vnets").path(specifiedNetworkId.asText()) .path("devices").path(vdevRes.id().toString()); return Response .created(locationBuilder.build()) .build(); } catch (IOException e) { throw new IllegalArgumentException(e); } }  @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);  }