Server/src/test/java/de/towerdefence/server/IntegrationTest.java

63 lines
1.8 KiB
Java
Raw Normal View History

2025-02-01 14:18:34 +01:00
package de.towerdefence.server;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.towerdefence.server.player.Player;
2025-02-11 14:16:35 +01:00
import de.towerdefence.server.player.PlayerRepository;
import de.towerdefence.server.player.PlayerService;
2025-02-01 14:18:34 +01:00
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;
2025-02-01 14:18:34 +01:00
@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;
2025-02-11 14:16:35 +01:00
@Autowired
protected PlayerRepository playerRepository;
@Autowired
protected PlayerService playerService;
2025-02-01 14:18:34 +01:00
@BeforeEach
void setUp() {
2025-02-11 14:16:35 +01:00
playerRepository.deleteAll();
Player player1 = new Player();
player1.setUsername("Alex");
try {
playerService.setPassword(player1, "1234");
} catch (NoSuchAlgorithmException e) {return;}
this.playerRepository.save(player1);
Player player2 = new Player();
player2.setUsername("Zorro");
try {
playerService.setPassword(player2, "1234");
} catch (NoSuchAlgorithmException e) {return;}
this.playerRepository.save(player2);
System.out.println("LISTE: " + playerRepository.findAll());
2025-02-01 14:18:34 +01:00
}
@AfterEach
void cleanUp() {
2025-02-11 14:16:35 +01:00
playerRepository.deleteAll();
2025-02-01 14:18:34 +01:00
}
}