Files
Backend/src/test/java/xyz/mcutils/backend/tests/ServerControllerTests.java

58 lines
2.2 KiB
Java
Raw Normal View History

2024-04-13 20:53:31 +01:00
package xyz.mcutils.backend.tests;
2024-04-10 11:06:28 +01:00
2024-04-10 14:44:05 +01:00
import cc.fascinated.config.TestRedisConfig;
2024-04-10 11:06:28 +01:00
import org.junit.jupiter.api.Test;
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.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
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.status;
@AutoConfigureMockMvc
@SpringBootTest(classes = TestRedisConfig.class)
class ServerControllerTests {
2024-04-10 14:44:05 +01:00
private final String testServer = "play.hypixel.net";
private final String testInvalidServer = "invalidhostnamehahahahahayesslmaooo";
2024-04-10 11:06:28 +01:00
@Autowired
private MockMvc mockMvc;
@Test
public void ensureServerLookupSuccess() throws Exception {
2024-04-10 14:44:05 +01:00
mockMvc.perform(get("/server/java/" + testServer)
2024-04-10 11:06:28 +01:00
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
2024-04-17 16:37:24 +01:00
.andExpect(jsonPath("$.hostname").value(testServer));
2024-04-10 11:06:28 +01:00
}
@Test
public void ensureServerLookupFailure() throws Exception {
2024-04-10 14:44:05 +01:00
mockMvc.perform(get("/server/java/" + testInvalidServer)
2024-04-10 11:06:28 +01:00
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
}
@Test
public void ensureServerIconLookupSuccess() throws Exception {
2024-04-10 14:44:05 +01:00
mockMvc.perform(get("/server/icon/" + testServer)
2024-04-10 11:06:28 +01:00
.contentType(MediaType.IMAGE_PNG))
.andExpect(status().isOk());
}
2024-04-10 14:39:12 +01:00
@Test
public void ensureBlockedServerLookupSuccess() throws Exception {
2024-04-10 14:44:05 +01:00
mockMvc.perform(get("/server/blocked/" + testServer)
2024-04-10 14:39:12 +01:00
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.blocked").value(false));
}
2024-04-10 11:06:28 +01:00
}