-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractMockMVCTest.java
50 lines (42 loc) · 1.36 KB
/
AbstractMockMVCTest.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
package com.github.restup.test.spring;
import com.github.restup.test.RestApiAssertions;
import com.github.restup.test.RestApiAssertions.Builder;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
/**
* Abstract implementation for convenience, autowiring mockMvc and setting up a {@link Builder}
*/
@RunWith(SpringRunner.class)
public abstract class AbstractMockMVCTest {
private final String path;
private final Object[] pathArgs;
protected Builder api;
@Autowired
MockMvc mockMvc;
private boolean jsonapi;
protected AbstractMockMVCTest(String path, Object... pathArgs) {
this.path = path;
this.pathArgs = pathArgs;
}
@Before
public void before() {
api = builder(path, pathArgs);
}
protected Builder builder(String path, Object... pathArgs) {
MockMVCApiExecutor executor = new MockMVCApiExecutor(mockMvc);
Builder b = RestApiAssertions.builder(executor, path, pathArgs);
if (jsonapi) {
b.jsonapi();
}
return b;
}
/**
* {@link #api} will call jsonapi() for testing jsonapi request/responses
*/
public void jsonapi() {
jsonapi = true;
}
}