aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/berzerkula/builddb/controllers/BuilddbDashboardControllerTest.java
blob: c0860e35e1d14d0bbac85071063ddaba8f372629 (plain)
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
package org.berzerkula.builddb.controllers;

import org.berzerkula.builddb.config.SecurityConfig;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;

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.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

@Import(SecurityConfig.class)
@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

class BuilddbDashboardControllerTest {

    @Autowired
    private MockMvc mockMvc;

    @Test
    @WithMockUser
    void shouldReturnActuatorDashboardView() throws Exception {
        this.mockMvc.perform(get("/actuatorDashboard"))
                .andExpect(status().isOk())
                .andExpect(view().name("actuatorDashboard"))
                .andDo(print());
    }

    @Test
    @WithMockUser
    void shouldReturnAdminView() throws Exception {
        this.mockMvc.perform(get("/admin"))
                .andExpect(status().isOk())
                .andExpect(view().name("admin"))
                .andDo(print());
    }

    @Test
    @WithMockUser
    void shouldReturnClientView() throws Exception {
        this.mockMvc.perform(get("/client"))
                .andExpect(status().isOk())
                .andExpect(view().name("client"))
                .andDo(print());
    }

    @Test
    @WithMockUser
    void shouldReturnUserView() throws Exception {
        this.mockMvc.perform(get("/user"))
                .andExpect(status().isOk())
                .andExpect(view().name("user"))
                .andDo(print());
    }

}