Hendrik Jungnitsch
2023-09-19 de447d5f944d19d617181003fcacd3674976933a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package de.gedoplan.seminar.jpa.exercise;
 
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
import java.util.stream.Stream;
 
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
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 com.fasterxml.jackson.databind.ObjectMapper;
 
import de.gedoplan.seminar.jpa.exercise.domain.Junction;
import de.gedoplan.seminar.jpa.exercise.domain.JunctionKind;
 
@TestMethodOrder(MethodOrderer.MethodName.class)
@AutoConfigureMockMvc
@SpringBootTest
public class Exercise02Test {
 
    // Sample junctions
    // ... of A1
    private static Junction testJunctionSchwerte = new Junction("Schwerte", JunctionKind.EXIT, "85");
    private static Junction testJunctionKreuzWesthofen = new Junction("Westhofener Kreuz", JunctionKind.INTERCHANGE,
            "86");
    private static Junction testJunctionHagenNord = new Junction("Hagen-Nord", JunctionKind.EXIT, "87");
    // ... of A2
    private static Junction testJunctionHerfordBadSalzuflen = new Junction("Herford/Bad Salzuflen", JunctionKind.EXIT,
            "29");
    private static Junction testJunctionBielefeldOst = new Junction("Bielefeld-Ost", JunctionKind.EXIT, "27");
    private static Junction testJunctionOWL = new Junction("Ostwestfalen/Lippe", JunctionKind.EXIT, "28");
    // ... of A33
    private static Junction testJunctionPaderbornZentrum = new Junction("Paderborn-Zentrum", JunctionKind.EXIT, "17");
 
    @Autowired
    MockMvc mockMvc;
 
    @Autowired
    private ObjectMapper mapper;
 
    @ParameterizedTest
    @MethodSource("getTestJunctions")
    void test01_insert(Junction junction) throws Exception {
        mockMvc.perform(
                post("/junctions").contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(junction)))
                .andExpect(status().isOk());
    }
 
    private static Stream<Junction> getTestJunctions() {
        return Stream.of(testJunctionSchwerte, testJunctionKreuzWesthofen, testJunctionHagenNord,
                testJunctionHerfordBadSalzuflen, testJunctionBielefeldOst, testJunctionOWL,
                testJunctionPaderbornZentrum);
    }
}