Merge pull request '[Feature]: Testing für Player Username Uniqueness' (!3) from story/td-3-player-registration-testing into trunk
All checks were successful
Quality Check / Validate OAS (push) Successful in 33s
Build Application / build (push) Successful in 1m4s
Quality Check / Testing (push) Successful in 1m6s
Quality Check / Linting (push) Successful in 1m9s
Build Application / build-docker (push) Successful in 14s
Quality Check / Static Analysis (push) Successful in 1m27s
Build Application / release (push) Successful in 7s
All checks were successful
Quality Check / Validate OAS (push) Successful in 33s
Build Application / build (push) Successful in 1m4s
Quality Check / Testing (push) Successful in 1m6s
Quality Check / Linting (push) Successful in 1m9s
Build Application / build-docker (push) Successful in 14s
Quality Check / Static Analysis (push) Successful in 1m27s
Build Application / release (push) Successful in 7s
Reviewed-on: #3
This commit is contained in:
commit
601d814b97
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