From a61791f3efd264f186c57ae95fb1db8e62723b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Wed, 2 Oct 2024 09:02:07 +0200 Subject: [PATCH] PMT-32: Implement Tests for Responses --- .../java/de/hmmh/pmt/project/GetAllTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/test/java/de/hmmh/pmt/project/GetAllTest.java 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..ea8fb84 --- /dev/null +++ b/src/test/java/de/hmmh/pmt/project/GetAllTest.java @@ -0,0 +1,39 @@ +package de.hmmh.pmt.project; + +import de.hmmh.pmt.IntegrationTest; + +import de.hmmh.pmt.db.Project; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasSize; +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 noProjects() throws Exception { + mvc + .perform(get(baseUri + "/project")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", empty())) + ; + } + + @Test + void multipleProjects() throws Exception { + List allProjects = createTestProjectData(); + + mvc + .perform(get(baseUri + "/project")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", hasSize(allProjects.size()))) + .andExpect(jsonPath("$[*].id").exists()) + .andExpect(jsonPath("$[*].name").exists()) + ; + } + +}