Compare commits
1 commit
440160980d
...
2740cc53be
Author | SHA1 | Date | |
---|---|---|---|
2740cc53be |
2 changed files with 1 additions and 84 deletions
|
@ -1,83 +0,0 @@
|
|||
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());
|
||||
}
|
||||
}
|
|
@ -80,4 +80,4 @@ class GetAllPlayersTest extends IntegrationTest {
|
|||
.andExpect(jsonPath("$[0].username").value("Alex"))
|
||||
.andExpect(jsonPath("$").isNotEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue