All checks were successful
Quality Check / Validate OAS (push) Successful in 37s
Quality Check / Validate OAS (pull_request) Successful in 38s
Quality Check / Testing (push) Successful in 1m17s
Quality Check / Static Analysis (push) Successful in 1m24s
Quality Check / Linting (push) Successful in 1m49s
Quality Check / Linting (pull_request) Successful in 1m17s
Quality Check / Static Analysis (pull_request) Successful in 1m16s
Quality Check / Testing (pull_request) Successful in 51s
61 lines
1.8 KiB
Java
61 lines
1.8 KiB
Java
package de.towerdefence.server;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import de.towerdefence.server.player.Player;
|
|
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;
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
@SpringBootTest
|
|
@AutoConfigureMockMvc(addFilters = false)
|
|
@ActiveProfiles("test")
|
|
public abstract class IntegrationTest {
|
|
|
|
protected final static String baseUri = "/api/v1";
|
|
|
|
@Autowired
|
|
protected MockMvc mvc;
|
|
@Autowired
|
|
protected ObjectMapper objectMapper;
|
|
@Autowired
|
|
protected PlayerRepository playerRepository;
|
|
@Autowired
|
|
protected PlayerService playerService;
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
playerRepository.deleteAll();
|
|
|
|
Map<String, String> players = new HashMap<>();
|
|
players.put("Alex", "1234");
|
|
players.put("Zorro", "1234");
|
|
|
|
players.forEach((username, password) -> {
|
|
Player player = new Player();
|
|
player.setUsername(username);
|
|
try {
|
|
playerService.setPassword(player, password);
|
|
playerRepository.saveAndFlush(player);
|
|
} catch (NoSuchAlgorithmException e) {
|
|
System.err.println("Error setting password for player: " + username);
|
|
}
|
|
});
|
|
}
|
|
|
|
@AfterEach
|
|
void cleanUp() {
|
|
playerRepository.deleteAll();
|
|
}
|
|
|
|
}
|
|
|