Java Code Examples for play.mvc.Http#RequestBuilder

The following examples show how to use play.mvc.Http#RequestBuilder . 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: StudentControllerUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenStudentPostData_whenCreatingStudent_ThenShouldReturnCreatedStudent() {
    final ObjectNode jsonNode = Json.newObject();
    jsonNode.put("firstName", "John");
    jsonNode.put("lastName", "Baeldung");
    jsonNode.put("age", 25);

    Http.RequestBuilder request = new Http.RequestBuilder()
            .method(POST)
            .bodyJson(jsonNode)
            .uri("/");

    Result result = route(app, request);
    assertEquals(CREATED, result.status());
    assertTrue(result.contentType().isPresent());
    assertEquals("application/json", result.contentType().get());
}
 
Example 2
Source File: UserSkillControllerTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
@Test
public void testGetSkill() {

  Map<String, Object> requestMap = new HashMap<>();
  Map<String, Object> innerMap = new HashMap<>();
  innerMap.put(JsonKey.USER_ID, "7687584");
  requestMap.put(JsonKey.REQUEST, innerMap);
  String data = mapToJson(requestMap);

  JsonNode json = Json.parse(data);
  Http.RequestBuilder req =
      new Http.RequestBuilder().bodyJson(json).uri("/v1/user/skill/read").method("POST");
  //req.headers(headerMap);
  Result result = Helpers.route(application,req);
  assertEquals(200, result.status());
}
 
Example 3
Source File: UserSkillEndorsementControllerTest.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
@Test
public void testAddSkillEndorsement() {
  PowerMockito.mockStatic(RequestInterceptor.class);
  when(RequestInterceptor.verifyRequestData(Mockito.anyObject()))
      .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
  Map<String, Object> requestMap = new HashMap();
  Map<String, Object> innerMap = new HashMap<>();
  innerMap.put(JsonKey.USER_ID, "{userId} uuiuhcf784508 8y8c79-fhh");
  innerMap.put(JsonKey.ENDORSED_USER_ID, "1223");
  innerMap.put(JsonKey.SKILL_NAME, "C");

  requestMap.put(JsonKey.REQUEST, innerMap);
  String data = mapToJson(requestMap);

  JsonNode json = Json.parse(data);
  Http.RequestBuilder req =
      new Http.RequestBuilder().bodyJson(json).uri("/v1/user/skill/endorse/add").method("POST");
  //req.headers(headerMap);
  Result result = Helpers.route(application,req);
  assertEquals(200, result.status());
}
 
Example 4
Source File: BulkUploadControllerTest.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
@Test
public void testGetUploadStatus() {
  Http.RequestBuilder req =
          new Http.RequestBuilder()
                  .uri("/v1/upload/status/pid")
                  .method("GET");
  Result result = Helpers.route(application, req);
  Assert.assertEquals( 200, result.status());
}
 
Example 5
Source File: OrgMemberControllerTest.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public Result performTest(String url, String method, Map map) {
  String data = mapToJson(map);
  Http.RequestBuilder req;
  if (StringUtils.isNotBlank(data)) {
    JsonNode json = Json.parse(data);
    req = new Http.RequestBuilder().bodyJson(json).uri(url).method(method);
  } else {
    req = new Http.RequestBuilder().uri(url).method(method);
  }
  //req.headers(new Http.Headers(headerMap));
  Result result = Helpers.route(application, req);
  return result;
}
 
Example 6
Source File: HomeControllerUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenRequest_whenHeadersPath_ThenCustomHeaderFieldSet() {
    Http.RequestBuilder request = new Http.RequestBuilder()
            .method(GET)
            .uri("/baeldung/headers");

    Result result = route(app, request);
    final Optional<String> headerOptional = result.header("Header-Key");
    assertTrue(headerOptional.isPresent());
    assertEquals("Some value", headerOptional.get());
}
 
Example 7
Source File: HomeControllerUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenRequest_whenCustomContentTypePath_ThenContextTypeTextHtml() {
    Http.RequestBuilder request = new Http.RequestBuilder()
            .method(GET)
            .uri("/baeldung/custom-content-type");

    Result result = route(app, request);
    assertTrue(result.contentType().isPresent());
    assertEquals("text/html", result.contentType().get());
}
 
Example 8
Source File: HomeControllerUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenRequest_whenRootPath_ThenStatusOkay() {
    Http.RequestBuilder request = new Http.RequestBuilder()
            .method(GET)
            .uri("/");

    Result result = route(app, request);
    assertEquals(OK, result.status());
}
 
Example 9
Source File: SitemapControllerTest.java    From play-sitemap-module.edulify.com with Apache License 2.0 5 votes vote down vote up
@Test @SuppressWarnings("rawtypes")
public void should_return_sitemap_file_index() {
  Call action = routes.Sitemaps.sitemap("_index");
  Http.RequestBuilder request = Helpers.fakeRequest(action);
  Result result = Helpers.route(request);
  Assertions.assertThat(result.status()).isEqualTo(Helpers.OK);
}
 
