Exemplo n.º 1
0
 /**
  * Runs REST validation on API, stores XML results into apiEntry.
  *
  * @param apiEntry informations about API.
  */
 private void validateTreeXML(ApiEntry apiEntry) {
   StringBuilder sb = new StringBuilder(apiEntry.getMessage());
   sb.append("<results_of_REST_checking>");
   RestValidator restValidator = new RestValidator(apiEntry.getResourceNodes());
   String validation;
   if (restValidator.validateApi()) {
     validation = "Your API is RESTful.";
   } else {
     ErrsAndWarns errsAndWarns = countErrsAndWarns(apiEntry);
     if (errsAndWarns.getErrorsCount() == 0) {
       validation =
           "Your API is RESTful, but found "
               + errsAndWarns.getWarnsCount()
               + " warnings - see details of each resource.";
     } else {
       validation =
           "Your API is not RESTful, found "
               + errsAndWarns.getErrorsCount()
               + " errors and "
               + errsAndWarns.getWarnsCount()
               + " warnings - see details of each resource.";
     }
   }
   sb.append(validation);
   sb.append("</results_of_REST_checking>");
   apiEntry.setMessage(sb.toString());
 }
Exemplo n.º 2
0
 /**
  * Run REST validation on API, stores results into apiEntry.
  *
  * @param apiEntry informations about API.
  */
 private void validateTree(ApiEntry apiEntry) {
   RestValidator restValidator = new RestValidator(apiEntry.getResourceNodes());
   String validation = "";
   if (restValidator.validateApi()) {
     if (apiEntry.getQuestionnaires().evaluate().equals("")) {
       validation = "</p><h3>Great Job! The API is RESTful!</h3><p>";
     }
     validation =
         validation
             + "</p><h4>Automatically checked constraints</h4><p>Cache constraint OK!<br />Layered System constraint OK!<br />Uniform Interface OK! (for resources under the API structure)</p>";
   } else {
     ErrsAndWarns errsAndWarns = countErrsAndWarns(apiEntry);
     if (errsAndWarns.getErrorsCount() == 0) {
       validation =
           "</p><h4>Automatically checked constraints</h4><p>Cache constraint OK!<br />Layered System constraint OK!<br />Uniform Interface OK! (for resources under the API structure)<br /> But found "
               + errsAndWarns.getWarnsCount()
               + " warnings - see yellow marks below for details.</p>";
     } else {
       validation =
           "</p><h4>Automatically checked constraints</h4><p>Your API is not RESTful, found "
               + errsAndWarns.getErrorsCount()
               + " errors and "
               + errsAndWarns.getWarnsCount()
               + " warnings - see colored marks below for details.</p>";
     }
   }
   apiEntry.setMessage(validation);
 }