Esempio n. 1
0
  public void testRunWithOnlyFormName() throws Exception {
    MockHttpServletRequest request = constructMockRequest("POST", "/document/validate", WILDCARD);
    request.setContent(("document=").getBytes()); // NOTE: need space between periods.
    MockHttpServletResponse response = invoke(request);

    assertEquals("HTTP status", HttpStatus.OK.getCode(), response.getStatus());
  }
Esempio n. 2
0
 public void testRun() throws Exception {
   MockHttpServletRequest request = constructMockRequest("POST", "/document/validate", WILDCARD);
   request.setContent("document=Foobar".getBytes());
   MockHttpServletResponse response = invoke(request);
   assertEquals("HTTP status", HttpStatus.OK.getCode(), response.getStatus());
   JSONArray errors = (JSONArray) new JSONObject(response.getContentAsString()).get("errors");
   assertEquals(0, errors.length());
 }
Esempio n. 3
0
  public void testRunWithErrors() throws Exception {
    MockHttpServletRequest request = constructMockRequest("POST", "/document/validate", WILDCARD);
    request.setContent(("document=foobar.foobar").getBytes()); // NOTE: need space between periods.
    MockHttpServletResponse response = invoke(request);

    assertEquals("HTTP status", HttpStatus.OK.getCode(), response.getStatus());
    System.out.println(response.getContentAsString());
    JSONArray errors = (JSONArray) new JSONObject(response.getContentAsString()).get("errors");
    // the following will change whenever the configuration or validator functionaliy changes
    // but it doesn't indicate what particular errors are new/missing
    // assertEquals(3, errors.length());
    assertTrue(errors.get(0).toString().length() > 0);
  }
Esempio n. 4
0
  public void testJSValidatorDoesntRunFromNonHomeDir() throws Exception {
    System.setProperty("REDPEN_HOME", ".");
    MockHttpServletRequest request =
        constructMockRequest("POST", "/document/validate/json", WILDCARD, APPLICATION_JSON);
    request.setContent(
        String.format(
                "{\"document\":\"Test, this is a test.\",\"format\":\"json2\",\"documentParser\":\"PLAIN\",\"config\":{\"lang\":\"en\",\"validators\":{\"JavaScript\":{\"properties\":{\"script-path\":\"%s\"}}}}}",
                "resources/js")
            .getBytes());
    MockHttpServletResponse response = invoke(request);

    assertEquals("HTTP status", HttpStatus.OK.getCode(), response.getStatus());
    JSONArray errors = new JSONObject(response.getContentAsString()).getJSONArray("errors");
    assertEquals(0, errors.length());
  }
Esempio n. 5
0
  public void testJSValidatorRuns() throws Exception {
    System.setProperty("REDPEN_HOME", "src/test");
    MockHttpServletRequest request =
        constructMockRequest("POST", "/document/validate/json", WILDCARD, APPLICATION_JSON);
    request.setContent(
        String.format(
                "{\"document\":\"Test, this is a test.\",\"format\":\"json2\",\"documentParser\":\"PLAIN\",\"config\":{\"lang\":\"en\",\"validators\":{\"JavaScript\":{\"properties\":{\"script-path\":\"%s\"}}}}}",
                "resources/js")
            .getBytes());
    MockHttpServletResponse response = invoke(request);

    assertEquals("HTTP status", HttpStatus.OK.getCode(), response.getStatus());
    JSONArray errors = new JSONObject(response.getContentAsString()).getJSONArray("errors");
    assertTrue(errors.length() > 0);
    for (int i = 0; i < errors.length(); ++i) {
      JSONObject o = errors.getJSONObject(i).getJSONArray("errors").getJSONObject(0);
      assertEquals("[pass.js] called", o.getString("message"));
    }
  }