BundleInfoRestEndpoint { public static Jsons.Obj bundleInfoJson(BundleInfo bundle) { return obj(p("host", bundle.getHost()), p("bundleSymbolicName", bundle.getBundleSymbolicName()), p("bundleId", bundle.getBundleId())).append(fullVersionJson.apply(bundle.getVersion())); }  @GET // path prefix "bundles" is contained here and not in the path annotation of the class // See https://opencast.jira.com/browse/MH-9768 @Path("bundles/list") @Produces(APPLICATION_JSON) @RestQuery( name = "list", description = "Return a list of all running bundles on the whole cluster.", responses = { @RestResponse(description = "A list of bundles.", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "The search results, expressed as xml or json.") Response getVersions(); @GET @Path("bundles/check") @RestQuery( name = "check", description = "Check if all bundles throughout the cluster have the same OSGi bundle version and build number.", restParameters = { @RestParameter( name = "prefix", description = "The bundle name prefixes to check. Defaults to '" + DEFAULT_BUNDLE_PREFIX + "'.", isRequired = false, defaultValue = DEFAULT_BUNDLE_PREFIX, type = RestParameter.Type.STRING) }, responses = { @RestResponse(description = "true/false", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "cannot find any bundles with the given prefix", responseCode = HttpServletResponse.SC_NOT_FOUND) }, returnDescription = "The search results, expressed as xml or json.") Response checkBundles(@DefaultValue(DEFAULT_BUNDLE_PREFIX) @QueryParam("prefix") List<String> prefixes); @GET @Path("bundles/version") @Produces(APPLICATION_JSON) @RestQuery( name = "bundleVersion", description = "Return the common OSGi build version and build number of all bundles matching the given prefix.", restParameters = { @RestParameter( name = "prefix", description = "The bundle name prefixes to check. Defaults to '" + DEFAULT_BUNDLE_PREFIX + "'.", isRequired = false, defaultValue = DEFAULT_BUNDLE_PREFIX, type = RestParameter.Type.STRING) }, responses = { @RestResponse(description = "Version structure", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No bundles with the given prefix", responseCode = HttpServletResponse.SC_NOT_FOUND) }, returnDescription = "The search results as json.") Response getBundleVersion(@DefaultValue(DEFAULT_BUNDLE_PREFIX) @QueryParam("prefix") List<String> prefixes); static Jsons.Obj bundleInfoJson(BundleInfo bundle); static final Function<BundleVersion, Jsons.Obj> fullVersionJson; static final Function<BundleInfo, Jsons.Obj> bundleInfo; }
@Test public void testBundleInfoJsonSerialization() { final JsonPath p = JsonPath.from(bundleInfoJson(bundleInfo("host", "bundle", 1L, "version", some("sha"))).toJson()); run(BundleInfo.class, new BundleInfo() { @Override public String getHost() { assertEquals("host", p.getString("host")); return null; } @Override public String getBundleSymbolicName() { assertEquals("bundle", p.getString("bundleSymbolicName")); return null; } @Override public long getBundleId() { assertEquals(1L, p.getLong("bundleId")); return 0; } @Override public String getBundleVersion() { assertEquals("bundle", p.getString("bundleSymbolicName")); return null; } @Override public Option<String> getBuildNumber() { assertEquals("sha", p.getString("buildNumber")); return null; } @Override public BundleVersion getVersion() { assertEquals("sha", p.getString("buildNumber")); return null; } }); }