Reworked frontend to be CRUD compliant and added tests
This commit is contained in:
@@ -2,6 +2,7 @@ plugins {
|
||||
id 'org.springframework.boot' version '2.7.3'
|
||||
id 'io.spring.dependency-management' version '1.0.13.RELEASE'
|
||||
id 'java'
|
||||
id 'org.asciidoctor.jvm.convert' version '3.3.2'
|
||||
}
|
||||
|
||||
group = 'dev.cato447'
|
||||
@@ -28,6 +29,14 @@ dependencies {
|
||||
runtimeOnly 'org.postgresql:postgresql'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation group: 'org.springframework.restdocs', name: 'spring-restdocs-mockmvc', version: '2.0.6.RELEASE'
|
||||
}
|
||||
|
||||
asciidoctor {
|
||||
|
||||
sourceDir('build/generated-snippets')
|
||||
outputDir('build/docs')
|
||||
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
|
||||
@@ -1,13 +1,61 @@
|
||||
package dev.cato447.semesteressen;
|
||||
|
||||
import dev.cato447.semesteressen.domain.Event;
|
||||
import dev.cato447.semesteressen.repository.EventRepository;
|
||||
import dev.cato447.semesteressen.service.EventService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.restdocs.RestDocumentationContextProvider;
|
||||
import org.springframework.restdocs.RestDocumentationExtension;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@ExtendWith({RestDocumentationExtension.class, SpringExtension.class})
|
||||
@SpringBootTest
|
||||
class SemesterEssenApplicationTests {
|
||||
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
private EventRepository eventRepository;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp(WebApplicationContext webApplicationContext,
|
||||
RestDocumentationContextProvider restDocumentation) {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
|
||||
.apply(documentationConfiguration(restDocumentation))
|
||||
.alwaysDo(document("{method-name}",preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
public void eventExample() throws Exception {
|
||||
|
||||
List<Event> eventList = new LinkedList<>();
|
||||
|
||||
eventList.add(new Event("Erstiessen #1", false, LocalDateTime.parse("2022-11-12T19:00:00"), 25));
|
||||
|
||||
when(eventRepository.findAll()).thenReturn(eventList);
|
||||
|
||||
this.mockMvc.perform(get("/api/events")).andExpect(status().isOk())
|
||||
.andDo(document("event"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user