Compare commits
1 commit
2740cc53be
...
440160980d
Author | SHA1 | Date | |
---|---|---|---|
440160980d |
2 changed files with 84 additions and 1 deletions
|
@ -0,0 +1,83 @@
|
||||||
|
package de.towerdefence.server.server;
|
||||||
|
|
||||||
|
import de.towerdefence.server.IntegrationTest;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
|
||||||
|
class GetAllPlayersPaginatedAndSortedTest extends IntegrationTest {
|
||||||
|
|
||||||
|
private MockHttpServletRequestBuilder createGetAllPlayersRequest(String requestBody) {
|
||||||
|
return MockMvcRequestBuilders.get(baseUri + "/admin/players")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content(requestBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void playersExist() throws Exception {
|
||||||
|
String requestBody = "{" +
|
||||||
|
"\"page\": 0," +
|
||||||
|
"\"pageSize\": 10," +
|
||||||
|
"\"sortBy\": \"username\"," +
|
||||||
|
"\"order\": \"descending\"," +
|
||||||
|
"\"username\": \"\"" +
|
||||||
|
"}";
|
||||||
|
|
||||||
|
this.mvc.perform(createGetAllPlayersRequest(requestBody))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$").isArray())
|
||||||
|
.andExpect(jsonPath("$[0]").exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void playersSortedByAsc() throws Exception {
|
||||||
|
String requestBody = "{" +
|
||||||
|
"\"page\": 0," +
|
||||||
|
"\"pageSize\": 10," +
|
||||||
|
"\"sortBy\": \"username\"," +
|
||||||
|
"\"order\": \"ascending\"," +
|
||||||
|
"\"username\": \"\"" +
|
||||||
|
"}";
|
||||||
|
|
||||||
|
this.mvc.perform(createGetAllPlayersRequest(requestBody))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$[0].username").value("Alex"))
|
||||||
|
.andExpect(jsonPath("$[1].username").value("Zorro"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void playersSortedByDesc() throws Exception {
|
||||||
|
String requestBody = "{" +
|
||||||
|
"\"page\": 0," +
|
||||||
|
"\"pageSize\": 10," +
|
||||||
|
"\"sortBy\": \"username\"," +
|
||||||
|
"\"order\": \"descending\"," +
|
||||||
|
"\"username\": \"\"" +
|
||||||
|
"}";
|
||||||
|
|
||||||
|
this.mvc.perform(createGetAllPlayersRequest(requestBody))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$[1].username").value("Alex"))
|
||||||
|
.andExpect(jsonPath("$[0].username").value("Zorro"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void playersFiltered() throws Exception {
|
||||||
|
String requestBody = "{" +
|
||||||
|
"\"page\": 0," +
|
||||||
|
"\"pageSize\": 10," +
|
||||||
|
"\"username\": \"Alex\","+
|
||||||
|
"\"order\": \"ascending\""+
|
||||||
|
"}";
|
||||||
|
|
||||||
|
this.mvc.perform(createGetAllPlayersRequest(requestBody))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$").isArray())
|
||||||
|
.andExpect(jsonPath("$[0].username").value("Alex"))
|
||||||
|
.andExpect(jsonPath("$").isNotEmpty());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue