From 4032e5505ce7882d4c931fb8c69779d51bf6749f Mon Sep 17 00:00:00 2001 From: Connor Linfoot Date: Tue, 5 Mar 2024 13:36:48 +0000 Subject: [PATCH] Implement tests via GitHub actions (#602) --- .github/workflows/maven.yml | 10 +-- hypixel-api-example/pom.xml | 17 ++--- .../net/hypixel/api/example/ExampleUtil.java | 12 +++- .../example/TestAuthenticatedEndpoints.java | 63 +++++++++++++++++++ .../test/resources/junit-platform.properties | 1 + 5 files changed, 89 insertions(+), 14 deletions(-) create mode 100644 hypixel-api-example/src/test/java/net/hypixel/api/example/TestAuthenticatedEndpoints.java create mode 100644 hypixel-api-example/src/test/resources/junit-platform.properties diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 10398786..95f09d49 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,4 +1,4 @@ -name: Maven Package +name: Maven Verify on: push: @@ -10,11 +10,13 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 8 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: '8' distribution: 'adopt' - name: Build with Maven - run: mvn -B package --file pom.xml \ No newline at end of file + run: mvn -B verify --file pom.xml + env: + HYPIXEL_API_KEY: ${{ secrets.HYPIXEL_API_KEY }} \ No newline at end of file diff --git a/hypixel-api-example/pom.xml b/hypixel-api-example/pom.xml index 82d05951..88304ec4 100644 --- a/hypixel-api-example/pom.xml +++ b/hypixel-api-example/pom.xml @@ -25,6 +25,11 @@ 1.8 + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + @@ -35,14 +40,10 @@ 4.3 - com.konghq - unirest-java - 3.14.4 - - - org.apache.httpcomponents - httpclient - 4.5.14 + org.junit.jupiter + junit-jupiter + 5.9.3 + test diff --git a/hypixel-api-example/src/main/java/net/hypixel/api/example/ExampleUtil.java b/hypixel-api-example/src/main/java/net/hypixel/api/example/ExampleUtil.java index 38c15f18..6d63c7c6 100644 --- a/hypixel-api-example/src/main/java/net/hypixel/api/example/ExampleUtil.java +++ b/hypixel-api-example/src/main/java/net/hypixel/api/example/ExampleUtil.java @@ -9,11 +9,19 @@ public class ExampleUtil { + private static String getApiKey() { + String apiKey = System.getenv("HYPIXEL_API_KEY"); + if (apiKey != null) { + return apiKey; + } + + return System.getProperty("apiKey", "64bd424e-ccb0-42ed-8b66-6e42a135afb4"); // arbitrary key, replace with your own to test or use the property + } + public static final HypixelAPI API; static { - String key = System.getProperty("apiKey", "64bd424e-ccb0-42ed-8b66-6e42a135afb4"); // arbitrary key, replace with your own to test or use the property - API = new HypixelAPI(new ApacheHttpClient(UUID.fromString(key))); + API = new HypixelAPI(new ApacheHttpClient(UUID.fromString(getApiKey()))); } public static final UUID HYPIXEL = UUID.fromString("f7c77d99-9f15-4a66-a87d-c4a51ef30d19"); diff --git a/hypixel-api-example/src/test/java/net/hypixel/api/example/TestAuthenticatedEndpoints.java b/hypixel-api-example/src/test/java/net/hypixel/api/example/TestAuthenticatedEndpoints.java new file mode 100644 index 00000000..888083d6 --- /dev/null +++ b/hypixel-api-example/src/test/java/net/hypixel/api/example/TestAuthenticatedEndpoints.java @@ -0,0 +1,63 @@ +package net.hypixel.api.example; + +import net.hypixel.api.reply.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class TestAuthenticatedEndpoints { + + @Test + void boosters() throws ExecutionException, InterruptedException, TimeoutException { + BoostersReply response = ExampleUtil.API.getBoosters().get(5, TimeUnit.SECONDS); + + Assertions.assertTrue(response.isSuccess()); + } + + @Test + void leaderboards() throws ExecutionException, InterruptedException, TimeoutException { + LeaderboardsReply response = ExampleUtil.API.getLeaderboards().get(5, TimeUnit.SECONDS); + + Assertions.assertTrue(response.isSuccess()); + } + + @Test + void punishmentStats() throws ExecutionException, InterruptedException, TimeoutException { + PunishmentStatsReply response = ExampleUtil.API.getPunishmentStats().get(5, TimeUnit.SECONDS); + + Assertions.assertTrue(response.isSuccess()); + } + + @Test + void player() throws ExecutionException, InterruptedException, TimeoutException { + PlayerReply response = ExampleUtil.API.getPlayerByUuid(ExampleUtil.HYPIXEL).get(5, TimeUnit.SECONDS); + + Assertions.assertTrue(response.isSuccess()); + Assertions.assertNotNull(response.getPlayer()); + Assertions.assertNotNull(response.getPlayer().getName()); + Assertions.assertNotNull(response.getPlayer().getUuid()); + } + + @Test + void guild() throws ExecutionException, InterruptedException, TimeoutException { + GuildReply response = ExampleUtil.API.getGuildByPlayer(ExampleUtil.HYPIXEL).get(5, TimeUnit.SECONDS); + + Assertions.assertTrue(response.isSuccess()); + Assertions.assertNotNull(response.getGuild()); + Assertions.assertNotNull(response.getGuild().getName()); + Assertions.assertNotNull(response.getGuild().getId()); + } + + @Test + void counts() throws ExecutionException, InterruptedException, TimeoutException { + CountsReply response = ExampleUtil.API.getCounts().get(5, TimeUnit.SECONDS); + + Assertions.assertTrue(response.isSuccess()); + Assertions.assertTrue(response.getPlayerCount() >= 0); + Assertions.assertFalse(response.getGames().isEmpty()); + } + +} diff --git a/hypixel-api-example/src/test/resources/junit-platform.properties b/hypixel-api-example/src/test/resources/junit-platform.properties new file mode 100644 index 00000000..809878a5 --- /dev/null +++ b/hypixel-api-example/src/test/resources/junit-platform.properties @@ -0,0 +1 @@ +junit.jupiter.execution.parallel.enabled=true \ No newline at end of file