aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www/src/test/java/com/juick/www/NotFoundPageTest.java
blob: c01194f474710ccb96215d3b184dc98ff35d36c2 (plain) (blame)
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
package com.juick.www;

import com.juick.configuration.DataConfiguration;
import com.juick.www.configuration.WebSecurityConfig;
import com.juick.www.configuration.WwwServletConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextHierarchy;
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 javax.inject.Inject;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

/**
 * Created by aalexeev on 11/24/16.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextHierarchy({
        @ContextConfiguration(classes = {
                com.juick.www.configuration.WebAppConfiguration.class,
                WebSecurityConfig.class,
                DataConfiguration.class}),
        @ContextConfiguration(classes = {WwwServletConfiguration.class}),
})
public class NotFoundPageTest {
    @Inject
    private WebApplicationContext wac;

    private MockMvc mockMvc;

    @Before
    public void setup() {
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac)
                .apply(SecurityMockMvcConfigurers.springSecurity()).build();
    }

    @Test
    public void pageNotFoundTest() throws Exception {
        mockMvc.perform(get("/-11"))
                .andExpect(status().is4xxClientError())
                .andExpect(view().name("views/error"));

        mockMvc.perform(get("/-1"))
                .andExpect(status().is4xxClientError())
                .andExpect(view().name("views/error"));
    }
}