forked from cexbrayat/linkit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJsonApiTest.java
150 lines (124 loc) · 3.37 KB
/
JsonApiTest.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import models.Interest;
import models.LightningTalk;
import models.Member;
import models.Talk;
import org.junit.*;
import play.mvc.Http.Response;
import play.test.Fixtures;
import play.test.FunctionalTest;
public class JsonApiTest extends FunctionalTest {
@BeforeClass
public static void setUp() {
Fixtures.deleteAllModels();
Fixtures.loadModels("init-data.yml");
}
@AfterClass
public static void tearDown() {
Fixtures.deleteAllModels();
}
@Test
public void testSpeakers() {
test("/api/members/speakers");
}
private void test(String url) {
json(url);
jsonDetails(url);
jsonp(url);
jsonpDetails(url);
}
private void json(String url) {
Response response = GET(url);
assertJson(response);
}
private void jsonDetails(String url) {
Response response = GET(url+"?details=true");
assertJson(response);
}
private void jsonp(String url) {
Response response = GET(url+"?callback=mycallback");
assertJsonp(response, "mycallback");
}
private void jsonpDetails(String url) {
Response response = GET(url+"?callback=mycallback&details=true");
assertJsonp(response, "mycallback");
}
@Test
public void testSponsors() {
test("/api/members/sponsors");
}
@Test
public void testMembers() {
test("/api/members");
}
@Test
public void testMember() {
Member m = Member.all().first();
test("/api/members/"+m.id);
}
@Test
public void testMember_notFound() {
Response r = GET("/api/members/999999");
assertStatus(404, r);
}
@Test
public void testMemberFavorites() {
Member m = Member.all().first();
test("/api/members/"+m.id+"/favorites");
}
@Test
public void testMemberFavorites_notFound() {
Response r = GET("/api/members/999999/favorites");
assertStatus(404, r);
}
@Test
public void testTalks() {
test("/api/talks");
}
@Test
public void testTalk() {
Talk t = Talk.all().first();
test("/api/talks/"+t.id);
}
@Test
public void testTalk_notFound() {
Response r = GET("/api/talks/999999");
assertStatus(404, r);
}
@Test
public void testLightningalks() {
test("/api/lightningtalks");
}
@Test
public void testLightningalk() {
LightningTalk lt = LightningTalk.all().first();
test("/api/lightningtalks/"+lt.id);
}
@Test
public void testLightningalk_notFound() {
Response r = GET("/api/lightningtalks/999999");
assertStatus(404, r);
}
@Test
public void testInterests() {
test("/api/interests");
}
@Test
public void testInterest() {
Interest i = Interest.all().first();
test("/api/interests/"+i.id);
}
@Test
public void testInterest_notFound() {
Response r = GET("/api/interests/999999");
assertStatus(404, r);
}
private void assertJson(Response response) {
assertIsOk(response);
assertContentType("application/json", response);
assertFalse(getContent(response).isEmpty());
}
private void assertJsonp(Response response, String callback) {
assertJson(response);
assertTrue(getContent(response).contains(callback));
}
}