Add junit tests
This commit is contained in:
parent
99af17cacc
commit
dc0fffb3a2
@ -14,11 +14,9 @@ java {
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = uri("http://repo.athene.tech/repository/maven-central/")
|
||||
allowInsecureProtocol(true)
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
@ -47,10 +45,11 @@ dependencies {
|
||||
implementation group: 'org.webjars', name: 'bootstrap-glyphicons', version: 'bdd2cbfba0'
|
||||
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation("org.springframework.security:spring-security-test")
|
||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
|
40
src/test/java/ru/ulstu/PeriodControllerTest.java
Normal file
40
src/test/java/ru/ulstu/PeriodControllerTest.java
Normal file
@ -0,0 +1,40 @@
|
||||
package ru.ulstu;
|
||||
|
||||
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.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
public class PeriodControllerTest {
|
||||
@Autowired()
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Test
|
||||
/*
|
||||
Тест сохранения нового периода отчетности
|
||||
*/
|
||||
void testAddPeriod() throws Exception {
|
||||
String json = "{" +
|
||||
"'startDate' : '2025-05-21'," +
|
||||
"'endDate' : '2025-05-21'" +
|
||||
"}";
|
||||
this.mockMvc.perform(
|
||||
post("/admin/saveReportPeriod")
|
||||
.with(
|
||||
user("admin")
|
||||
.password("admin"))
|
||||
.content(json)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.param("save", "true"))
|
||||
.andExpect(redirectedUrl("/admin/reportPeriodList"));
|
||||
}
|
||||
}
|
31
src/test/java/ru/ulstu/ReportControllerTest.java
Normal file
31
src/test/java/ru/ulstu/ReportControllerTest.java
Normal file
@ -0,0 +1,31 @@
|
||||
package ru.ulstu;
|
||||
|
||||
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.hamcrest.Matchers.containsString;
|
||||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
|
||||
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.status;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
class ReportControllerTest {
|
||||
|
||||
@Autowired()
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Test
|
||||
/*
|
||||
Тест просмотра страницы
|
||||
*/
|
||||
void shouldReturnDefaultMessage() throws Exception {
|
||||
this.mockMvc.perform(get("/report/reportList").with(user("admin").password("admin")))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("Период отчетности")));
|
||||
}
|
||||
}
|
23
src/test/java/ru/ulstu/ReportTest.java
Normal file
23
src/test/java/ru/ulstu/ReportTest.java
Normal file
@ -0,0 +1,23 @@
|
||||
package ru.ulstu;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import ru.ulstu.report.controller.ReportController;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest
|
||||
public class ReportTest {
|
||||
|
||||
@Autowired
|
||||
private ReportController reportController;
|
||||
|
||||
@Test
|
||||
/*
|
||||
Тест наличия инициализированного контроллера
|
||||
*/
|
||||
void controllerIsPresent() throws Exception {
|
||||
assertThat(reportController).isNotNull();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user