/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/java/java-503-272-003/main.java
32 строки
1 KB
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
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.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.MockMvcResultMatchers.status; @SpringBootTest @AutoConfigureMockMvc class ApiControllerTest { @Autowired MockMvc mvc; @Test void publicOk() throws Exception { mvc.perform(get("/api/public")).andExpect(status().isOk()); } @Test void privateUnauthorized() throws Exception { mvc.perform(get("/api/private")).andExpect(status().isUnauthorized()); } @Test @WithMockUser(username = "demo") void privateWithUser() throws Exception { mvc.perform(get("/api/private")).andExpect(status().isOk()); } }