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()); }
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()); }
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); }
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()); }
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")); } }