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()); + } + +}