forked from knastnt/JavaRush-Training-Topjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRootControllerTest.java
More file actions
41 lines (35 loc) · 1.4 KB
/
RootControllerTest.java
File metadata and controls
41 lines (35 loc) · 1.4 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
package ru.javawebinar.topjava.web;
import org.junit.jupiter.api.Test;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static ru.javawebinar.topjava.TestUtil.userAuth;
import static ru.javawebinar.topjava.UserTestData.ADMIN;
import static ru.javawebinar.topjava.UserTestData.USER;
class RootControllerTest extends AbstractControllerTest {
@Test
void getUsers() throws Exception {
perform(get("/users")
.with(userAuth(ADMIN)))
.andDo(print())
.andExpect(status().isOk())
.andExpect(view().name("users"))
.andExpect(forwardedUrl("/WEB-INF/jsp/users.jsp"));
}
@Test
void unAuth() throws Exception {
perform(get("/users"))
.andDo(print())
.andExpect(status().is3xxRedirection())
.andExpect(redirectedUrl("http://localhost/login"));
}
@Test
void getMeals() throws Exception {
perform(get("/meals")
.with(userAuth(USER)))
.andDo(print())
.andExpect(status().isOk())
.andExpect(view().name("meals"))
.andExpect(forwardedUrl("/WEB-INF/jsp/meals.jsp"));
}
}