package com.kaidi.oa.install; 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.test.web.servlet.MockMvc; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringBootTest( classes = InstallerApplication.class, properties = { "erp.install.token=test-token", "erp.install.version=test", "erp.install.exit-after-complete=false", "erp.install.install-root=build/installer-test", "erp.install.config-file=build/installer-test/config/erp.env", "erp.install.pending-file=build/installer-test/state/install.pending", "erp.install.lock-file=build/installer-test/state/install.lock", "erp.install.operation-lock-file=build/installer-test/state/install-operation.lock" }) @AutoConfigureMockMvc class InstallerApiTest { @Autowired private MockMvc mockMvc; @Test void setupApiRequiresOneTimeToken() throws Exception { mockMvc.perform(get("/api/install/status")) .andExpect(status().isForbidden()) .andExpect(content().json("{\"code\":40301}")); } @Test void setupStatusAndStaticPageAreAvailableWithToken() throws Exception { mockMvc.perform(get("/api/install/status").header("X-Setup-Token", "test-token")) .andExpect(status().isOk()) .andExpect(content().json("{\"code\":0,\"data\":{\"minimumPostgres\":15,\"redisRequired\":false,\"locked\":false}}", false)); mockMvc.perform(get("/")) .andExpect(status().isOk()) .andExpect(forwardedUrl("index.html")); } }