Java Code Examples for play.test.Helpers#contentAsString()

The following examples show how to use play.test.Helpers#contentAsString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrgMemberControllerTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public String getResponseCode(Result result) {
  String responseStr = Helpers.contentAsString(result);
  ObjectMapper mapper = new ObjectMapper();

  try {
    Response response = mapper.readValue(responseStr, Response.class);

    if (response != null) {
      ResponseParams params = response.getParams();
      return params.getStatus();
    }
  } catch (Exception e) {
    ProjectLogger.log(
            "BaseControllerTest:getResponseCode: Exception occurred with error message = "
                    + e.getMessage(),
            LoggerEnum.ERROR.name());
  }
  return "";
}
 
Example 2
Source File: OrganisationControllerTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public String getResponseCode(Result result) {
  String responseStr = Helpers.contentAsString(result);
  ObjectMapper mapper = new ObjectMapper();

  try {
    Response response = mapper.readValue(responseStr, Response.class);

    if (response != null) {
      ResponseParams params = response.getParams();
      return params.getStatus();
    }
  } catch (Exception e) {
    ProjectLogger.log(
        "BaseControllerTest:getResponseCode: Exception occurred with error message = "
            + e.getMessage(),
        LoggerEnum.ERROR.name());
  }
  return "";
}
 
Example 3
Source File: OrgTypeControllerTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public String getResponseCode(Result result) {
  String responseStr = Helpers.contentAsString(result);
  ObjectMapper mapper = new ObjectMapper();

  try {
    Response response = mapper.readValue(responseStr, Response.class);

    if (response != null) {
      ResponseParams params = response.getParams();
      return params.getStatus();
    }
  } catch (Exception e) {
    ProjectLogger.log(
            "BaseControllerTest:getResponseCode: Exception occurred with error message = "
                    + e.getMessage(),
            LoggerEnum.ERROR.name());
  }
  return "";
}
 
Example 4
Source File: BaseApplicationTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public String getResponseCode(Result result) {
  String responseStr = Helpers.contentAsString(result);
  ObjectMapper mapper = new ObjectMapper();

  try {
    Response response = mapper.readValue(responseStr, Response.class);

    if (response != null) {
      ResponseParams params = response.getParams();
      return params.getStatus();
    }
  } catch (Exception e) {
    ProjectLogger.log(
        "BaseControllerTest:getResponseCode: Exception occurred with error message = "
            + e.getMessage(),
        LoggerEnum.ERROR.name());
  }
  return "";
}
 
Example 5
Source File: OtpControllerTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public String getResponseCode(Result result) {
  String responseStr = Helpers.contentAsString(result);
  ObjectMapper mapper = new ObjectMapper();

  try {
    Response response = mapper.readValue(responseStr, Response.class);

    if (response != null) {
      ResponseParams params = response.getParams();
      return params.getStatus();
    }
  } catch (Exception e) {
    ProjectLogger.log(
            "BaseControllerTest:getResponseCode: Exception occurred with error message = "
                    + e.getMessage(),
            LoggerEnum.ERROR.name());
  }
  return "";
}
 
Example 6
Source File: UserDataEncryptionControllerTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public String getResponseCode(Result result) {
  String responseStr = Helpers.contentAsString(result);
  ObjectMapper mapper = new ObjectMapper();

  try {
    Response response = mapper.readValue(responseStr, Response.class);

    if (response != null) {
      ResponseParams params = response.getParams();
      return params.getStatus();
    }
  } catch (Exception e) {
    ProjectLogger.log(
            "BaseControllerTest:getResponseCode: Exception occurred with error message = "
                    + e.getMessage(),
            LoggerEnum.ERROR.name());
  }
  return "";
}
 
Example 7
Source File: UserRoleControllerTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public String getResponseCode(Result result) {
  String responseStr = Helpers.contentAsString(result);
  ObjectMapper mapper = new ObjectMapper();

  try {
    Response response = mapper.readValue(responseStr, Response.class);

    if (response != null) {
      ResponseParams params = response.getParams();
      return params.getStatus();
    }
  } catch (Exception e) {
    ProjectLogger.log(
            "BaseControllerTest:getResponseCode: Exception occurred with error message = "
                    + e.getMessage(),
            LoggerEnum.ERROR.name());
  }
  return "";
}
 
