-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
446 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,34 @@ | ||
import org.json.JSONObject; | ||
import org.junit.Ignore; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class PlayerAPITest extends ApiTestHelper { | ||
|
||
@Test | ||
public void testPingEndpoint() throws IOException { | ||
String urlString = ApiTestHelper.getBaseUrl() + "/v1/ping"; | ||
URL url = new URL(urlString); | ||
public void testPlayersEndpoint() throws IOException { | ||
HttpURLConnection conn = sendRequest("/v1/players", "GET"); | ||
String response = ApiTestHelper.readResponse(conn); | ||
|
||
assertEquals(200, conn.getResponseCode()); | ||
assertNotNull(response); | ||
|
||
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | ||
conn.setRequestMethod("GET"); | ||
JSONObject jsonResponse = new JSONObject(response); | ||
|
||
int responseCode = conn.getResponseCode(); | ||
assertEquals(200, responseCode, "Expected response code to be 200"); | ||
assertTrue(jsonResponse.has("onlinePlayers")); | ||
assertEquals(0, jsonResponse.getJSONArray("onlinePlayers").length()); | ||
} | ||
|
||
String response = readResponse(conn); | ||
assertNotNull(response, "Response should not be null"); | ||
assertEquals("pong", response.trim(), "Expected response to be 'pong'"); | ||
@Test | ||
@Disabled | ||
public void testPlayerEndpoint() throws IOException { | ||
HttpURLConnection conn = sendRequest("/v1/player/Shweit", "GET"); | ||
assertEquals(404, conn.getResponseCode()); | ||
} | ||
} |
Oops, something went wrong.