本文整理汇总了Java中play.test.Helpers类的典型用法代码示例。如果您正苦于以下问题:Java Helpers类的具体用法?Java Helpers怎么用?Java Helpers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Helpers类属于play.test包,在下文中一共展示了Helpers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateEnrolmentFutureReservationExists
import play.test.Helpers; //导入依赖的package包/类
@Test
@RunAsStudent
public void testCreateEnrolmentFutureReservationExists() throws Exception {
// Setup
reservation.setMachine(room.getExamMachines().get(0));
reservation.setStartAt(DateTime.now().plusDays(1));
reservation.setEndAt(DateTime.now().plusDays(2));
reservation.save();
DateTime enrolledOn = DateTime.now();
enrolment.setEnrolledOn(enrolledOn);
enrolment.setReservation(reservation);
enrolment.save();
// Execute
Result result = request(Helpers.POST,
String.format("/app/enroll/%s/exam/%d", exam.getCourse().getCode(), exam.getId()), null);
assertThat(result.status()).isEqualTo(200);
// Verify
List<ExamEnrolment> enrolments = Ebean.find(ExamEnrolment.class).findList();
assertThat(enrolments).hasSize(1);
ExamEnrolment e = enrolments.get(0);
assertThat(e.getEnrolledOn().isAfter(enrolledOn));
assertThat(e.getReservation()).isNull();
}
示例2: navAdminFirefox17
import play.test.Helpers; //导入依赖的package包/类
/**
* @author andre.tschirch
*
* Example test method for using specific Firefox version e.g. v17.
*
* Test method for running a successful login and the right presentation of
* the activity state of the admin navigation link, which must be active,
* for browser Firefox.
*/
// @Test
public void navAdminFirefox17() {
ProfilesIni profile = new ProfilesIni();
FirefoxProfile firefoxProfile = profile.getProfile("firefox17");
WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File("D:/schatzsuche/firefox17/firefox.exe")), firefoxProfile);
TestBrowser browser = Helpers.testBrowser(driver, 3333);
TestServer server = Helpers.testServer(3333, Helpers.fakeApplication());
TestServer startedServer = null;
try {
server.start();
startedServer = server;
new NavAdminCallbackComposite().invoke(browser);
} catch(Throwable t) {
throw new RuntimeException(t);
} finally {
if(browser != null) {
browser.quit();
}
if(startedServer != null) {
startedServer.stop();
}
}
}
示例3: startApp
import play.test.Helpers; //导入依赖的package包/类
@BeforeClass
public static void startApp() {
//createtableList();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD_PLUGIN);
entityName = "announcement";
app = Helpers.fakeApplication();
Helpers.start(app);
headerMap = new HashMap<String, String[]>();
headerMap.put(HeaderParam.X_Consumer_ID.getName(), new String[]{"Service test consumer"});
headerMap.put(HeaderParam.X_Device_ID.getName(), new String[]{"Some Device Id"});
headerMap.put(HeaderParam.X_Authenticated_Userid.getName(), new String[]{"Authenticated user id"});
headerMap.put(JsonKey.MESSAGE_ID, new String[]{"Unique Message id"});
system = ActorSystem.create("system");
ActorRef subject = system.actorOf(props);
BaseController.setActorRef(subject);
}
示例4: setUp
import play.test.Helpers; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
// Unfortunately we need to restart for each test because there is some weird issue with question id sequence.
// Ebean allocates us duplicate PKs eventually unless server is recreated in between. This is either a bug with
// Ebean (batching) or an issue with our question entity JPA mappings.
app = Helpers.fakeApplication();
Helpers.start(app);
cleanDB();
Database db = getDB();
Evolutions.applyEvolutions(db);
cleanEvolvedTables(db);
db.shutdown();
addTestData();
onBeforeLogin();
Method testMethod = getClass().getDeclaredMethod(currentTest.getMethodName());
if (testMethod.isAnnotationPresent(RunAsStudent.class)) {
loginAsStudent();
} else if (testMethod.isAnnotationPresent(RunAsTeacher.class)) {
loginAsTeacher();
} else if (testMethod.isAnnotationPresent(RunAsAdmin.class)) {
loginAsAdmin();
}
}
示例5: testCreateReservationStartIsPast
import play.test.Helpers; //导入依赖的package包/类
@Test
@RunAsStudent
public void testCreateReservationStartIsPast() throws Exception {
// Setup
DateTime start = DateTime.now().withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0).minusHours(1);
DateTime end = DateTime.now().withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0).plusHours(2);
// Execute
Result result = request(Helpers.POST, "/app/calendar/reservation",
Json.newObject().put("roomId", room.getId())
.put("examId", exam.getId())
.put("start", ISODateTimeFormat.dateTime().print(start))
.put("end", ISODateTimeFormat.dateTime().print(end)));
assertThat(result.status()).isEqualTo(400);
// Verify
ExamEnrolment ee = Ebean.find(ExamEnrolment.class, enrolment.getId());
assertThat(ee.getReservation()).isNull();
}
示例6: testCreateReservationEndsBeforeStarts
import play.test.Helpers; //导入依赖的package包/类
@Test
@RunAsStudent
public void testCreateReservationEndsBeforeStarts() throws Exception {
// Setup
DateTime start = DateTime.now().withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0).plusHours(2);
DateTime end = DateTime.now().withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0).plusHours(1);
// Execute
Result result = request(Helpers.POST, "/app/calendar/reservation",
Json.newObject().put("roomId", room.getId())
.put("examId", exam.getId())
.put("start", ISODateTimeFormat.dateTime().print(start))
.put("end", ISODateTimeFormat.dateTime().print(end)));
assertThat(result.status()).isEqualTo(400);
// Verify
ExamEnrolment ee = Ebean.find(ExamEnrolment.class, enrolment.getId());
assertThat(ee.getReservation()).isNull();
}
示例7: testRemoveReservation
import play.test.Helpers; //导入依赖的package包/类
@Test
@RunAsStudent
public void testRemoveReservation() throws Exception {
// Setup
reservation.setMachine(room.getExamMachines().get(0));
reservation.setStartAt(DateTime.now().plusHours(2));
reservation.setEndAt(DateTime.now().plusHours(3));
reservation.save();
enrolment.setReservation(reservation);
enrolment.update();
// Execute
Result result = request(Helpers.DELETE, "/app/calendar/reservation/" + reservation.getId(), null);
assertThat(result.status()).isEqualTo(200);
assertThat(greenMail.waitForIncomingEmail(MAIL_TIMEOUT, 1)).isTrue();
// Verify
ExamEnrolment ee = Ebean.find(ExamEnrolment.class, enrolment.getId());
assertThat(ee.getReservation()).isNull();
assertThat(Ebean.find(Reservation.class, reservation.getId())).isNull();
}
示例8: testRemoveReservationInPast
import play.test.Helpers; //导入依赖的package包/类
@Test
@RunAsStudent
public void testRemoveReservationInPast() throws Exception {
// Setup
reservation.setMachine(room.getExamMachines().get(0));
reservation.setStartAt(DateTime.now().minusHours(2));
reservation.setEndAt(DateTime.now().minusHours(1));
reservation.save();
enrolment.setReservation(reservation);
enrolment.update();
// Execute
Result result = request(Helpers.DELETE, "/app/calendar/reservation/" + reservation.getId(), null);
assertThat(result.status()).isEqualTo(403);
// Verify
ExamEnrolment ee = Ebean.find(ExamEnrolment.class, enrolment.getId());
assertThat(ee.getReservation().getId()).isEqualTo(reservation.getId());
}
示例9: testRemoveReservationInProgress
import play.test.Helpers; //导入依赖的package包/类
@Test
@RunAsStudent
public void testRemoveReservationInProgress() throws Exception {
// Setup
reservation.setMachine(room.getExamMachines().get(0));
reservation.setStartAt(DateTime.now().minusHours(1));
reservation.setEndAt(DateTime.now().plusHours(1));
reservation.save();
enrolment.setReservation(reservation);
enrolment.update();
// Execute
Result result = request(Helpers.DELETE, "/app/calendar/reservation/" + reservation.getId(), null);
assertThat(result.status()).isEqualTo(403);
// Verify
ExamEnrolment ee = Ebean.find(ExamEnrolment.class, enrolment.getId());
assertThat(ee.getReservation().getId()).isEqualTo(reservation.getId());
}
示例10: testConcurentCreateEnrolment
import play.test.Helpers; //导入依赖的package包/类
@Test
@RunAsStudent
public void testConcurentCreateEnrolment() throws Exception {
final int callCount = 10;
final Waiter waiter = new Waiter();
IntStream.range(0, callCount).parallel().forEach(i -> new Thread(() -> {
request(Helpers.POST,
String.format("/app/enroll/%s/exam/%d", exam.getCourse().getCode(), exam.getId()), null);
waiter.resume();
}).start());
waiter.await(5000, callCount);
final int count = Ebean.find(ExamEnrolment.class).where().eq("exam.id", exam.getId())
.eq("user.id", user.getId()).findCount();
assertThat(count).isEqualTo(1);
}
示例11: testRecreateEnrolment
import play.test.Helpers; //导入依赖的package包/类
@Test
@RunAsStudent
public void testRecreateEnrolment() throws Exception {
// Setup
DateTime enrolledOn = DateTime.now();
enrolment.setEnrolledOn(enrolledOn);
enrolment.save();
// Execute
Result result = request(Helpers.POST,
String.format("/app/enroll/%s/exam/%d", exam.getCourse().getCode(), exam.getId()), null);
assertThat(result.status()).isEqualTo(403);
assertThat(contentAsString(result)).isEqualTo("sitnet_error_enrolment_exists");
// Verify
List<ExamEnrolment> enrolments = Ebean.find(ExamEnrolment.class).findList();
assertThat(enrolments).hasSize(1);
enrolment = enrolments.get(0);
assertThat(enrolment.getEnrolledOn()).isEqualTo(enrolledOn);
}
示例12: testCreateEnrolmentOngoingReservationExists
import play.test.Helpers; //导入依赖的package包/类
@Test
@RunAsStudent
public void testCreateEnrolmentOngoingReservationExists() throws Exception {
// Setup
reservation.setMachine(room.getExamMachines().get(0));
reservation.setStartAt(DateTime.now().minusDays(1));
reservation.setEndAt(DateTime.now().plusDays(1));
reservation.save();
DateTime enrolledOn = DateTime.now();
enrolment.setEnrolledOn(enrolledOn);
enrolment.setReservation(reservation);
enrolment.save();
// Execute
Result result = request(Helpers.POST,
String.format("/app/enroll/%s/exam/%d", exam.getCourse().getCode(), exam.getId()), null);
assertThat(result.status()).isEqualTo(403); // Not found
assertThat(contentAsString(result)).isEqualTo("sitnet_reservation_in_effect");
// Verify
List<ExamEnrolment> enrolments = Ebean.find(ExamEnrolment.class).findList();
assertThat(enrolments).hasSize(1);
ExamEnrolment e = enrolments.get(0);
assertThat(e.getEnrolledOn()).isEqualTo(enrolledOn);
}
示例13: testCreateEnrolmentPastReservationExists
import play.test.Helpers; //导入依赖的package包/类
@Test
@RunAsStudent
public void testCreateEnrolmentPastReservationExists() throws Exception {
// Setup
reservation.setMachine(room.getExamMachines().get(0));
reservation.setStartAt(DateTime.now().minusDays(2));
reservation.setEndAt(DateTime.now().minusDays(1));
reservation.save();
DateTime enrolledOn = DateTime.now();
enrolment.setEnrolledOn(enrolledOn);
enrolment.setReservation(reservation);
enrolment.save();
// Execute
Result result = request(Helpers.POST,
String.format("/app/enroll/%s/exam/%d", exam.getCourse().getCode(), exam.getId()), null);
assertThat(result.status()).isEqualTo(200);
// Verify
List<ExamEnrolment> enrolments = Ebean.find(ExamEnrolment.class).findList();
assertThat(enrolments).hasSize(2);
ExamEnrolment e = enrolments.get(1);
assertThat(e.getEnrolledOn().isAfter(enrolledOn));
assertThat(e.getReservation()).isNull();
}
示例14: testDisableRoom
import play.test.Helpers; //导入依赖的package包/类
@Test
@RunAsAdmin
public void testDisableRoom() throws Exception {
// Setup
ExamRoom room = Ebean.find(ExamRoom.class, 1L);
assertThat(room.getState()).isNotEqualTo(ExamRoom.State.INACTIVE.toString());
// Execute
Result result = request(Helpers.DELETE, "/app/rooms/" + 1, null);
assertThat(result.status()).isEqualTo(200);
// Verify (both response and database)
JsonNode node = Json.parse(contentAsString(result));
ExamRoom deserialized = deserialize(ExamRoom.class, node);
assertThat(deserialized.getState()).isEqualTo(ExamRoom.State.INACTIVE.toString());
room = Ebean.find(ExamRoom.class, 1L);
assertThat(room.getState()).isEqualTo(ExamRoom.State.INACTIVE.toString());
}
示例15: testEnableRoom
import play.test.Helpers; //导入依赖的package包/类
@Test
@RunAsAdmin
public void testEnableRoom() throws Exception {
// Setup
ExamRoom room = Ebean.find(ExamRoom.class, 1L);
room.setState(ExamRoom.State.INACTIVE.toString());
room.update();
// Execute
Result result = request(Helpers.POST, "/app/rooms/" + 1, null);
assertThat(result.status()).isEqualTo(200);
// Verify (both response and database)
JsonNode node = Json.parse(contentAsString(result));
ExamRoom deserialized = deserialize(ExamRoom.class, node);
assertThat(deserialized.getState()).isEqualTo(ExamRoom.State.ACTIVE.toString());
room = Ebean.find(ExamRoom.class, 1L);
assertThat(room.getState()).isEqualTo(ExamRoom.State.ACTIVE.toString());
}