source: Dev/branches/play-2.0.1/samples/java/computer-database-jpa/test/ModelTest.java @ 322

Last change on this file since 322 was 322, checked in by hendrikvanantwerpen, 13 years ago

Added Play! framework and application with Jena dependency. Working on
the basic things now (login/register), after that start implementing
our data model.

File size: 1.5 KB
Line 
1import org.junit.*;
2
3import java.util.*;
4
5import play.mvc.*;
6import play.test.*;
7import play.libs.F.*;
8import play.db.jpa.*;
9
10import static play.test.Helpers.*;
11import static org.fest.assertions.Assertions.*;
12
13import models.*;
14
15public class ModelTest {
16   
17    private String formatted(Date date) {
18        return new java.text.SimpleDateFormat("yyyy-MM-dd").format(date);
19    }
20
21    @Test
22    public void findById() {
23        running(fakeApplication(), new Runnable() {
24           public void run() {
25               JPA.withTransaction(new play.libs.F.Callback0() {
26                   public void invoke() {
27                       Computer macintosh = Computer.findById(21l);
28                       assertThat(macintosh.name).isEqualTo("Macintosh");
29                       assertThat(formatted(macintosh.introduced)).isEqualTo("1984-01-24");
30                   }
31               });
32           }
33        });
34    }
35   
36    @Test
37    public void pagination() {
38        running(fakeApplication(inMemoryDatabase()), new Runnable() {
39           public void run() {
40               JPA.withTransaction(new play.libs.F.Callback0() {
41                   public void invoke() {
42                       Computer.Page computers = Computer.page(1, 20, "name", "ASC", "");
43                       assertThat(computers.getTotalRowCount()).isEqualTo(574);
44                       assertThat(computers.getList().size()).isEqualTo(20);
45                   }
46               });
47           }
48        });
49    }
50   
51}
Note: See TracBrowser for help on using the repository browser.