SmartGwtResponse { public static <T> SmartGwtResponse<T> asError(String msg) { SmartGwtResponse<T> result = new SmartGwtResponse<T>(); result.setErrorData(msg); return result; } SmartGwtResponse();  SmartGwtResponse(T singletonDataItem);  SmartGwtResponse(List<T> data);  SmartGwtResponse(int status, Integer startRow, Integer endRow, Integer totalRows, List<T> data); static SmartGwtResponse<T> asError(String msg); static SmartGwtResponse<T> asError(Throwable t); static SmartGwtResponse<T> asError(String msg, Throwable t); static SmartGwtResponse<T> asError(String fieldName, String message); static ErrorBuilder<T> asError(); List<T> getData(); Integer getEndRow(); Map<String, List<ErrorMessage>> getErrors(); Integer getStartRow(); int getStatus(); Integer getTotalRows(); static final int STATUS_FAILURE; static final int STATUS_LOGIN_INCORRECT; static final int STATUS_LOGIN_REQUIRED; static final int STATUS_LOGIN_SUCCESS; static final int STATUS_MAX_LOGIN_ATTEMPTS_EXCEEDED; static final int STATUS_SERVER_TIMEOUT; static final int STATUS_SUCCESS; static final int STATUS_TRANSPORT_ERROR; static final int STATUS_VALIDATION_ERROR; }
@Test public void testValidationError() throws Exception { SmartGwtResponse<Long> response = SmartGwtResponse.<Long>asError() .error("field1", "ERROR_F1_1") .error("field1", "ERROR_F1_2") .error("field2", "ERROR_F2") .build(); String json = mapper.writeValueAsString(response); assertEquals(("{'response':{'status':-4,'errors':{" + "'field1':[{'errorMessage':'ERROR_F1_1'},{'errorMessage':'ERROR_F1_2'}]," + "'field2':[{'errorMessage':'ERROR_F2'}]" + "}}}").replaceAll("'", "\""), json); }
@Test public void testError() throws Exception { SmartGwtResponse<Long> response = SmartGwtResponse.asError("ERROR"); String json = mapper.writeValueAsString(response); assertEquals("{'response':{'status':-1,'data':'ERROR'}}".replaceAll("'", "\""), json); }