HintsConverter { public static Map<String, ?> toRepresentation(final Hints hints, final JsonHomeMediaType mediaType) { final Map<String, Object> jsonHints = new LinkedHashMap<>(); jsonHints.put("allow", hints.getAllows()); jsonHints.put("representations", hints.getRepresentations()); if (!hints.getAcceptPut().isEmpty()) { jsonHints.put("accept-put", hints.getAcceptPut()); } if (!hints.getAcceptPost().isEmpty()) { jsonHints.put("accept-post", hints.getAcceptPost()); } if (!hints.getAcceptPatch().isEmpty()) { jsonHints.put("accept-patch", hints.getAcceptPatch()); } if (!hints.getAcceptRanges().isEmpty()) { jsonHints.put("accept-ranges", hints.getAcceptRanges()); } if (!hints.getPreferences().isEmpty()) { jsonHints.put("prefer", hints.getPreferences()); } if (!hints.getPreconditionReq().isEmpty()) { jsonHints.put("precondition-req", hints.getPreconditionReq().stream().map(Objects::toString).collect(toList())); } if (!hints.getAuthReq().isEmpty()) { final List<Map<String,?>> authReq = new ArrayList<>(); for (final Authentication authentication : hints.getAuthReq()) { final Map<String, Object> authMap = new HashMap<>(); authMap.put("scheme", authentication.getScheme()); if (!authentication.getRealms().isEmpty()) { authMap.put("realms", authentication.getRealms()); } authReq.add(authMap); } jsonHints.put("auth-req", authReq); } if (!hints.getStatus().equals(Status.OK)) { jsonHints.put("status", hints.getStatus().name().toLowerCase()); } if (hints.getDocs().hasLink()) { jsonHints.put("docs", hints.getDocs().getLink().toString()); } if (mediaType.equals(JsonHomeMediaType.APPLICATION_JSON)) { if (hints.getDocs().hasDescription()) { jsonHints.put("description", hints.getDocs().getDescription()); } if (hints.getDocs().hasDetailedDescription()) { jsonHints.put("detailedDescription", hints.getDocs().getDetailedDescription()); } } return jsonHints; } private  HintsConverter(); static Map<String, ?> toJsonHomeRepresentation(final Hints hints); static Map<String, ?> toRepresentation(final Hints hints, final JsonHomeMediaType mediaType);  }
@Test public void testAdditionalDescriptionForApplicationJsonHome() { final Hints hints = hintsBuilder() .with(documentation(asList("foo", "bar"), "<h1>Hello</h1>", create("http: .build(); final Map<String, ?> jsonHomeMap = toRepresentation(hints, APPLICATION_JSONHOME); assertEquals(jsonHomeMap.get("docs"), "http: assertNull(jsonHomeMap.get("description")); assertNull(jsonHomeMap.get("detailedDescription")); }
@Test public void testAdditionalDescriptionForApplicationJson() { final Hints hints = hintsBuilder() .with(documentation(asList("foo", "bar"), "<h1>Hello</h1>", create("http: .build(); final Map<String, ?> jsonMap = toRepresentation(hints, APPLICATION_JSON); assertEquals(jsonMap.get("docs"), "http: assertEquals(jsonMap.get("description"), asList("foo", "bar")); assertEquals(jsonMap.get("detailedDescription"), "<h1>Hello</h1>"); }