Example 10
Source File: HomeControllerUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenRequest_whenBadRequest_ThenStatusBadRequest() {
    Http.RequestBuilder request = new Http.RequestBuilder()
            .method(GET)
            .uri("/baeldung/bad-req");

    Result result = route(app, request);
    assertEquals(BAD_REQUEST, result.status());
}
 
Example 11
Source File: SitemapControllerTest.java    From play-sitemap-module.edulify.com with Apache License 2.0 5 votes vote down vote up
@Test @SuppressWarnings("rawtypes")
public void should_return_not_found_if_sitemap_file_does_not_exists() {
  Call action = routes.Sitemaps.sitemap("-fake");
  Http.RequestBuilder request = Helpers.fakeRequest(action);
  Result result = Helpers.route(request);
  Assertions.assertThat(result.status()).isEqualTo(Helpers.NOT_FOUND);
}
 
Example 12
Source File: TodoControllerTest.java    From play-rest-security with MIT License 5 votes vote down vote up
@Test
public void addTodoNoValue() {
    DemoData demoData = app.injector().instanceOf(DemoData.class);
    String authToken = demoData.user1.createToken();

    Http.RequestBuilder fakeRequest = fakeRequest(controllers.routes.TodoController.createTodo())
            .header(SecurityController.AUTH_TOKEN_HEADER, authToken);

    Result result = route(fakeRequest);

    assertEquals(BAD_REQUEST, result.status());
}
 
Example 13
Source File: HomeControllerUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenRequest_whenRootPath_ThenStatusOkay() {
    Http.RequestBuilder request = new Http.RequestBuilder()
            .method(GET)
            .uri("/");

    Result result = route(app, request);
    assertEquals(OK, result.status());
}
 
Example 14
Source File: FeedControllerTest.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
@Test
public void testGetUserFeedUnAuthorized() {
  Http.RequestBuilder req =
      new Http.RequestBuilder().uri("/v1/user/feed/1234567890").method("GET");
  Result result = Helpers.route(application, req);
  assertEquals(401, result.status());
}
 
Example 15
Source File: UserTypeControllerTest.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public Result performTest(String url, String method, Map map) {
  String data = mapToJson(map);
  Http.RequestBuilder req;
  if (StringUtils.isNotBlank(data)) {
    JsonNode json = Json.parse(data);
    req = new Http.RequestBuilder().bodyJson(json).uri(url).method(method);
  } else {
    req = new Http.RequestBuilder().uri(url).method(method);
  }
  //req.headers(new Http.Headers(headerMap));
  Result result = Helpers.route(application, req);
  return result;
}
 
Example 16
Source File: UserControllerTest.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public Result performTest(String url, String method, Map map) {
  String data = mapToJson(map);
  Http.RequestBuilder req;
  if (StringUtils.isNotBlank(data)) {
    JsonNode json = Json.parse(data);
    req = new Http.RequestBuilder().bodyJson(json).uri(url).method(method);
  } else {
    req = new Http.RequestBuilder().uri(url).method(method);
  }
  //req.headers(new Http.Headers(headerMap));
  Result result = Helpers.route(application, req);
  return result;
}
 
Example 17
Source File: UserStatusControllerTest.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public Result performTest(String url, String method, Map map) {
  String data = mapToJson(map);
  Http.RequestBuilder req;
  if (StringUtils.isNotBlank(data)) {
    JsonNode json = Json.parse(data);
    req = new Http.RequestBuilder().bodyJson(json).uri(url).method(method);
  } else {
    req = new Http.RequestBuilder().uri(url).method(method);
  }
  //req.headers(new Http.Headers(headerMap));
  Result result = Helpers.route(application, req);
  return result;
}
 
Example 18
Source File: UserRoleControllerTest.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public Result performTest(String url, String method, Map map) {
    String data = mapToJson(map);
    Http.RequestBuilder req;
    if (StringUtils.isNotBlank(data)) {
      JsonNode json = Json.parse(data);
      req = new Http.RequestBuilder().bodyJson(json).uri(url).method(method);
    } else {
      req = new Http.RequestBuilder().uri(url).method(method);
    }
//    req.headers(new Http.Headers(headerMap));
    Result result = Helpers.route(application, req);
    return result;
  }
 
Example 19
Source File: UserDataEncryptionControllerTest.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public Result performTest(String url, String method, Map map) {
  String data = mapToJson(map);
  Http.RequestBuilder req;
  if (StringUtils.isNotBlank(data)) {
    JsonNode json = Json.parse(data);
    req = new Http.RequestBuilder().bodyJson(json).uri(url).method(method);
  } else {
    req = new Http.RequestBuilder().uri(url).method(method);
  }
  //req.headers(new Http.Headers(headerMap));
  Result result = Helpers.route(application, req);
  return result;
}
 
Example 20
Source File: OtpControllerTest.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public Result performTest(String url, String method, Map map) {
  String data = mapToJson(map);
  Http.RequestBuilder req;
  if (StringUtils.isNotBlank(data)) {
    JsonNode json = Json.parse(data);
    req = new Http.RequestBuilder().bodyJson(json).uri(url).method(method);
  } else {
    req = new Http.RequestBuilder().uri(url).method(method);
  }
  //req.headers(new Http.Headers(headerMap));
  Result result = Helpers.route(application, req);
  return result;
}