This repository has been archived by the owner on Apr 23, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
ModelTest.java
56 lines (46 loc) · 1.96 KB
/
ModelTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import io.ebean.PagedList;
import models.Computer;
import org.junit.Test;
import play.Application;
import play.inject.guice.GuiceApplicationBuilder;
import play.test.WithApplication;
import repository.ComputerRepository;
import java.util.Date;
import java.util.Optional;
import java.util.concurrent.CompletionStage;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
public class ModelTest extends WithApplication {
@Override
protected Application provideApplication() {
return new GuiceApplicationBuilder().build();
}
private String formatted(Date date) {
return new java.text.SimpleDateFormat("yyyy-MM-dd").format(date);
}
@Test
public void findById() {
final ComputerRepository computerRepository = app.injector().instanceOf(ComputerRepository.class);
final CompletionStage<Optional<Computer>> stage = computerRepository.lookup(21L);
await().atMost(1, SECONDS).until(() ->
assertThat(stage.toCompletableFuture()).isCompletedWithValueMatching(computerOptional -> {
final Computer macintosh = computerOptional.get();
return (macintosh.name.equals("Macintosh") && formatted(macintosh.introduced).equals("1984-01-24"));
})
);
}
@Test
public void pagination() {
final ComputerRepository computerRepository = app.injector().instanceOf(ComputerRepository.class);
CompletionStage<PagedList<Computer>> stage = computerRepository.page(1, 20, "name", "ASC", "");
// Test the completed result
await().atMost(1, SECONDS).until(() ->
assertThat(stage.toCompletableFuture()).isCompletedWithValueMatching(computers ->
computers.getTotalCount() == 574 &&
computers.getTotalPageCount() == 29 &&
computers.getList().size() == 20
)
);
}
}