forked from Realhedin/topjava02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebTest.java
More file actions
50 lines (41 loc) · 1.45 KB
/
WebTest.java
File metadata and controls
50 lines (41 loc) · 1.45 KB
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 ru.javawebinar.topjava.web;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import ru.javawebinar.topjava.service.UserService;
import javax.annotation.PostConstruct;
import javax.transaction.Transactional;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
/**
* User: gkislin
* Date: 10.08.2014
*/
@ContextConfiguration({
"classpath:spring/spring-app.xml",
"classpath:spring/spring-mvc.xml",
"classpath:spring/spring-db.xml"
})
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
abstract public class WebTest {
protected MockMvc mockMvc;
@Autowired
private UserService userService;
@Autowired
private WebApplicationContext webApplicationContext;
@PostConstruct
void postConstruct() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
}
@Before
public void setUp() {
userService.evictCache();
}
}