本文整理汇总了Java中play.test.FakeRequest类的典型用法代码示例。如果您正苦于以下问题:Java FakeRequest类的具体用法?Java FakeRequest怎么用?Java FakeRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FakeRequest类属于play.test包,在下文中一共展示了FakeRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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());
}
}
示例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());
}
}
示例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());
}
}
示例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;
}
});
}
示例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;
}
});
}
示例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;
}
});
}
示例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;
}
});
}
示例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;
}
});
}
示例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;
}
});
}
示例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;
}
});
}
示例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\"");
}
});
}
示例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");
}
});
}
示例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");
}
});
}
示例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;
}
});
}