From 58264e1206081840cb891be140f63a67fda142f1 Mon Sep 17 00:00:00 2001 From: Connor Linfoot Date: Thu, 15 Jun 2023 01:23:13 +0100 Subject: [PATCH 1/9] Implement tests via GitHub actions --- .github/workflows/maven.yml | 4 +- .../main/java/net/hypixel/api/HypixelAPI.java | 2 + hypixel-api-example/pom.xml | 25 ++++++-- .../net/hypixel/api/example/ExampleUtil.java | 12 +++- .../example/TestAuthenticatedEndpoints.java | 64 +++++++++++++++++++ .../test/resources/junit-platform.properties | 1 + 6 files changed, 99 insertions(+), 9 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..a99d6743 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -17,4 +17,6 @@ jobs: 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-core/src/main/java/net/hypixel/api/HypixelAPI.java b/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java index 781c4ead..d3a0d299 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java @@ -304,6 +304,8 @@ private CompletableFuture get(Class clazz, Strin if (clazz == ResourceReply.class) { return checkReply((R) new ResourceReply(Utilities.GSON.fromJson(response.getBody(), JsonObject.class))); } + System.out.println(response.getStatusCode()); + System.out.println(response.getBody()); return checkReply(Utilities.GSON.fromJson(response.getBody(), clazz)); }); } diff --git a/hypixel-api-example/pom.xml b/hypixel-api-example/pom.xml index 1b625269..cf2ebafe 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,22 @@ 4.2.1 - com.konghq - unirest-java - 3.11.09 + org.junit.jupiter + junit-jupiter-api + 5.5.0 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.5.0 + test - org.apache.httpcomponents - httpclient - 4.5.13 + org.junit.jupiter + junit-jupiter-params + 5.5.0 + 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..b71005d9 --- /dev/null +++ b/hypixel-api-example/src/test/java/net/hypixel/api/example/TestAuthenticatedEndpoints.java @@ -0,0 +1,64 @@ +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); + + System.out.println(response); + 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 From 704736f0c4a3790911de0371a8fe6a7eafd41399 Mon Sep 17 00:00:00 2001 From: Connor Linfoot Date: Thu, 15 Jun 2023 01:24:52 +0100 Subject: [PATCH 2/9] revert debug --- hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java b/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java index d3a0d299..781c4ead 100644 --- a/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java +++ b/hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java @@ -304,8 +304,6 @@ private CompletableFuture get(Class clazz, Strin if (clazz == ResourceReply.class) { return checkReply((R) new ResourceReply(Utilities.GSON.fromJson(response.getBody(), JsonObject.class))); } - System.out.println(response.getStatusCode()); - System.out.println(response.getBody()); return checkReply(Utilities.GSON.fromJson(response.getBody(), clazz)); }); } From ae699d2bd25d6d6cca9cb4dacac31d61b474a985 Mon Sep 17 00:00:00 2001 From: Connor Linfoot Date: Thu, 15 Jun 2023 01:26:01 +0100 Subject: [PATCH 3/9] rename the workflow --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index a99d6743..44229a8d 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,4 +1,4 @@ -name: Maven Package +name: Maven Verify on: push: From 5816867bda91134765fed42d38aae4ba97999868 Mon Sep 17 00:00:00 2001 From: Connor Linfoot Date: Thu, 15 Jun 2023 01:28:42 +0100 Subject: [PATCH 4/9] update pom --- hypixel-api-example/pom.xml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/hypixel-api-example/pom.xml b/hypixel-api-example/pom.xml index cf2ebafe..0c0c3128 100644 --- a/hypixel-api-example/pom.xml +++ b/hypixel-api-example/pom.xml @@ -42,19 +42,7 @@ org.junit.jupiter junit-jupiter-api - 5.5.0 - test - - - org.junit.jupiter - junit-jupiter-engine - 5.5.0 - test - - - org.junit.jupiter - junit-jupiter-params - 5.5.0 + 5.9.3 test From 98620271ef4e4210d92fd896b0aa37068de84e3c Mon Sep 17 00:00:00 2001 From: Connor Linfoot Date: Thu, 15 Jun 2023 01:29:40 +0100 Subject: [PATCH 5/9] remove --- .../java/net/hypixel/api/example/TestAuthenticatedEndpoints.java | 1 - 1 file changed, 1 deletion(-) 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 index b71005d9..888083d6 100644 --- 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 @@ -28,7 +28,6 @@ void leaderboards() throws ExecutionException, InterruptedException, TimeoutExce void punishmentStats() throws ExecutionException, InterruptedException, TimeoutException { PunishmentStatsReply response = ExampleUtil.API.getPunishmentStats().get(5, TimeUnit.SECONDS); - System.out.println(response); Assertions.assertTrue(response.isSuccess()); } From e221e73995e6f9b77e76e70ae00d84c5227b12cd Mon Sep 17 00:00:00 2001 From: Connor Linfoot Date: Mon, 26 Jun 2023 11:05:32 +0100 Subject: [PATCH 6/9] Update gradle versions in README --- hypixel-api-transport-apache/README.md | 2 +- hypixel-api-transport-reactor/README.md | 2 +- hypixel-api-transport-unirest/README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hypixel-api-transport-apache/README.md b/hypixel-api-transport-apache/README.md index 0717b3f6..c75c0c63 100644 --- a/hypixel-api-transport-apache/README.md +++ b/hypixel-api-transport-apache/README.md @@ -16,7 +16,7 @@ Can also be included with Gradle. ```gradle dependencies { - implementation 'net.hypixel:hypixel-api-transport-apache:4.2.1' + implementation 'net.hypixel:hypixel-api-transport-apache:4.3' } ``` diff --git a/hypixel-api-transport-reactor/README.md b/hypixel-api-transport-reactor/README.md index 28c2dcdd..49d065f9 100644 --- a/hypixel-api-transport-reactor/README.md +++ b/hypixel-api-transport-reactor/README.md @@ -16,7 +16,7 @@ Can also be included with Gradle. ```gradle dependencies { - implementation 'net.hypixel:hypixel-api-transport-reactor:4.2.1' + implementation 'net.hypixel:hypixel-api-transport-reactor:4.3' } ``` diff --git a/hypixel-api-transport-unirest/README.md b/hypixel-api-transport-unirest/README.md index cad90016..659b7474 100644 --- a/hypixel-api-transport-unirest/README.md +++ b/hypixel-api-transport-unirest/README.md @@ -16,7 +16,7 @@ Can also be included with Gradle. ```gradle dependencies { - implementation 'net.hypixel:hypixel-api-transport-unirest:4.2.1' + implementation 'net.hypixel:hypixel-api-transport-unirest:4.3' } ``` From f8b7e6991584b2734fbaea7b915b99c927a374b6 Mon Sep 17 00:00:00 2001 From: Connor Linfoot Date: Mon, 26 Jun 2023 11:07:16 +0100 Subject: [PATCH 7/9] add back junit --- hypixel-api-example/pom.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hypixel-api-example/pom.xml b/hypixel-api-example/pom.xml index 6ee59fd5..09b501f3 100644 --- a/hypixel-api-example/pom.xml +++ b/hypixel-api-example/pom.xml @@ -40,9 +40,10 @@ 4.3 - org.apache.httpcomponents - httpclient - 4.5.14 + org.junit.jupiter + junit-jupiter-api + 5.9.3 + test From 07bf778098342265ee366c09e216d74865bdb916 Mon Sep 17 00:00:00 2001 From: Connor Linfoot Date: Tue, 5 Mar 2024 13:31:15 +0000 Subject: [PATCH 8/9] fix tests not running under example --- hypixel-api-example/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hypixel-api-example/pom.xml b/hypixel-api-example/pom.xml index 09b501f3..88304ec4 100644 --- a/hypixel-api-example/pom.xml +++ b/hypixel-api-example/pom.xml @@ -41,7 +41,7 @@ org.junit.jupiter - junit-jupiter-api + junit-jupiter 5.9.3 test From 2656f305dfacea025365590b91bf2f2e7941fe37 Mon Sep 17 00:00:00 2001 From: Connor Linfoot Date: Tue, 5 Mar 2024 13:33:42 +0000 Subject: [PATCH 9/9] attempt to update action versions --- .github/workflows/maven.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 44229a8d..95f09d49 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -10,9 +10,9 @@ 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'