HeliumRestApi { @GET @Path("package") public Response getAllPackageInfo() { try { return new JsonResponse<>(Response.Status.OK, "", helium.getAllPackageInfo()).build(); } catch (RuntimeException e) { logger.error(e.getMessage(), e); return new JsonResponse(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage()).build(); } } @Inject  HeliumRestApi(Helium helium, Notebook notebook); @GET @Path("package") Response getAllPackageInfo(); @GET @Path("enabledPackage") Response getAllEnabledPackageInfo(); @GET @Path("package/{packageName}") Response getSinglePackageInfo(@PathParam("packageName") String packageName); @GET @Path("suggest/{noteId}/{paragraphId}") Response suggest(@PathParam("noteId") String noteId,
          @PathParam("paragraphId") String paragraphId); @POST @Path("load/{noteId}/{paragraphId}") Response load(@PathParam("noteId") String noteId,
          @PathParam("paragraphId") String paragraphId, String heliumPackage); @GET @Path("bundle/load/{packageName}") @Produces("text/javascript") Response bundleLoad(@QueryParam("refresh") String refresh,
          @PathParam("packageName") String packageName); @POST @Path("enable/{packageName}") Response enablePackage(@PathParam("packageName") String packageName, String artifact); @POST @Path("disable/{packageName}") Response disablePackage(@PathParam("packageName") String packageName); @GET @Path("spell/config/{packageName}") Response getSpellConfigUsingMagic(@PathParam("packageName") String packageName); @GET @Path("config") Response getAllPackageConfigs(); @GET @Path("config/{packageName}/{artifact}") Response getPackageConfig(@PathParam("packageName") String packageName,
          @PathParam("artifact") String artifact); @POST @Path("config/{packageName}/{artifact}") Response updatePackageConfig(@PathParam("packageName") String packageName,
          @PathParam("artifact") String artifact, String rawConfig); @GET @Path("order/visualization") Response getVisualizationPackageOrder(); @POST @Path("order/visualization") Response setVisualizationPackageOrder(String orderedPackageNameList);  }
@Test public void testGetAllPackageInfo() throws IOException { GetMethod get = httpGet("/helium/package"); assertThat(get, isAllowed()); Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() { }.getType()); Map<String, Set<String>> body = (Map<String, Set<String>>) resp.get("body"); assertEquals(2, body.size()); assertTrue(body.containsKey("name1")); assertTrue(body.containsKey("name2")); }
@Test public void testVisualizationPackageOrder() throws IOException { GetMethod get1 = httpGet("/helium/order/visualization"); assertThat(get1, isAllowed()); Map<String, Object> resp1 = gson.fromJson(get1.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() { }.getType()); List<Object> body1 = (List<Object>) resp1.get("body"); assertEquals(body1.size(), 0); helium.getAllPackageInfo(); String postRequestJson = "[name2, name1]"; PostMethod post = httpPost("/helium/order/visualization", postRequestJson); assertThat(post, isAllowed()); post.releaseConnection(); GetMethod get2 = httpGet("/helium/order/visualization"); assertThat(get2, isAllowed()); Map<String, Object> resp2 = gson.fromJson(get2.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() { }.getType()); List<Object> body2 = (List<Object>) resp2.get("body"); assertEquals(body2.size(), 2); assertEquals(body2.get(0), "name2"); assertEquals(body2.get(1), "name1"); }