Hendrik Jungnitsch
2023-09-18 193135c2c85871bc497e1da5c3c25ee7610bed59
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
package de.gedoplan.seminar.sbt.di.exercise;
 
import de.gedoplan.seminar.sbt.di.exercise.domain.CocktailSamples;
import de.gedoplan.seminar.sbt.di.exercise.service.CocktailService;
import org.assertj.core.api.Assertions;
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.CoreMatchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
 
@AutoConfigureMockMvc
@SpringBootTest
public class Exercise02Test {
 
    @Autowired
    CocktailService cocktailService;
 
    @Autowired
    MockMvc mockMvc;
 
    @Test
    public void test() throws Exception {
        mockMvc.perform(get("/api/bar/cocktails"))
                .andExpect(jsonPath("$.size()",is(4)));
        Assertions.assertThat(cocktailService.findAll())
                .containsExactlyInAnyOrderElementsOf(CocktailSamples.COCKTAILS);
    }
}