forked from baskbuddy/zhangshun
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.5 KiB
36 lines
1.5 KiB
package com.mydreamjob.company;
|
|
|
|
import com.mydreamjob.auth.AuthSessionService;
|
|
import com.mydreamjob.auth.JwtTokenProvider;
|
|
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.autoconfigure.web.servlet.WebMvcTest;
|
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext;
|
|
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.MockMvcResultMatchers.jsonPath;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
@WebMvcTest(CompanyController.class)
|
|
@AutoConfigureMockMvc(addFilters = false)
|
|
@MockBean({JpaMetamodelMappingContext.class, JwtTokenProvider.class,
|
|
AuthSessionService.class, java.time.Clock.class})
|
|
class CompanyControllerMvcTest {
|
|
|
|
@Autowired
|
|
private MockMvc mockMvc;
|
|
|
|
@MockBean
|
|
private CompanyService companyService;
|
|
|
|
@Test
|
|
void getCompany_nonNumericId_shouldReturn400WithCode1001() throws Exception {
|
|
mockMvc.perform(get("/companies/abc"))
|
|
.andExpect(status().isBadRequest())
|
|
.andExpect(jsonPath("$.code").value(1001))
|
|
.andExpect(jsonPath("$.message").value("bad request"));
|
|
}
|
|
}
|