Add class for orderCatalog integration tests

This commit is contained in:
Erik Hohlfeld 2023-12-08 17:15:23 +01:00 committed by Denis Natusch
parent e37c2506b8
commit 7ad2a2c3b1
No known key found for this signature in database
GPG key ID: 5E57BD8EDACFA985

View file

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