Package ch.ralscha.extdirectspring.bean.api

Examples of ch.ralscha.extdirectspring.bean.api.ActionDoc


   * @param documentation
   * @return ActionDoc
   */
  private Action extractDocumentationAnnotations(ExtDirectMethodDocumentation documentation) {
    if (!documentation.value().isEmpty()) {
      ActionDoc actionDoc = new ActionDoc(getAction(), documentation.value(), documentation.author(),
          documentation.version(), documentation.deprecated());
      ExtDirectDocParameters docParameters = documentation.parameters();
      if (null != docParameters) {
        String[] params = docParameters.params();
        String[] descriptions = docParameters.descriptions() == null ? new String[params.length]
            : docParameters.descriptions();
        if (params.length == descriptions.length) {
          for (int i = 0; i < params.length; i++) {
            actionDoc.getParameters().put(params[i],
                descriptions[i] == null ? "No description" : descriptions[i]);
          }
        } else {
          LogFactory
              .getLog(MethodInfo.class)
              .info("Documentation: skip generation of parameters, params size is different from descriptions size");
        }
      }
      ExtDirectDocReturn docReturn = documentation.returnMethod();
      if (null != docReturn) {
        String[] properties = docReturn.properties();
        String[] descriptions = docReturn.descriptions() == null ? new String[properties.length] : docReturn
            .descriptions();
        if (properties.length == descriptions.length) {
          for (int i = 0; i < properties.length; i++) {
            actionDoc.getReturnMethod().put(properties[i],
                descriptions[i] == null ? "No description" : descriptions[i]);
          }
        } else {
          LogFactory
              .getLog(MethodInfo.class)
View Full Code Here


          // mode
          if (jgen.getPrettyPrinter() != null && action instanceof ActionDoc) {// insertion
                                              // of
                                              // doc
                                              // here
            ActionDoc actionDoc = (ActionDoc) action;
            jgen.writeRaw("\n\t/**");
            if (actionDoc.isDeprecated()) {
              jgen.writeRaw("\n\t* @deprecated");
            }
            jgen.writeRaw("\n\t* " + actionDoc.getName() + ": " + actionDoc.getMethodComment());
            jgen.writeRaw("\n\t* @author: " + actionDoc.getAuthor());
            jgen.writeRaw("\n\t* @version: " + actionDoc.getVersion());
            jgen.writeRaw("\n\t*");
            for (Entry<String, String> entry2 : actionDoc.getParameters().entrySet()) {
              jgen.writeRaw("\n\t* @param: [" + entry2.getKey() + "] " + entry2.getValue());
            }
            jgen.writeRaw("\n\t* @return");
            for (Entry<String, String> entry2 : actionDoc.getReturnMethod().entrySet()) {
              jgen.writeRaw("\n\t*\t [" + entry2.getKey() + "] " + entry2.getValue());
            }
            jgen.writeRaw("\n\t*/\n");
          }
          jgen.writeObject(action);
 
View Full Code Here

   * @return ActionDoc
   */
  private Action extractDocumentationAnnotations(
      ExtDirectMethodDocumentation documentation) {
    if (!documentation.value().isEmpty()) {
      ActionDoc actionDoc = new ActionDoc(getAction(), documentation.value(),
          documentation.author(), documentation.version(),
          documentation.deprecated());
      ExtDirectDocParameters docParameters = documentation.parameters();
      if (null != docParameters) {
        String[] params = docParameters.params();
        String[] descriptions = docParameters.descriptions() == null ? new String[params.length]
            : docParameters.descriptions();
        if (params.length == descriptions.length) {
          for (int i = 0; i < params.length; i++) {
            actionDoc.getParameters().put(
                params[i],
                descriptions[i] == null ? "No description"
                    : descriptions[i]);
          }
        }
        else {
          LogFactory
              .getLog(MethodInfo.class)
              .info("Documentation: skip generation of parameters, params size is different from descriptions size");
        }
      }
      ExtDirectDocReturn docReturn = documentation.returnMethod();
      if (null != docReturn) {
        String[] properties = docReturn.properties();
        String[] descriptions = docReturn.descriptions() == null ? new String[properties.length]
            : docReturn.descriptions();
        if (properties.length == descriptions.length) {
          for (int i = 0; i < properties.length; i++) {
            actionDoc.getReturnMethod().put(
                properties[i],
                descriptions[i] == null ? "No description"
                    : descriptions[i]);
          }
        }
View Full Code Here

  }

  @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();
  }
View Full Code Here

    assertThat(doc.getReturnMethod()).isEmpty();
  }

  @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();
  }
View Full Code Here

    MvcResult result = mockMvc.perform(request).andExpect(status().isOk())
        .andExpect(content().contentType("application/javascript")).andReturn();

    ApiControllerTest.compare(result, ApiControllerTest.groupApisWithDoc("actionns"),
        params);
    ActionDoc doc = getCommentForMethod(result.getResponse().getContentAsString(),
        method);
    return doc;
  }
View Full Code Here

  private final static Pattern COMMENT_PATTERN = Pattern.compile("/\\*\\*([^/]*)\\*/",
      Pattern.MULTILINE);

  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;
  }
View Full Code Here

   *
   * @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"));
  }
View Full Code Here

        entry("success", "true for success, false otherwise"));
  }

  @Test
  public void testDoc2() throws Exception {
    ActionDoc doc = callApi("method2");

    assertThat(doc.isDeprecated()).isFalse();
    assertThat(doc.getMethodComment()).isEqualTo("method two doc");
    assertThat(doc.getAuthor()).isEmpty();
    assertThat(doc.getVersion()).isEqualTo("1.0");
    assertThat(doc.getParameters()).isEmpty();
    assertThat(doc.getReturnMethod()).isEmpty();
  }
View Full Code Here

    assertThat(doc.getReturnMethod()).isEmpty();
  }

  @Test
  public void testDoc3() throws Exception {
    ActionDoc doc = callApi("method3");

    assertThat(doc.isDeprecated()).isFalse();
    assertThat(doc.getMethodComment()).isEqualTo("method three doc");
    assertThat(doc.getAuthor()).isEqualTo("dbs");
    assertThat(doc.getVersion()).isEqualTo("1.0");
    assertThat(doc.getParameters()).isEmpty();
    assertThat(doc.getReturnMethod()).isEmpty();
  }
View Full Code Here

TOP

Related Classes of ch.ralscha.extdirectspring.bean.api.ActionDoc

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.