From 7ad2a2c3b12e7d6e05a27042b340d5e7dc80f40a Mon Sep 17 00:00:00 2001 From: Erik Hohlfeld Date: Fri, 8 Dec 2023 17:15:23 +0100 Subject: [PATCH] Add class for orderCatalog integration tests --- .../CatalogControllerIntegrationTests.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/test/java/catering/orderCatalog/CatalogControllerIntegrationTests.java diff --git a/src/test/java/catering/orderCatalog/CatalogControllerIntegrationTests.java b/src/test/java/catering/orderCatalog/CatalogControllerIntegrationTests.java new file mode 100644 index 0000000..2e6b966 --- /dev/null +++ b/src/test/java/catering/orderCatalog/CatalogControllerIntegrationTests.java @@ -0,0 +1,47 @@ +package catering.orderCatalog; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.salespointframework.useraccount.Password; +import org.salespointframework.useraccount.Role; +import org.salespointframework.useraccount.UserAccountManagement; +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.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@SpringBootTest +@AutoConfigureMockMvc +public class CatalogControllerIntegrationTests { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private CatalogController catalogController; + + @Autowired + UserAccountManagement userAccountManagement; + + @BeforeEach + void setUp() { + if (userAccountManagement.findByUsername("anna").isEmpty()) { + userAccountManagement.create("anna", + Password.UnencryptedPassword.of("12345"), Role.of("CUSTOMER")); + } + } + + @Test + void customerViewsCatalog() throws Exception { + this.mockMvc.perform(get("/catalog").with(user("anna").roles("CUSTOMER"))) + .andExpect(status().isOk()) + .andExpect(view().name("catalog")) + .andDo(print()); + } + +}