ValhallaAppTests.java 1.53 KB
package cn.fw.valhalla;

import cn.fw.common.util.ValidationUtils;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
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.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;

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

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ValhallaApplication.class})
@AutoConfigureMockMvc
class ValhallaAppTests {

    private final MockMvc mvc;

    @Autowired
    ValhallaAppTests(final MockMvc mvc) {
        this.mvc = mvc;
    }

    @Test
    public void exampleTest() throws Exception {
        this.mvc.perform(
                        get("/app/accident/demo")
                                .header("Authorization", "4B70342B7CC9709C7D76A982217570ADB407D23ECDC0763C4AD3F5D069B8DEB33C5FCE9E493D9F6DE05D532E7A8B5DD1")
                                .param("val", "12345"))
                .andExpect(status().isOk())
                .andDo(MockMvcResultHandlers.print());
    }

    @Test
    public void phoneTest() {
        String phone = "+8619142820251";
        System.out.println(ValidationUtils.checkMobile(phone));
    }
}