@Test public void testPutOverwrite() throws IOException { String network = "network1"; String key = "foo/bar"; Main.getWorkMgr().initNetwork(network, null); String oldContent = "baz"; String newContent = "bath"; Main.getWorkMgr() .putNetworkObject(new ByteArrayInputStream(oldContent.getBytes()), network, key); try (Response response = getTarget(network, key) .put(Entity.entity(newContent, MediaType.APPLICATION_OCTET_STREAM))) { assertThat(response.getStatus(), equalTo(OK.getStatusCode())); try (InputStream stream = Main.getWorkMgr().getNetworkObject(network, key)) { assertThat(stream, not(nullValue())); assertThat(IOUtils.toString(stream, UTF_8), equalTo(newContent)); } } }
@PUT @Consumes(MediaType.APPLICATION_OCTET_STREAM) public @Nonnull Response put(InputStream inputStream, @QueryParam(QP_KEY) String key) throws IOException { if (Main.getWorkMgr().putNetworkObject(inputStream, _network, key)) { return Response.ok().build(); } else { return Response.status(Status.NOT_FOUND).build(); } }
NetworkObjectsResource { @PUT @Consumes(MediaType.APPLICATION_OCTET_STREAM) public @Nonnull Response put(InputStream inputStream, @QueryParam(QP_KEY) String key) throws IOException { if (Main.getWorkMgr().putNetworkObject(inputStream, _network, key)) { return Response.ok().build(); } else { return Response.status(Status.NOT_FOUND).build(); } } }
NetworkObjectsResource { @PUT @Consumes(MediaType.APPLICATION_OCTET_STREAM) public @Nonnull Response put(InputStream inputStream, @QueryParam(QP_KEY) String key) throws IOException { if (Main.getWorkMgr().putNetworkObject(inputStream, _network, key)) { return Response.ok().build(); } else { return Response.status(Status.NOT_FOUND).build(); } } NetworkObjectsResource(String network); }
NetworkObjectsResource { @PUT @Consumes(MediaType.APPLICATION_OCTET_STREAM) public @Nonnull Response put(InputStream inputStream, @QueryParam(QP_KEY) String key) throws IOException { if (Main.getWorkMgr().putNetworkObject(inputStream, _network, key)) { return Response.ok().build(); } else { return Response.status(Status.NOT_FOUND).build(); } } NetworkObjectsResource(String network); @DELETE @Nonnull Response delete(@QueryParam(QP_KEY) String key); @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @SuppressWarnings({"MustBeClosedChecker", "PMD.CloseResource"}) // Response eventually closes it. @Nonnull Response get(@QueryParam(QP_KEY) String key); @PUT @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Nonnull Response put(InputStream inputStream, @QueryParam(QP_KEY) String key); }
NetworkObjectsResource { @PUT @Consumes(MediaType.APPLICATION_OCTET_STREAM) public @Nonnull Response put(InputStream inputStream, @QueryParam(QP_KEY) String key) throws IOException { if (Main.getWorkMgr().putNetworkObject(inputStream, _network, key)) { return Response.ok().build(); } else { return Response.status(Status.NOT_FOUND).build(); } } NetworkObjectsResource(String network); @DELETE @Nonnull Response delete(@QueryParam(QP_KEY) String key); @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @SuppressWarnings({"MustBeClosedChecker", "PMD.CloseResource"}) // Response eventually closes it. @Nonnull Response get(@QueryParam(QP_KEY) String key); @PUT @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Nonnull Response put(InputStream inputStream, @QueryParam(QP_KEY) String key);  }