@Test public void testDoc12() throws Exception { ActionDoc doc = callApi("method12"); assertThat(doc.isDeprecated()).isFalse(); assertThat(doc.getMethodComment()).isEqualTo("method twelve doc"); assertThat(doc.getAuthor()).isEqualTo("sr"); assertThat(doc.getVersion()).isEqualTo("1.0"); assertThat(doc.getParameters()).isEmpty(); assertThat(doc.getReturnMethod()).isEmpty(); }
@Test public void testDoc9() throws Exception { ActionDoc doc = callApi("method9"); assertThat(doc.isDeprecated()).isFalse(); assertThat(doc.getMethodComment()).isEqualTo("method nine doc"); assertThat(doc.getAuthor()).isEqualTo("dbs"); assertThat(doc.getVersion()).isEqualTo("0.9"); assertThat(doc.getParameters()).isEmpty(); assertThat(doc.getReturnMethod()).isEmpty(); }
@Test public void testDoc11() throws Exception { ActionDoc doc = callApi("method11"); assertThat(doc.isDeprecated()).isFalse(); assertThat(doc.getMethodComment()).isEqualTo("method eleven doc"); assertThat(doc.getAuthor()).isEmpty(); assertThat(doc.getVersion()).isEqualTo("1.0"); assertThat(doc.getParameters()).hasSize(2); assertThat(doc.getParameters()).contains(entry("a", "a desc"), entry("b", "b desc")); assertThat(doc.getReturnMethod()).isEmpty(); }
@Test public void testDoc8() throws Exception { ActionDoc doc = callApi("method8"); assertThat(doc.isDeprecated()).isFalse(); assertThat(doc.getMethodComment()).isEqualTo("method eight doc"); assertThat(doc.getAuthor()).isEqualTo("sr"); assertThat(doc.getVersion()).isEqualTo("0.8"); assertThat(doc.getParameters()).isEmpty(); assertThat(doc.getReturnMethod()).hasSize(2); assertThat(doc.getReturnMethod()).contains(entry("p1", "p1 desc"), entry("p2", "p2 desc")); }
@Test public void testDoc7() throws Exception { ActionDoc doc = callApi("method7"); assertThat(doc.isDeprecated()).isTrue(); assertThat(doc.getMethodComment()).isEqualTo("method seven doc"); assertThat(doc.getAuthor()).isEqualTo("sr"); assertThat(doc.getVersion()).isEqualTo("0.7"); assertThat(doc.getParameters()).isEmpty(); assertThat(doc.getReturnMethod()).hasSize(1); assertThat(doc.getReturnMethod()).contains(entry("p1", "p1 desc")); }
private static ActionDoc getCommentForMethod(String apiString, String method) { ActionDoc doc = new ActionDoc(method, Collections.<String>emptyList()); String block = findCommentBlock(apiString, method); if (block != null) { doc.setDeprecated(block.contains("* @deprecated")); int p = block.indexOf("@author:"); if (p != -1) { doc.setAuthor(block.substring(p + 9, block.indexOf('\n', p))); } p = block.indexOf("@version:"); if (p != -1) { doc.setVersion(block.substring(p + 10, block.indexOf('\n', p))); } p = block.indexOf(method); if (p != -1) { doc.setMethodComment(block.substring(p + method.length() + 2, block.indexOf('\n', p))); } Map<String, String> params = new HashMap<String, String>(); p = block.indexOf("@param:"); while (p != -1) { int p2 = block.indexOf('\n', p); String pc = block.substring(p + 8, p2); int c1 = pc.indexOf('['); int c2 = pc.indexOf(']'); params.put(pc.substring(c1 + 1, c2), pc.substring(c2 + 2)); p = block.indexOf("@param:", p2); } doc.setParameters(params); Map<String, String> returns = new HashMap<String, String>(); p = block.indexOf("@return"); if (p != -1) { p = block.indexOf('[', p); while (p != -1) { int p2 = block.indexOf(']', p); returns.put(block.substring(p + 1, p2), block.substring(p2 + 2, block.indexOf('\n', p2))); p = block.indexOf('[', p2); } } doc.setReturnMethod(returns); } return doc; }
/** * to test the following need to activate Feature 'ALLOW_COMMENTS' for jackson parser * * <p>typical error is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('/' * (code 47)): maybe a (non-standard) comment? * * @throws Exception */ @Test public void testDoc1() throws Exception { ActionDoc doc = callApi("method1"); assertThat(doc.isDeprecated()).isTrue(); assertThat(doc.getMethodComment()) .isEqualTo("this method is used to test the documentation generation"); assertThat(doc.getAuthor()).isEqualTo("dbs"); assertThat(doc.getVersion()).isEqualTo("0.1"); assertThat(doc.getParameters()).hasSize(5); assertThat(doc.getParameters()) .contains( entry("a", "property a integer"), entry("b", "property b string"), entry("c", "property c string"), entry("d", "property d boolean"), entry("e", "array of integers")); assertThat(doc.getReturnMethod()).hasSize(2); assertThat(doc.getReturnMethod()) .contains( entry("errors", "list of failed fields"), entry("success", "true for success, false otherwise")); }