cleanup tests

This commit is contained in:
Lee 2024-04-10 14:44:05 +01:00
parent 8f1bc67596
commit d156d2cb3b
3 changed files with 22 additions and 15 deletions

@ -8,8 +8,8 @@ import cc.fascinated.common.packet.impl.java.JavaPacketHandshakingInSetProtocol;
import cc.fascinated.common.packet.impl.java.JavaPacketStatusInStart; import cc.fascinated.common.packet.impl.java.JavaPacketStatusInStart;
import cc.fascinated.exception.impl.BadRequestException; import cc.fascinated.exception.impl.BadRequestException;
import cc.fascinated.exception.impl.ResourceNotFoundException; import cc.fascinated.exception.impl.ResourceNotFoundException;
import cc.fascinated.model.token.JavaServerStatusToken;
import cc.fascinated.model.server.JavaMinecraftServer; import cc.fascinated.model.server.JavaMinecraftServer;
import cc.fascinated.model.token.JavaServerStatusToken;
import cc.fascinated.service.pinger.MinecraftServerPinger; import cc.fascinated.service.pinger.MinecraftServerPinger;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;

@ -1,5 +1,6 @@
package cc.fascinated.tests; package cc.fascinated.tests;
import cc.fascinated.config.TestRedisConfig;
import cc.fascinated.model.player.Skin; import cc.fascinated.model.player.Skin;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -7,7 +8,6 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import cc.fascinated.config.TestRedisConfig;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
@ -17,30 +17,34 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest(classes = TestRedisConfig.class) @SpringBootTest(classes = TestRedisConfig.class)
class PlayerControllerTests { class PlayerControllerTests {
private final String testPlayerUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48";
private final String testPlayer = "ImFascinated";
private final String testInvalidPlayer = "invalidplayeromgyeswow";
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Test @Test
public void ensurePlayerLookupUuidSuccess() throws Exception { public void ensurePlayerLookupUuidSuccess() throws Exception {
mockMvc.perform(get("/player/eeab5f8a-18dd-4d58-af78-2b3c4543da48") mockMvc.perform(get("/player/" + testPlayerUuid)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.username").value("ImFascinated")); .andExpect(jsonPath("$.username").value(testPlayer));
} }
@Test @Test
public void ensurePlayerLookupUsernameSuccess() throws Exception { public void ensurePlayerLookupUsernameSuccess() throws Exception {
mockMvc.perform(get("/player/ImFascinated") mockMvc.perform(get("/player/" + testPlayer)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.username").value("ImFascinated")); .andExpect(jsonPath("$.username").value(testPlayer));
} }
@Test @Test
public void ensurePlayerLookupFailure() throws Exception { public void ensurePlayerLookupFailure() throws Exception {
mockMvc.perform(get("/player/invalidnamehahahahahayesslmaooo") mockMvc.perform(get("/player/" + testInvalidPlayer)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound()); .andExpect(status().isNotFound());
@ -49,7 +53,7 @@ class PlayerControllerTests {
@Test @Test
public void ensurePlayerSkinPartsLookupSuccess() throws Exception { public void ensurePlayerSkinPartsLookupSuccess() throws Exception {
for (Skin.Parts part : Skin.Parts.values()) { for (Skin.Parts part : Skin.Parts.values()) {
mockMvc.perform(get("/player/" + part.getName() + "/eeab5f8a-18dd-4d58-af78-2b3c4543da48") mockMvc.perform(get("/player/" + part.getName() + "/" + testPlayerUuid)
.accept(MediaType.IMAGE_PNG) .accept(MediaType.IMAGE_PNG)
.contentType(MediaType.IMAGE_PNG)) .contentType(MediaType.IMAGE_PNG))
.andExpect(status().isOk()); .andExpect(status().isOk());
@ -58,7 +62,7 @@ class PlayerControllerTests {
@Test @Test
public void ensurePlayerSkinPartsLookupFailure() throws Exception { public void ensurePlayerSkinPartsLookupFailure() throws Exception {
mockMvc.perform(get("/player/invalidpart/eeab5f8a-18dd-4d58-af78-2b3c4543da48")) mockMvc.perform(get("/player/invalidpart/" + testPlayer))
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
} }
} }

@ -1,12 +1,12 @@
package cc.fascinated.tests; package cc.fascinated.tests;
import cc.fascinated.config.TestRedisConfig;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import cc.fascinated.config.TestRedisConfig;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
@ -16,21 +16,24 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest(classes = TestRedisConfig.class) @SpringBootTest(classes = TestRedisConfig.class)
class ServerControllerTests { class ServerControllerTests {
private final String testServer = "play.hypixel.net";
private final String testInvalidServer = "invalidhostnamehahahahahayesslmaooo";
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Test @Test
public void ensureServerLookupSuccess() throws Exception { public void ensureServerLookupSuccess() throws Exception {
mockMvc.perform(get("/server/java/play.hypixel.net") mockMvc.perform(get("/server/java/" + testServer)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.server.hostname").value("play.hypixel.net")); .andExpect(jsonPath("$.server.hostname").value(testServer));
} }
@Test @Test
public void ensureServerLookupFailure() throws Exception { public void ensureServerLookupFailure() throws Exception {
mockMvc.perform(get("/server/java/invalidhostnamehahahahahayesslmaooo") mockMvc.perform(get("/server/java/" + testInvalidServer)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
@ -38,14 +41,14 @@ class ServerControllerTests {
@Test @Test
public void ensureServerIconLookupSuccess() throws Exception { public void ensureServerIconLookupSuccess() throws Exception {
mockMvc.perform(get("/server/icon/play.hypixel.net") mockMvc.perform(get("/server/icon/" + testServer)
.contentType(MediaType.IMAGE_PNG)) .contentType(MediaType.IMAGE_PNG))
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
@Test @Test
public void ensureBlockedServerLookupSuccess() throws Exception { public void ensureBlockedServerLookupSuccess() throws Exception {
mockMvc.perform(get("/server/blocked/play.hypixel.net") mockMvc.perform(get("/server/blocked/" + testServer)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())