Example 8
Source File: UserStatusControllerTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public String getResponseCode(Result result) {
  String responseStr = Helpers.contentAsString(result);
  ObjectMapper mapper = new ObjectMapper();

  try {
    Response response = mapper.readValue(responseStr, Response.class);

    if (response != null) {
      ResponseParams params = response.getParams();
      return params.getStatus();
    }
  } catch (Exception e) {
    ProjectLogger.log(
            "BaseControllerTest:getResponseCode: Exception occurred with error message = "
                    + e.getMessage(),
            LoggerEnum.ERROR.name());
  }
  return "";
}
 
Example 9
Source File: UserControllerTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public String getResponseCode(Result result) {
  String responseStr = Helpers.contentAsString(result);
  ObjectMapper mapper = new ObjectMapper();

  try {
    Response response = mapper.readValue(responseStr, Response.class);

    if (response != null) {
      ResponseParams params = response.getParams();
      return params.getStatus();
    }
  } catch (Exception e) {
    ProjectLogger.log(
            "BaseControllerTest:getResponseCode: Exception occurred with error message = "
                    + e.getMessage(),
            LoggerEnum.ERROR.name());
  }
  return "";
}
 
Example 10
Source File: UserTypeControllerTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public String getResponseCode(Result result) {
  String responseStr = Helpers.contentAsString(result);
  ObjectMapper mapper = new ObjectMapper();

  try {
    Response response = mapper.readValue(responseStr, Response.class);

    if (response != null) {
      ResponseParams params = response.getParams();
      return params.getStatus();
    }
  } catch (Exception e) {
    ProjectLogger.log(
            "BaseControllerTest:getResponseCode: Exception occurred with error message = "
                    + e.getMessage(),
            LoggerEnum.ERROR.name());
  }
  return "";
}
 
Example 11
Source File: TnCControllerTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public String getResponseCode(Result result) {
  String responseStr = Helpers.contentAsString(result);
  ObjectMapper mapper = new ObjectMapper();

  try {
    Response response = mapper.readValue(responseStr, Response.class);

    if (response != null) {
      ResponseParams params = response.getParams();
      return params.getStatus();
    }
  } catch (Exception e) {
    ProjectLogger.log(
            "BaseControllerTest:getResponseCode: Exception occurred with error message = "
                    + e.getMessage(),
            LoggerEnum.ERROR.name());
  }
  return "";
}
 
Example 12
Source File: TestUtil.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public static String getResponseCode(Result result) {
  String responseStr = Helpers.contentAsString(result);
  ObjectMapper mapper = new ObjectMapper();

  try {
    Response response = mapper.readValue(responseStr, Response.class);

    if (response != null) {
      ResponseParams params = response.getParams();
      return params.getStatus();
    }
  } catch (Exception e) {
    ProjectLogger.log(
        "BaseControllerTest:getResponseCode: Exception occurred with error message = "
            + e.getMessage(),
        LoggerEnum.ERROR.name());
  }
  return "";
}
 
Example 13
Source File: UserProfileControllerTest.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
@Test
public void testProfileVisibilityFailure() {

  String data = getRequesteddata(userId);
  JsonNode json = Json.parse(data);
  RequestBuilder req =
      new RequestBuilder().bodyJson(json).uri("/v1/user/profile/visibility").method("POST");
  //req.headers(headerMap);
  Result result = Helpers.route(application,req);
  String response = Helpers.contentAsString(result);
  assertEquals(400, result.status());
}
 
Example 14
Source File: UserProfileControllerTest.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
@Test
public void testProfileVisibilityFailureWithDifferentUsedIdAndRequestedId() {

  String data = getRequesteddata("some-user-id");
  JsonNode json = Json.parse(data);
  RequestBuilder req =
      new RequestBuilder().bodyJson(json).uri("/v1/user/profile/visibility").method("POST");
  //req.headers(headerMap);
  Result result = Helpers.route(application,req);
  String response = Helpers.contentAsString(result);
  assertTrue(response.contains(ResponseCode.invalidParameterValue.getErrorCode()));
  assertEquals(400, result.status());
}