mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
parent
ff8bbdca15
commit
da19356496
|
@ -94,7 +94,7 @@ public class UserController {
|
||||||
if (
|
if (
|
||||||
(!result.hasErrors()) &&
|
(!result.hasErrors()) &&
|
||||||
(!userManagement.getUserByName(form.getUsername()).isEmpty()) &&
|
(!userManagement.getUserByName(form.getUsername()).isEmpty()) &&
|
||||||
(userManagement.getUserByAccount(userAccount).get().getUsername() != form.getUsername())
|
(!userManagement.getUserByAccount(userAccount).get().getUsername().equals(form.getUsername()))
|
||||||
) {
|
) {
|
||||||
result.rejectValue("username", "username already in use");
|
result.rejectValue("username", "username already in use");
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,8 @@ class UserControllerIntegrationTests {
|
||||||
createTestUser("paul");
|
createTestUser("paul");
|
||||||
createTestUser("mark");
|
createTestUser("mark");
|
||||||
createTestUser("eva");
|
createTestUser("eva");
|
||||||
|
createTestUser("sarah");
|
||||||
|
createTestUser("paul");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -353,4 +355,50 @@ class UserControllerIntegrationTests {
|
||||||
).andExpect(content().string(containsString("Ungültiger Nutzername")));
|
).andExpect(content().string(containsString("Ungültiger Nutzername")));
|
||||||
assertTrue(userAccountManagement.findByUsername("eva").isPresent());
|
assertTrue(userAccountManagement.findByUsername("eva").isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithMockUser(username = "admin", password = "admin", roles = "ADMIN")
|
||||||
|
void editCustomerDetailsExeptUsername() throws Exception {
|
||||||
|
assertThat(userManagement.getUsers().findAll())
|
||||||
|
.extracting("username", "fullName", "address")
|
||||||
|
.contains(tuple("sarah", "Sarah Klaus", "Baum Weg"));
|
||||||
|
mvc.perform(post("/customers/edit/" + userManagement.getUserByName("sarah").get().getId())
|
||||||
|
// this form of construction is necessary,
|
||||||
|
// because we belive MockMvc internally uses the provided strings directly
|
||||||
|
// this leads to different behavor between tests and browser
|
||||||
|
.param("username", new String("sarah"))
|
||||||
|
.param("fullName", "Sarah Klaus")
|
||||||
|
.param("address", "Baum Straße"))
|
||||||
|
.andExpect(redirectedUrl("/customers"));
|
||||||
|
assertThat(userManagement.getUsers().findAll())
|
||||||
|
.extracting("username", "fullName", "address")
|
||||||
|
.contains(tuple("sarah", "Sarah Klaus", "Baum Straße"));
|
||||||
|
mvc.perform(get("/customers/edit/" + userManagement.getUserByName("sarah").get().getId()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(view().name("edit-customer"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithMockUser(username = "paul", password = "123")
|
||||||
|
void updateEverythingInProfileExceptUsername() throws Exception {
|
||||||
|
assertTrue(userManagement.getUserByName("paul").isPresent());
|
||||||
|
MockHttpServletRequestBuilder createMessage = post("/profile")
|
||||||
|
.param("username", new String("paul")) // explained above
|
||||||
|
.param("password", "paul")
|
||||||
|
.param("fullName", "Paul")
|
||||||
|
.param("address", "Hotel");
|
||||||
|
mvc.perform(createMessage)
|
||||||
|
.andExpect(status().is3xxRedirection())
|
||||||
|
.andExpect(redirectedUrl("/profile"));
|
||||||
|
assertThat(userManagement.getUsers().findAll())
|
||||||
|
.extracting("username", "fullName", "address")
|
||||||
|
.contains(tuple("paul", "Paul", "Hotel"));
|
||||||
|
MockHttpServletRequestBuilder login = post("/login")
|
||||||
|
.param("username", "paul")
|
||||||
|
.param("password", "paul");
|
||||||
|
mvc.perform(login)
|
||||||
|
.andExpect(status().is3xxRedirection())
|
||||||
|
.andExpect(redirectedUrl("/"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue