• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FakeRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中play.test.FakeRequest的典型用法代码示例。如果您正苦于以下问题:Java FakeRequest类的具体用法?Java FakeRequest怎么用?Java FakeRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FakeRequest类属于play.test包,在下文中一共展示了FakeRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: setUp

import play.test.FakeRequest; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    Map<String, String> flashData = Collections.emptyMap();
    Map<String, Object> argData = Collections.emptyMap();
    Long id = 2L;
    play.api.mvc.RequestHeader header = new FakeRequest("GET", "/").getWrappedRequest();
    Http.Request request = mock(Http.Request.class);
    Http.Context ctx = new Http.Context(id, header, request, flashData, flashData, argData);
    Http.Context.current.set(ctx);

    when(request.body()).thenReturn(new Http.RequestBody());
    keyResponse = IOUtils.toString(SelfAssessmentConnectorTest.class.getResourceAsStream("/keystoreResponse.json"));
    calculatorResponse = IOUtils.toString(SelfAssessmentConnectorTest.class.getResourceAsStream("/calculatorResponse.json"));

    timestamp = LocalTime.now().toString();
    uuid = "1";

    ObjectMapper mapper = new ObjectMapper();
    tree = mapper.readTree(keyResponse);
    calculatorResponseTree = mapper.readTree(calculatorResponse);
}
 
开发者ID:hmrc,项目名称:self-service-time-to-pay-frontend-java,代码行数:22,代码来源:BaseControllerTest.java


示例2: getAll_AuthorizedRequest_SuccessfullyGetAllAssignments

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void getAll_AuthorizedRequest_SuccessfullyGetAllAssignments() {
    Result result = callAction(routes.ref.AssignmentController.getAll(),
            authorizeRequest(new FakeRequest(), getAdmin()));

    String jsonString = contentAsString(result);
    try {
        JsonNode node = JsonHelper.removeRootElement(jsonString, Assignment.class, true);
        if (node.isArray()) {
            for (int i = 0; i < testAssignments.size(); ++i) {
                Assignment testAssignment = testAssignments.get(i);
                Assignment receivedAssignment = Json.fromJson(node.get(i), Assignment.class);
                assertThat(testAssignment.getId()).isEqualTo(receivedAssignment.getId());
            }
        } else
            Assert.fail("Returned JSON is not an array");
    } catch(JsonHelper.InvalidJSONException ex) {
        Assert.fail("Invalid json exception: " + ex.getMessage());
    }
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:21,代码来源:AssignmentControllerTest.java


示例3: getAll_AuthorizedRequest_SuccessfullyGetAllBasestations

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void getAll_AuthorizedRequest_SuccessfullyGetAllBasestations() {
    Result result = callAction(routes.ref.BasestationController.getAll(),
            authorizeRequest(new FakeRequest(), getAdmin()));

    String jsonString = contentAsString(result);
    try {
        JsonNode node = JsonHelper.removeRootElement(jsonString, Basestation.class, true);
        if (node.isArray()) {
            for (int i = 0; i < testBasestations.size(); ++i) {
                Basestation testBasestation = testBasestations.get(i);
                Basestation receivedBasestation = Json.fromJson(node.get(i), Basestation.class);
                assertThat(testBasestation.getId()).isEqualTo(receivedBasestation.getId());
            }
        } else
            Assert.fail("Returned JSON is not an array");
    } catch(JsonHelper.InvalidJSONException ex) {
        Assert.fail("Invalid json exception: " + ex.getMessage());
    }
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:21,代码来源:BasestationTest.java


示例4: get_AuthorizedRequestWithValidId_SuccessfullyGetBasestation

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void get_AuthorizedRequestWithValidId_SuccessfullyGetBasestation(){
    int index = testBasestations.size()-1;
    Basestation testBasestation = testBasestations.get(index);
    Result result = callAction(routes.ref.BasestationController.get(testBasestation.getId()),
            authorizeRequest(new FakeRequest(), getAdmin()));

    String jsonString = contentAsString(result);
    try {
        JsonNode node = JsonHelper.removeRootElement(jsonString, Basestation.class, false);
        Basestation receivedBasestation = Json.fromJson(node, Basestation.class);
        assertThat(testBasestation).isEqualTo(receivedBasestation);
    } catch(JsonHelper.InvalidJSONException ex) {
        Assert.fail("Invalid json exception: " + ex.getMessage());
    }
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:17,代码来源:BasestationTest.java


示例5: suspendUser

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void suspendUser() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(Session session, User user, FakeRequest r)
        throws Throwable {
      final UserDAO dao = new UserDAO(session, jcrom());
      assertThat(dao.checkPassword(user, "password")).isTrue();
      dao.suspend(user);
      user = dao.loadById(user.getId());
      assertThat(user.isVerified()).isFalse();
      assertThat(dao.checkPassword(user, "password")).isFalse();
      dao.unsuspend(user);
      user = dao.loadById(user.getId());
      assertThat(user.isVerified()).isTrue();
      assertThat(dao.checkPassword(user, "password")).isTrue();
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:21,代码来源:UserDAOTest.java


示例6: findById

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void findById() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(Session session, User user, FakeRequest req)
        throws Throwable {
      final CommentStore cs = injector().getInstance(CommentStore.class);
      final CommentStore.Manager csm = cs.getManager(session);
      final String targetId = UUID.randomUUID().toString();
      final String msg = "Mr. Flibble's very cross.";
      final CommentStore.Comment c = csm.create(user.getId(), targetId, msg);
      final CommentStore.Comment foundC = csm.findById(c.getId());
      assertThat(foundC).isNotNull();
      assertThat(foundC.getId()).isEqualTo(c.getId());
      assertThat(foundC).isEqualTo(c);
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:20,代码来源:CommentStoreTest.java


示例7: update

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void update() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(Session session, User user, FakeRequest req)
        throws Throwable {
      final CommentStore cs = injector().getInstance(CommentStore.class);
      final CommentStore.Manager csm = cs.getManager(session);
      final String targetId = UUID.randomUUID().toString();
      final String msg1 = "Mr. Flibble's very cross.";
      final String msg2 = "Game over, boys.";
      final CommentStore.Comment c = csm.create(user.getId(), targetId, msg1);
      assertThat(c.getMessage()).isEqualTo(msg1);
      assertThat(c.getModificationTime()).isEqualTo(c.getCreationTime());
      c.setMessage(msg2);
      // Ensure there's a time gap
      Thread.sleep(2);
      final CommentStore.Comment updatedC = csm.update(c);
      assertThat(updatedC).isNotNull();
      assertThat(updatedC.getMessage()).isEqualTo(msg2);
      assertThat(updatedC.getModificationTime().getTimeInMillis())
        .isNotEqualTo(updatedC.getCreationTime().getTimeInMillis());
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:27,代码来源:CommentStoreTest.java


示例8: delete

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void delete() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(Session session, User user, FakeRequest req)
        throws Throwable {
      final CommentStore cs = injector().getInstance(CommentStore.class);
      final CommentStore.Manager csm = cs.getManager(session);
      final String targetId = UUID.randomUUID().toString();
      final String msg = "Mr. Flibble's very cross.";
      final CommentStore.Comment c = csm.create(user.getId(), targetId, msg);
      csm.delete(c);
      final CommentStore.Comment foundC = csm.findById(c.getId());
      assertThat(foundC).isNull();
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:19,代码来源:CommentStoreTest.java


示例9: routes

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void routes() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(
        final Session session,
        final User user,
        final FakeRequest newRequest) throws Throwable {
      {
        final Call call = controllers.routes.GroupController.list();
        assertThat(call.method()).isEqualTo("GET");
        assertThat(call.url()).isEqualTo("/groups");
      }
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:18,代码来源:GroupControllerTest.java


示例10: get

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void get() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(
        final Session session,
        final User user,
        final FakeRequest newRequest) throws Throwable {
      final Result result = callAction(
          controllers.routes.ref.GroupController.get("testgroup"),
          newRequest);
      assertThat(status(result)).isEqualTo(200);
      assertThat(contentType(result)).isEqualTo("application/json");
      assertThat(charset(result)).isEqualTo("utf-8");
      assertThat(header("Cache-Control", result))
        .isEqualTo("max-age=0, must-revalidate");
      final JsonNode json = Json.parse(contentAsString(result));
      assertThat(json.isArray()).isFalse();
      assertThat(json.has("id")).isTrue();
      assertThat(json.has("name")).isTrue();
      assertThat(json.has("members")).isTrue();
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:26,代码来源:GroupControllerTest.java


示例11: delete

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void delete() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(
        final Session session,
        final User user,
        final FakeRequest newRequest) throws Throwable {
      final Result result = callAction(
          controllers.routes.ref.GroupController.delete("testgroup"),
          newRequest);
      try {
        new GroupManager(session).find("testgroup");
        fail();
      } catch (PathNotFoundException e) {
        // As expected
      }
      assertThat(status(result)).isEqualTo(204);
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:23,代码来源:GroupControllerTest.java


示例12: loginDetectsInvalidEmailAddress

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void loginDetectsInvalidEmailAddress() {
  running(fakeAorraApp(), new Runnable() {
    @Override
    public void run() {
      final Map<String,String> data = new HashMap<String,String>();
      data.put("email", "notanemailaddress");
      data.put("password", "password");
      Result result;
      {
        final FakeRequest request =
            fakeRequest().withFormUrlEncodedBody(data);
        result = callAction(
          controllers.routes.ref.Application.postLogin(),
          request);
      }
      assertThat(status(result)).isEqualTo(400);
      String pageContent = contentAsString(result);
      assertThat(pageContent).contains("name=\"email\"");
      assertThat(pageContent).contains("name=\"password\"");
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:24,代码来源:ApplicationTest.java


示例13: missingUserPopulatesFlashMessage

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void missingUserPopulatesFlashMessage() {
  running(fakeAorraApp(), new Runnable() {
    @Override
    public void run() {
      final Map<String,String> data = new HashMap<String,String>();
      data.put("email", "[email protected]");
      data.put("password", "password");
      Result result;
      {
        final FakeRequest request =
            fakeRequest().withFormUrlEncodedBody(data);
        result = callAction(
          controllers.routes.ref.Application.postLogin(),
          request);
      }
      assertThat(status(result)).isEqualTo(303);
      assertThat(header("Location", result)).isEqualTo("/login");
      assertThat(flash(result).get("error")).contains("email address or password");
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:23,代码来源:ApplicationTest.java


示例14: incorrectPasswordPopulatesFlashMessage

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void incorrectPasswordPopulatesFlashMessage() {
  running(fakeAorraApp(), new Runnable() {
    @Override
    public void run() {
      final String password = "password";
      final User user = createNewUser("[email protected]", "differentpassword");
      final Map<String,String> data = new HashMap<String,String>();
      data.put("email", user.getEmail());
      data.put("password", password);
      Result result;
      {
        final FakeRequest request =
            fakeRequest().withFormUrlEncodedBody(data);
        result = callAction(
          controllers.routes.ref.Application.postLogin(),
          request);
      }
      assertThat(status(result)).isEqualTo(303);
      assertThat(header("Location", result)).isEqualTo("/login");
      assertThat(flash(result).get("error")).contains("email address or password");
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:25,代码来源:ApplicationTest.java


示例15: invitesMustProvideName

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void invitesMustProvideName() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(
        final Session session,
        final User user,
        final FakeRequest newRequest) throws Throwable {
      final Map<String,String> data = new HashMap<String,String>();
      data.put("email", "[email protected]");
      data.put("name", "");
      final Result result = callAction(
        controllers.routes.ref.Application.postInvite(),
        newRequest.withFormUrlEncodedBody(data));
      assertThat(status(result)).isEqualTo(400);
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:20,代码来源:ApplicationTest.java


示例16: delete

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void delete() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(
        final Session session,
        final User user,
        final FakeRequest newRequest) throws Throwable {
      final String targetId = UUID.randomUUID().toString();
      final String msg = "Test message.";
      final CommentStore.Manager csm =
          injector().getInstance(CommentStore.class).getManager(session);
      final String cId = csm.create(user.getId(), targetId, msg).getId();
      final Result result = callAction(
          controllers.routes.ref.CommentController.delete(cId, targetId),
          newRequest);
      assertThat(status(result)).isEqualTo(204);
      assertThat(header("Cache-Control", result))
        .isEqualTo("max-age=0, must-revalidate");
      assertThat(csm.findById(cId)).isNull();
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:25,代码来源:CommentControllerTest.java


示例17: getFilestoreJSON

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void getFilestoreJSON() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(
        final Session session,
        final User user,
        final FakeRequest newRequest) throws Throwable {
      final Result result = callAction(
          controllers.routes.ref.FileStoreController.filestoreJson(),
          newRequest);
      assertThat(status(result)).isEqualTo(200);
      assertThat(contentType(result)).isEqualTo("application/json");
      assertThat(charset(result)).isEqualTo("utf-8");
      assertThat(header("Cache-Control", result))
        .isEqualTo("max-age=0, must-revalidate");
      final String expectedContent = (new JsonBuilder())
          .toJson(fileStore().getManager(session).getFolders())
          .toString();
      assertThat(contentAsString(result)).contains(expectedContent);
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:25,代码来源:FileStoreControllerTest.java


示例18: getFolderHTML

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void getFolderHTML() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(
        final Session session,
        final User user,
        final FakeRequest newRequest) throws Throwable {
      final FileStore.Manager fm = fileStore().getManager(session);
      for (String mime : new String[]{"text/html", "*/*"}) {
        final Result result = callAction(
            controllers.routes.ref.FileStoreController.showFolder(
                fm.getRoot().getIdentifier()),
            newRequest.withHeader("Accept", mime));
        assertThat(status(result)).isEqualTo(200);
        assertThat(contentType(result)).isEqualTo("text/html");
        assertThat(charset(result)).isEqualTo("utf-8");
        assertThat(header("Cache-Control", result))
          .isEqualTo("max-age=0, must-revalidate");
      }
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:25,代码来源:FileStoreControllerTest.java


示例19: getFolderUnsupported

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void getFolderUnsupported() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(
        final Session session,
        final User user,
        final FakeRequest newRequest) throws Throwable {
      final FileStore.Manager fm = fileStore().getManager(session);
      final Result result = callAction(
          controllers.routes.ref.FileStoreController.showFolder(
              fm.getRoot().getIdentifier()),
          newRequest.withHeader("Accept", "text/plain"));
      assertThat(status(result)).isEqualTo(Status.UNSUPPORTED_MEDIA_TYPE);
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:19,代码来源:FileStoreControllerTest.java


示例20: getFileUnsupported

import play.test.FakeRequest; //导入依赖的package包/类
@Test
public void getFileUnsupported() {
  asAdminUser(new F.Function3<Session, User, FakeRequest, Session>() {
    @Override
    public Session apply(
        final Session session,
        final User user,
        final FakeRequest newRequest) throws Throwable {
      final FileStore.Manager fm = fileStore().getManager(session);
      final Result result = callAction(
          controllers.routes.ref.FileStoreController.showFile(
              fm.getRoot().getIdentifier()),
          newRequest.withHeader("Accept", "text/plain"));
      assertThat(status(result)).isEqualTo(Status.UNSUPPORTED_MEDIA_TYPE);
      return session;
    }
  });
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:19,代码来源:FileStoreControllerTest.java



注:本文中的play.test.FakeRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MetaClass类代码示例发布时间:2022-05-21
下一篇:
Java ApprovalStore类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap