@Test public void getFrameworkJar() { final Framework mockedFramework = new Framework(); mockedFramework.setId("FRAMEWORK_TO_GET"); mockedFramework.setName("test-framework"); mockedFramework.setLabel("Test Framework"); final byte[] mockedFrameworkJar = "FRAMEWORK CONTENT GOES HERE".getBytes(); when(frameworkServiceMock.getFramework(anyString())).thenReturn(mockedFramework); when(frameworkServiceMock.getFrameworkJar(anyString())).then(new Answer<byte[]>() { @Override public byte[] answer(InvocationOnMock invocation) throws Throwable { String argFrameworkId = (String) invocation.getArguments()[0]; assertEquals("Service framework ID should match the requested framework ID", mockedFramework.getId(), argFrameworkId); return mockedFrameworkJar; } }); byte[] responseFrameworkJar = resource().path("/api/frameworks/" + mockedFramework.getId() + "/jar") .accept("application/java-archive").get(byte[].class); assertTrue("Response framework should match the mocked framework", Arrays.equals(mockedFrameworkJar, responseFrameworkJar)); verify(frameworkServiceMock).getFramework(anyString()); verify(frameworkServiceMock).getFrameworkJar(anyString()); }
@GET @Path("/{frameworkId}/jar") @Produces("application/java-archive") public Response getFrameworkJar(@PathParam("frameworkId") String frameworkId) { Framework framework = frameworkService.getFramework(frameworkId); byte[] frameworkJar = frameworkService.getFrameworkJar(frameworkId); return Response.ok().entity(frameworkJar) .header("Content-Disposition", "attachment; filename=\"" + framework.getName() + ".jar\"") .header("Cache-Control", "no-cache").build(); }
FrameworkResource { @GET @Path("/{frameworkId}/jar") @Produces("application/java-archive") public Response getFrameworkJar(@PathParam("frameworkId") String frameworkId) { Framework framework = frameworkService.getFramework(frameworkId); byte[] frameworkJar = frameworkService.getFrameworkJar(frameworkId); return Response.ok().entity(frameworkJar) .header("Content-Disposition", "attachment; filename=\"" + framework.getName() + ".jar\"") .header("Cache-Control", "no-cache").build(); } }
FrameworkResource { @GET @Path("/{frameworkId}/jar") @Produces("application/java-archive") public Response getFrameworkJar(@PathParam("frameworkId") String frameworkId) { Framework framework = frameworkService.getFramework(frameworkId); byte[] frameworkJar = frameworkService.getFrameworkJar(frameworkId); return Response.ok().entity(frameworkJar) .header("Content-Disposition", "attachment; filename=\"" + framework.getName() + ".jar\"") .header("Cache-Control", "no-cache").build(); } @Inject  FrameworkResource(FrameworkService frameworkService,
            ComponentService componentService, ResourceService resourceService,
            SerializationService serializationService); }
FrameworkResource { @GET @Path("/{frameworkId}/jar") @Produces("application/java-archive") public Response getFrameworkJar(@PathParam("frameworkId") String frameworkId) { Framework framework = frameworkService.getFramework(frameworkId); byte[] frameworkJar = frameworkService.getFrameworkJar(frameworkId); return Response.ok().entity(frameworkJar) .header("Content-Disposition", "attachment; filename=\"" + framework.getName() + ".jar\"") .header("Cache-Control", "no-cache").build(); } @Inject  FrameworkResource(FrameworkService frameworkService,
            ComponentService componentService, ResourceService resourceService,
            SerializationService serializationService); @GET @Produces(MediaType.APPLICATION_JSON) List<Framework> listFrameworks(); @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) Framework saveFramework(@FormDataParam("file") byte[] frameworkJar, 
            @FormDataParam("isPublic") @DefaultValue("false") boolean isPublic); @GET @Path("/{frameworkId}") @Produces(MediaType.APPLICATION_JSON) Framework getFramework(@PathParam("frameworkId") String frameworkId); @DELETE @Path("/{frameworkId}") Response deleteFramework(@PathParam("frameworkId") String frameworkId); @GET @Path("/{frameworkId}/jar") @Produces("application/java-archive") Response getFrameworkJar(@PathParam("frameworkId") String frameworkId); @GET @Path("/{frameworkId}/components") @Produces(MediaType.APPLICATION_JSON) List<Component> getFrameworkComponents(@PathParam("frameworkId") String frameworkId); @GET @Path("/{frameworkId}/resources") @Produces(MediaType.APPLICATION_JSON) List<Resource> getFrameworkResources(@PathParam("frameworkId") String frameworkId); @GET @Path("/{frameworkId}/serializations") @Produces(MediaType.APPLICATION_JSON) List<Serialization> getFrameworkSerializations(@PathParam("frameworkId") String frameworkId); }
FrameworkResource { @GET @Path("/{frameworkId}/jar") @Produces("application/java-archive") public Response getFrameworkJar(@PathParam("frameworkId") String frameworkId) { Framework framework = frameworkService.getFramework(frameworkId); byte[] frameworkJar = frameworkService.getFrameworkJar(frameworkId); return Response.ok().entity(frameworkJar) .header("Content-Disposition", "attachment; filename=\"" + framework.getName() + ".jar\"") .header("Cache-Control", "no-cache").build(); } @Inject  FrameworkResource(FrameworkService frameworkService,
            ComponentService componentService, ResourceService resourceService,
            SerializationService serializationService); @GET @Produces(MediaType.APPLICATION_JSON) List<Framework> listFrameworks(); @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) Framework saveFramework(@FormDataParam("file") byte[] frameworkJar, 
            @FormDataParam("isPublic") @DefaultValue("false") boolean isPublic); @GET @Path("/{frameworkId}") @Produces(MediaType.APPLICATION_JSON) Framework getFramework(@PathParam("frameworkId") String frameworkId); @DELETE @Path("/{frameworkId}") Response deleteFramework(@PathParam("frameworkId") String frameworkId); @GET @Path("/{frameworkId}/jar") @Produces("application/java-archive") Response getFrameworkJar(@PathParam("frameworkId") String frameworkId); @GET @Path("/{frameworkId}/components") @Produces(MediaType.APPLICATION_JSON) List<Component> getFrameworkComponents(@PathParam("frameworkId") String frameworkId); @GET @Path("/{frameworkId}/resources") @Produces(MediaType.APPLICATION_JSON) List<Resource> getFrameworkResources(@PathParam("frameworkId") String frameworkId); @GET @Path("/{frameworkId}/serializations") @Produces(MediaType.APPLICATION_JSON) List<Serialization> getFrameworkSerializations(@PathParam("frameworkId") String frameworkId);  }