TD-3: Test for Playername uniqueness
All checks were successful
Quality Check / Validate OAS (push) Successful in 30s
Quality Check / Linting (push) Successful in 56s
Quality Check / Testing (push) Successful in 57s
Quality Check / Static Analysis (push) Successful in 1m16s
Quality Check / Validate OAS (pull_request) Successful in 31s
Quality Check / Testing (pull_request) Successful in 57s
Quality Check / Linting (pull_request) Successful in 1m0s
Quality Check / Static Analysis (pull_request) Successful in 1m17s
All checks were successful
Quality Check / Validate OAS (push) Successful in 30s
Quality Check / Linting (push) Successful in 56s
Quality Check / Testing (push) Successful in 57s
Quality Check / Static Analysis (push) Successful in 1m16s
Quality Check / Validate OAS (pull_request) Successful in 31s
Quality Check / Testing (pull_request) Successful in 57s
Quality Check / Linting (pull_request) Successful in 1m0s
Quality Check / Static Analysis (pull_request) Successful in 1m17s
This commit is contained in:
parent
a400f3391d
commit
985915c08c
2 changed files with 41 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
|||
package de.towerdefence.server;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.towerdefence.server.player.PlayerRepository;
|
||||
import de.towerdefence.server.player.PlayerService;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -20,15 +22,17 @@ public abstract class IntegrationTest {
|
|||
protected MockMvc mvc;
|
||||
@Autowired
|
||||
protected ObjectMapper objectMapper;
|
||||
@Autowired
|
||||
protected PlayerRepository playerRepository;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
//repository.deleteAll();
|
||||
playerRepository.deleteAll();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
//repository.deleteAll();
|
||||
playerRepository.deleteAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package de.towerdefence.server.server;
|
||||
|
||||
import de.towerdefence.server.IntegrationTest;
|
||||
import de.towerdefence.server.oas.models.PlayerRegistrationData;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.RequestBuilder;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
public class PlayerRegistrationTest extends IntegrationTest {
|
||||
|
||||
@Test
|
||||
void playerUsernameIsUnique() throws Exception {
|
||||
PlayerRegistrationData body = new PlayerRegistrationData();
|
||||
body.setUsername("test");
|
||||
body.setPassword("password");
|
||||
|
||||
this.mvc
|
||||
.perform(getRequest(body))
|
||||
.andExpect(status().isCreated());
|
||||
this.mvc
|
||||
.perform(getRequest(body))
|
||||
.andExpect(status().isConflict());
|
||||
}
|
||||
|
||||
private RequestBuilder getRequest(PlayerRegistrationData playerRegistrationData) throws Exception {
|
||||
return MockMvcRequestBuilders
|
||||
.post(baseUri + "/player/register")
|
||||
.content(this.objectMapper.writeValueAsString(playerRegistrationData))
|
||||
.contentType(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue