From 9e811d12b7c1da12c6417c44aba9eaa3f2234f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20K=C3=BCck?= Date: Mon, 30 Sep 2024 16:24:36 +0200 Subject: [PATCH] PMT-32: testing --- api/pmt.yml | 4 +++- .../java/de/hmmh/pmt/auth/AuthConfig.java | 1 - .../java/de/hmmh/pmt/IntegrationTest.java | 14 ++++++++----- .../java/de/hmmh/pmt/project/GetAllTest.java | 21 +++++++++++++++++++ 4 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 src/test/java/de/hmmh/pmt/project/GetAllTest.java diff --git a/api/pmt.yml b/api/pmt.yml index 159e6a5..b498fc0 100644 --- a/api/pmt.yml +++ b/api/pmt.yml @@ -45,4 +45,6 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/GetAllProjectsDTO" \ No newline at end of file + $ref: "#/components/schemas/GetAllProjectsDTO" + 500: + $ref: "#/components/responses/InternalError" \ No newline at end of file diff --git a/src/main/java/de/hmmh/pmt/auth/AuthConfig.java b/src/main/java/de/hmmh/pmt/auth/AuthConfig.java index 268a9ec..a1efeb1 100644 --- a/src/main/java/de/hmmh/pmt/auth/AuthConfig.java +++ b/src/main/java/de/hmmh/pmt/auth/AuthConfig.java @@ -11,7 +11,6 @@ import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy; import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; import org.springframework.security.web.session.HttpSessionEventPublisher; -import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @Configuration @EnableWebSecurity diff --git a/src/test/java/de/hmmh/pmt/IntegrationTest.java b/src/test/java/de/hmmh/pmt/IntegrationTest.java index 6df5bcc..09e7c65 100644 --- a/src/test/java/de/hmmh/pmt/IntegrationTest.java +++ b/src/test/java/de/hmmh/pmt/IntegrationTest.java @@ -8,19 +8,23 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.web.servlet.MockMvc; +import de.hmmh.pmt.db.ProjectRepository; + @SpringBootTest -@AutoConfigureMockMvc +@AutoConfigureMockMvc(addFilters = false) @ActiveProfiles("test") @ContextConfiguration(initializers = PostgresContextInitializer.class) public abstract class IntegrationTest { + + protected final static String baseUri = "/api/v1"; @Autowired - protected MockMvc mockMvc; - - //protected Repository repository; + protected MockMvc mvc; + @Autowired + protected ProjectRepository projectRepository; @BeforeEach void setUp() { - //repository.deleteAll(); + projectRepository.deleteAll(); } } diff --git a/src/test/java/de/hmmh/pmt/project/GetAllTest.java b/src/test/java/de/hmmh/pmt/project/GetAllTest.java new file mode 100644 index 0000000..849831c --- /dev/null +++ b/src/test/java/de/hmmh/pmt/project/GetAllTest.java @@ -0,0 +1,21 @@ +package de.hmmh.pmt.project; + +import de.hmmh.pmt.IntegrationTest; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.empty; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +public class GetAllTest extends IntegrationTest { + @Test + void emptyList() throws Exception { + assert projectRepository.findAll().isEmpty(); + mvc + .perform(get(baseUri + "/project")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", empty())); + } + +}