mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add class for orderCatalog integration tests
This commit is contained in:
parent
e37c2506b8
commit
7ad2a2c3b1
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue