HintsConverter { public static Map<String, ?> toJsonHomeRepresentation(final Hints hints) { return toRepresentation(hints, APPLICATION_JSONHOME); } private  HintsConverter(); static Map<String, ?> toJsonHomeRepresentation(final Hints hints); static Map<String, ?> toRepresentation(final Hints hints, final JsonHomeMediaType mediaType);  }
@Test public void testToJson() throws Exception { final Set<Allow> allows = of(GET, POST, PUT); final List<String> representations = asList("text/html", "text/plain"); final List<String> acceptPut = asList("foo/bar"); final List<String> acceptPost = asList("bar/foo"); final Hints hints = hintsBuilder() .allowing(allows) .representedAs(representations) .acceptingForPut(acceptPut) .acceptingForPost(acceptPost) .acceptingRanges("bytes") .preferring("return-representation=application/json", "return-asynch") .with(emptyDocs()) .requiring(asList(ETAG, LAST_MODIFIED)) .withStatus(Status.DEPRECATED) .build(); final Map<String, ?> map = toJsonHomeRepresentation(hints); assertEquals(map.keySet().size(), 8); assertEquals(map.get("allow"), allows); assertEquals(map.get("representations"), representations); assertEquals(map.get("accept-put"), acceptPut); assertEquals(map.get("accept-post"), acceptPost); assertEquals(map.get("accept-ranges"), asList("bytes")); assertEquals(map.get("prefer"), asList("return-representation=application/json", "return-asynch")); assertEquals(map.get("precondition-req"), asList("etag", "last-modified")); assertEquals(map.get("status"), "deprecated"); }
@Test public void testAuthReq() { final Hints hints = hintsBuilder().withAuthRequired(asList( authReq("Basic", asList("private")))) .build(); final Map<String, ?> map = toJsonHomeRepresentation(hints); assertEquals(map.keySet().size(), 3); List<Map<String, Object>> expectedAuthReq = new ArrayList<Map<String, Object>>(); Map<String, Object> auth = new HashMap<String, Object>(); auth.put("scheme", "Basic"); auth.put("realms", asList("private")); expectedAuthReq.add(auth); assertEquals(map.get("auth-req"), expectedAuthReq); }
@Test public void testStatusDeprecated() throws Exception { final Hints hints = hintsBuilder().withStatus(Status.DEPRECATED).build(); final Map<String, ?> map = toJsonHomeRepresentation(hints); assertEquals(map.get("status"), "deprecated"); }
@Test public void testStatusGone() throws Exception { final Hints hints = hintsBuilder().withStatus(Status.GONE).build(); final Map<String, ?> map = toJsonHomeRepresentation(hints); assertEquals(map.get("status"), "gone"); }
@Test public void testStatusOK() throws Exception { final Hints hints = hintsBuilder().withStatus(Status.OK).build(); final Map<String, ?> map = toJsonHomeRepresentation(hints); assertEquals(map.get("status"), null); }