From 061d04e55c80914ffbda1f2d4e1845cfe3734a4d Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Tue, 2 Jul 2024 11:11:24 -0600 Subject: [PATCH 01/17] add rest of versions --- .github/workflows/test.yml | 78 +++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4d17ab3..37b5ee1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,65 +6,65 @@ on: - "master" - "develop" pull_request: - types: [ ready_for_review, synchronize, opened ] + types: [ready_for_review, synchronize, opened] jobs: format: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} - - name: Merge Conflict finder - uses: olivernybroe/action-conflict-finder@v1.1 + - name: Merge Conflict finder + uses: olivernybroe/action-conflict-finder@v1.1 - - name: Use Java Version 8 - uses: actions/setup-java@v2 - with: - distribution: 'adopt' - java-version: 8 - cache: 'gradle' + - name: Use Java Version 8 + uses: actions/setup-java@v2 + with: + distribution: "adopt" + java-version: 8 + cache: "gradle" - - name: Format code - run: gradle format + - name: Format code + run: gradle format - - name: Commit fixed code - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: "style: resolve style guide violations" - branch: ${{ github.head_ref }} + - name: Commit fixed code + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "style: resolve style guide violations" + branch: ${{ github.head_ref }} unit: runs-on: ubuntu-latest strategy: matrix: # test against the latest update of each major Java version, as well as specific updates of LTS versions: - java: [ 8, 11, 15, 16, 17 ] + java: [8, 11, 15, 16, 17, 18, 19, 20, 21, 22] steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} - - name: Merge Conflict finder - uses: olivernybroe/action-conflict-finder@v1.1 + - name: Merge Conflict finder + uses: olivernybroe/action-conflict-finder@v1.1 - - name: Use Java Version ${{ matrix.java }} - uses: actions/setup-java@v2 - with: - distribution: 'zulu' - java-version: ${{ matrix.java }} - cache: 'gradle' + - name: Use Java Version ${{ matrix.java }} + uses: actions/setup-java@v2 + with: + distribution: "zulu" + java-version: ${{ matrix.java }} + cache: "gradle" - - name: Install - run: gradle dependencies + - name: Install + run: gradle dependencies - - name: Test - run: gradle test && gradle jacocoTestReport + - name: Test + run: gradle test && gradle jacocoTestReport - - name: Codecov - run: bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} + - name: Codecov + run: bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} From cec7974b79c46bffa89cbfbfc409a32ef1d6efae Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Tue, 2 Jul 2024 11:14:57 -0600 Subject: [PATCH 02/17] remove locks --- .../arkecosystem/client/api/LocksTest.java | 55 ------------------- .../java/org/arkecosystem/client/api/Api.java | 2 - .../org/arkecosystem/client/api/Locks.java | 38 ------------- .../arkecosystem/client/api/LocksTest.java | 50 ----------------- 4 files changed, 145 deletions(-) delete mode 100644 src/integration/java/org/arkecosystem/client/api/LocksTest.java delete mode 100644 src/main/java/org/arkecosystem/client/api/Locks.java delete mode 100644 src/test/java/org/arkecosystem/client/api/LocksTest.java diff --git a/src/integration/java/org/arkecosystem/client/api/LocksTest.java b/src/integration/java/org/arkecosystem/client/api/LocksTest.java deleted file mode 100644 index 83d230d..0000000 --- a/src/integration/java/org/arkecosystem/client/api/LocksTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.arkecosystem.client.api; - -import org.arkecosystem.client.BaseClientTest; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.util.Collections; -import java.util.Map; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasEntry; -import static org.hamcrest.Matchers.hasKey; - -@SuppressWarnings("unchecked") -public class LocksTest extends BaseClientTest { - - @Test - void all() throws IOException { - Map actual = connection.api().locks.all(); - assertThat(actual, hasKey("meta")); - assertThat(actual, hasKey("data")); - } - - @Test - void allWithParams() throws IOException { - Map actual = - connection.api().locks.param("page", 1).param("limit", 2).all(); - assertThat(actual, hasKey("meta")); - assertThat(actual, hasKey("data")); - assertThat((Map) actual.get("meta"), hasEntry("count", 2.0)); - } - - @Test - void show() throws IOException { - Map actual = connection.api().locks.show("d8e7491055f5b34c0c954da9d4e184f1bdef3fbfe3dfc81d312c81899fbfc74d"); - assertThat(actual, hasKey("data")); - assertThat((Map) actual.get("data"), hasEntry("lockId", "d8e7491055f5b34c0c954da9d4e184f1bdef3fbfe3dfc81d312c81899fbfc74d")); - } - - @Test - void searchUnlocked() throws IOException { - Map actual = connection.api().locks.searchUnlocked(Collections.singletonMap("ids", Collections.singletonList("d8e7491055f5b34c0c954da9d4e184f1bdef3fbfe3dfc81d312c81899fbfc74d"))); - assertThat(actual, hasKey("meta")); - assertThat(actual, hasKey("data")); - assertThat((Map) actual.get("meta"), hasEntry("count", 0.0)); - } - - @Test - void searchUnlockedWithParams() throws IOException { - Map actual = connection.api().locks.param("ids", Collections.singletonList("d8e7491055f5b34c0c954da9d4e184f1bdef3fbfe3dfc81d312c81899fbfc74d")).searchUnlocked(); - assertThat(actual, hasKey("meta")); - assertThat(actual, hasKey("data")); - assertThat((Map) actual.get("meta"), hasEntry("count", 0.0)); - } -} diff --git a/src/main/java/org/arkecosystem/client/api/Api.java b/src/main/java/org/arkecosystem/client/api/Api.java index b177ca4..089e3f1 100644 --- a/src/main/java/org/arkecosystem/client/api/Api.java +++ b/src/main/java/org/arkecosystem/client/api/Api.java @@ -8,7 +8,6 @@ public class Api { public final Blocks blocks; public final Delegates delegates; public final Entities entities; - public final Locks locks; public final Node node; public final Peers peers; public final Rounds rounds; @@ -21,7 +20,6 @@ public Api(Client client) { this.blocks = new Blocks(client); this.delegates = new Delegates(client); this.entities = new Entities(client); - this.locks = new Locks(client); this.node = new Node(client); this.peers = new Peers(client); this.rounds = new Rounds(client); diff --git a/src/main/java/org/arkecosystem/client/api/Locks.java b/src/main/java/org/arkecosystem/client/api/Locks.java deleted file mode 100644 index 3226841..0000000 --- a/src/main/java/org/arkecosystem/client/api/Locks.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.arkecosystem.client.api; - -import java.io.IOException; -import java.util.LinkedHashMap; -import java.util.Map; -import org.arkecosystem.client.http.Client; - -public class Locks implements SupportsParams { - private final Client client; - - private final Map params = new LinkedHashMap<>(); - - public Locks(Client client) { - this.client = client; - } - - @Override - public Locks param(String name, Object value) { - params.put(name, value); - return this; - } - - public Map all() throws IOException { - return this.client.get("locks", params); - } - - public Map show(String id) throws IOException { - return this.client.get("locks/" + id); - } - - public Map searchUnlocked() throws IOException { - return this.client.post("locks/unlocked", params); - } - - public Map searchUnlocked(Map parameters) throws IOException { - return this.client.post("locks/unlocked", parameters); - } -} diff --git a/src/test/java/org/arkecosystem/client/api/LocksTest.java b/src/test/java/org/arkecosystem/client/api/LocksTest.java deleted file mode 100644 index 115f82a..0000000 --- a/src/test/java/org/arkecosystem/client/api/LocksTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.arkecosystem.client.api; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import org.arkecosystem.client.Connection; -import org.arkecosystem.client.MockHelper; -import org.junit.jupiter.api.Test; - -public class LocksTest { - - @Test - void all() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().locks.all(); - assertTrue((boolean) actual.get("success")); - } - - @Test - void allWithParams() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = - connection.api().locks.param("page", 1).param("limit", 100).all(); - assertTrue((boolean) actual.get("success")); - } - - @Test - void show() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().locks.show("dummy"); - assertTrue((boolean) actual.get("success")); - } - - @Test - void searchUnlocked() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().locks.searchUnlocked(); - assertTrue((boolean) actual.get("success")); - } - - @Test - void searchUnlockedWithParams() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = - connection.api().locks.searchUnlocked(Collections.singletonMap("page", 1)); - assertTrue((boolean) actual.get("success")); - } -} From c0d92596547b1d1e42481c11919b9b813328cd65 Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Tue, 2 Jul 2024 11:23:11 -0600 Subject: [PATCH 03/17] add api nodes --- .../arkecosystem/client/api/ApiNodesTest.java | 30 +++++++++++++++++++ .../java/org/arkecosystem/client/api/Api.java | 2 ++ .../org/arkecosystem/client/api/ApiNodes.java | 26 ++++++++++++++++ .../arkecosystem/client/api/ApiNodesTest.java | 27 +++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 src/integration/java/org/arkecosystem/client/api/ApiNodesTest.java create mode 100644 src/main/java/org/arkecosystem/client/api/ApiNodes.java create mode 100644 src/test/java/org/arkecosystem/client/api/ApiNodesTest.java diff --git a/src/integration/java/org/arkecosystem/client/api/ApiNodesTest.java b/src/integration/java/org/arkecosystem/client/api/ApiNodesTest.java new file mode 100644 index 0000000..a40b5ca --- /dev/null +++ b/src/integration/java/org/arkecosystem/client/api/ApiNodesTest.java @@ -0,0 +1,30 @@ +package org.arkecosystem.client.api; + +import org.arkecosystem.client.BaseClientTest; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasKey; + +@SuppressWarnings("unchecked") +public class ApiNodesIntegrationTest extends BaseClientTest { + + @Test + void all() throws IOException { + Map actual = connection.api().apiNodes.all(); + assertThat(actual, hasKey("data")); + assertThat(actual, hasKey("meta")); + } + + @Test + void allWithParams() throws IOException { + Map actual = + connection.api().apiNodes.param("page", 1).param("limit", 100).all(); + assertThat(actual, hasKey("data")); + assertThat(actual, hasKey("meta")); + } +} diff --git a/src/main/java/org/arkecosystem/client/api/Api.java b/src/main/java/org/arkecosystem/client/api/Api.java index 089e3f1..ab8f7ac 100644 --- a/src/main/java/org/arkecosystem/client/api/Api.java +++ b/src/main/java/org/arkecosystem/client/api/Api.java @@ -14,6 +14,7 @@ public class Api { public final Transactions transactions; public final Votes votes; public final Wallets wallets; + public final ApiNodes apiNodes; public Api(Client client) { this.blockchain = new Blockchain(client); @@ -26,5 +27,6 @@ public Api(Client client) { this.transactions = new Transactions(client); this.votes = new Votes(client); this.wallets = new Wallets(client); + this.apiNodes = new ApiNodes(client); } } diff --git a/src/main/java/org/arkecosystem/client/api/ApiNodes.java b/src/main/java/org/arkecosystem/client/api/ApiNodes.java new file mode 100644 index 0000000..1667b59 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/ApiNodes.java @@ -0,0 +1,26 @@ +package org.arkecosystem.client.api; + +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; +import org.arkecosystem.client.http.Client; + +public class ApiNodes implements SupportsParams { + private final Client client; + + private final Map params = new LinkedHashMap<>(); + + public ApiNodes(Client client) { + this.client = client; + } + + @Override + public ApiNodes param(String name, Object value) { + params.put(name, value); + return this; + } + + public Map all() throws IOException { + return this.client.get("api-nodes", params); + } +} diff --git a/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java b/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java new file mode 100644 index 0000000..b0fa9dc --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java @@ -0,0 +1,27 @@ +package org.arkecosystem.client.api; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.util.Map; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +public class ApiNodesTest { + + @Test + void all() throws IOException { + Connection connection = MockHelper.connection(); + Map actual = connection.api().apiNodes.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + void allWithParams() throws IOException { + Connection connection = MockHelper.connection(); + Map actual = + connection.api().apiNodes.param("page", 1).param("limit", 100).all(); + assertTrue((boolean) actual.get("success")); + } +} From fba7ab9d9e66c53d77e2efc3aa984409c5f7a02c Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Tue, 2 Jul 2024 11:25:59 -0600 Subject: [PATCH 04/17] add commits class --- .../arkecosystem/client/api/CommitsTest.java | 20 +++++++++++++++++++ .../java/org/arkecosystem/client/api/Api.java | 3 ++- .../org/arkecosystem/client/api/Commits.java | 17 ++++++++++++++++ .../arkecosystem/client/api/CommitsTest.java | 19 ++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/integration/java/org/arkecosystem/client/api/CommitsTest.java create mode 100644 src/main/java/org/arkecosystem/client/api/Commits.java create mode 100644 src/test/java/org/arkecosystem/client/api/CommitsTest.java diff --git a/src/integration/java/org/arkecosystem/client/api/CommitsTest.java b/src/integration/java/org/arkecosystem/client/api/CommitsTest.java new file mode 100644 index 0000000..e9733db --- /dev/null +++ b/src/integration/java/org/arkecosystem/client/api/CommitsTest.java @@ -0,0 +1,20 @@ +package org.arkecosystem.client.api; + +import org.arkecosystem.client.BaseClientTest; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasKey; + +@SuppressWarnings("unchecked") +public class CommitsIntegrationTest extends BaseClientTest { + + @Test + void show() throws IOException { + Map actual = connection.api().commits.show(123456); + assertThat(actual, hasKey("data")); + } +} diff --git a/src/main/java/org/arkecosystem/client/api/Api.java b/src/main/java/org/arkecosystem/client/api/Api.java index ab8f7ac..63f48fa 100644 --- a/src/main/java/org/arkecosystem/client/api/Api.java +++ b/src/main/java/org/arkecosystem/client/api/Api.java @@ -3,7 +3,6 @@ import org.arkecosystem.client.http.Client; public class Api { - public final Blockchain blockchain; public final Blocks blocks; public final Delegates delegates; @@ -15,6 +14,7 @@ public class Api { public final Votes votes; public final Wallets wallets; public final ApiNodes apiNodes; + public final Commits commits; public Api(Client client) { this.blockchain = new Blockchain(client); @@ -28,5 +28,6 @@ public Api(Client client) { this.votes = new Votes(client); this.wallets = new Wallets(client); this.apiNodes = new ApiNodes(client); + this.commits = new Commits(client); } } diff --git a/src/main/java/org/arkecosystem/client/api/Commits.java b/src/main/java/org/arkecosystem/client/api/Commits.java new file mode 100644 index 0000000..e7a344c --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/Commits.java @@ -0,0 +1,17 @@ +package org.arkecosystem.client.api; + +import java.io.IOException; +import java.util.Map; +import org.arkecosystem.client.http.Client; + +public class Commits { + private final Client client; + + public Commits(Client client) { + this.client = client; + } + + public Map show(int height) throws IOException { + return this.client.get("commits/" + height); + } +} diff --git a/src/test/java/org/arkecosystem/client/api/CommitsTest.java b/src/test/java/org/arkecosystem/client/api/CommitsTest.java new file mode 100644 index 0000000..ceea79d --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/CommitsTest.java @@ -0,0 +1,19 @@ +package org.arkecosystem.client.api; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.util.Map; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +public class CommitsTest { + + @Test + void show() throws IOException { + Connection connection = MockHelper.connection(); + Map actual = connection.api().commits.show(123456); + assertTrue((boolean) actual.get("success")); + } +} From 4c48a38ab60d77885a1f817aeb01ef40460fe1fe Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Tue, 2 Jul 2024 11:29:02 -0600 Subject: [PATCH 05/17] add new rounds methods --- .../arkecosystem/client/api/RoundsTest.java | 25 ++++++++++++++++++- .../org/arkecosystem/client/api/Rounds.java | 15 +++++++++++ .../arkecosystem/client/api/RoundsTest.java | 22 ++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/integration/java/org/arkecosystem/client/api/RoundsTest.java b/src/integration/java/org/arkecosystem/client/api/RoundsTest.java index 29ccd67..622e112 100644 --- a/src/integration/java/org/arkecosystem/client/api/RoundsTest.java +++ b/src/integration/java/org/arkecosystem/client/api/RoundsTest.java @@ -7,13 +7,36 @@ import java.util.Map; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.hasKey; -public class RoundsTest extends BaseClientTest { +public class RoundsIntegrationTest extends BaseClientTest { @Test void delegates() throws IOException { Map actual = connection.api().rounds.delegates(12345); assertThat(actual, hasKey("data")); } + + @Test + void all() throws IOException { + Map actual = connection.api().rounds.all(); + assertThat(actual, hasKey("data")); + assertThat(actual, hasKey("meta")); + } + + @Test + void allWithParams() throws IOException { + Map actual = + connection.api().rounds.param("page", 1).param("limit", 100).all(); + assertThat(actual, hasKey("data")); + assertThat(actual, hasKey("meta")); + } + + @Test + void show() throws IOException { + Map actual = connection.api().rounds.show(12345); + assertThat(actual, hasKey("data")); + assertThat((Map) actual.get("data"), hasEntry("id", 12345.0)); + } } diff --git a/src/main/java/org/arkecosystem/client/api/Rounds.java b/src/main/java/org/arkecosystem/client/api/Rounds.java index 1039e25..1cff635 100644 --- a/src/main/java/org/arkecosystem/client/api/Rounds.java +++ b/src/main/java/org/arkecosystem/client/api/Rounds.java @@ -1,17 +1,32 @@ package org.arkecosystem.client.api; import java.io.IOException; +import java.util.LinkedHashMap; import java.util.Map; import org.arkecosystem.client.http.Client; public class Rounds { private final Client client; + private final Map params = new LinkedHashMap<>(); public Rounds(Client client) { this.client = client; } + public Rounds param(String name, Object value) { + params.put(name, value); + return this; + } + public Map delegates(int id) throws IOException { return this.client.get("rounds/" + id + "/delegates"); } + + public Map all() throws IOException { + return this.client.get("rounds", params); + } + + public Map show(int roundId) throws IOException { + return this.client.get("rounds/" + roundId); + } } diff --git a/src/test/java/org/arkecosystem/client/api/RoundsTest.java b/src/test/java/org/arkecosystem/client/api/RoundsTest.java index b2175d2..f524938 100644 --- a/src/test/java/org/arkecosystem/client/api/RoundsTest.java +++ b/src/test/java/org/arkecosystem/client/api/RoundsTest.java @@ -16,4 +16,26 @@ void delegates() throws IOException { Map actual = connection.api().rounds.delegates(12345); assertTrue((boolean) actual.get("success")); } + + @Test + void all() throws IOException { + Connection connection = MockHelper.connection(); + Map actual = connection.api().rounds.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + void allWithParams() throws IOException { + Connection connection = MockHelper.connection(); + Map actual = + connection.api().rounds.param("page", 1).param("limit", 100).all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + void show() throws IOException { + Connection connection = MockHelper.connection(); + Map actual = connection.api().rounds.show(12345); + assertTrue((boolean) actual.get("success")); + } } From 566f8d63900b90fea6b5f9bfef3ffa0407c63c41 Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Tue, 2 Jul 2024 11:31:34 -0600 Subject: [PATCH 06/17] remove locks method from java --- .../java/org/arkecosystem/client/api/WalletsTest.java | 10 ---------- src/main/java/org/arkecosystem/client/api/Wallets.java | 4 ---- .../java/org/arkecosystem/client/api/WalletsTest.java | 9 +-------- 3 files changed, 1 insertion(+), 22 deletions(-) diff --git a/src/integration/java/org/arkecosystem/client/api/WalletsTest.java b/src/integration/java/org/arkecosystem/client/api/WalletsTest.java index 7e4c12b..1ae3e6b 100644 --- a/src/integration/java/org/arkecosystem/client/api/WalletsTest.java +++ b/src/integration/java/org/arkecosystem/client/api/WalletsTest.java @@ -130,16 +130,6 @@ void votesWithParams() throws IOException { assertThat((Map) actual.get("meta"), hasEntry("count", 3.0)); } - @Test - void locks() throws IOException { - Map actual = connection.api().wallets.locks("D6i8P5N44rFto6M6RALyUXLLs7Q1A1WREW"); - logger.info("actual: {}", actual); - - assertThat(actual, hasKey("meta")); - assertThat(actual, hasKey("data")); - assertThat((Map) actual.get("meta"), hasEntry("count", 0.0)); - } - @Test void top() throws IOException { Map actual = connection.api().wallets.top(); diff --git a/src/main/java/org/arkecosystem/client/api/Wallets.java b/src/main/java/org/arkecosystem/client/api/Wallets.java index f3ecd30..d730731 100644 --- a/src/main/java/org/arkecosystem/client/api/Wallets.java +++ b/src/main/java/org/arkecosystem/client/api/Wallets.java @@ -47,8 +47,4 @@ public Map receivedTransactions(String id) throws IOException { public Map votes(String id) throws IOException { return this.client.get("wallets/" + id + "/votes", params); } - - public Map locks(String id) throws IOException { - return this.client.get("wallets/" + id + "/locks"); - } } diff --git a/src/test/java/org/arkecosystem/client/api/WalletsTest.java b/src/test/java/org/arkecosystem/client/api/WalletsTest.java index d09f275..6545b6e 100644 --- a/src/test/java/org/arkecosystem/client/api/WalletsTest.java +++ b/src/test/java/org/arkecosystem/client/api/WalletsTest.java @@ -90,14 +90,7 @@ void votesWithParams() throws IOException { Map actual = connection.api().wallets.param("page", 1).votes("dummy"); assertTrue((boolean) actual.get("success")); } - - @Test - void locks() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().wallets.locks("dummy"); - assertTrue((boolean) actual.get("success")); - } - + @Test void top() throws IOException { Connection connection = MockHelper.connection(); From c6c480a435806653bf29f0af1a1d6a9eaaa7a83c Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Tue, 2 Jul 2024 11:33:47 -0600 Subject: [PATCH 07/17] add java versions to integration tests --- .github/workflows/integration-test.yml | 28 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index d1ac906..11f4440 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -5,19 +5,25 @@ on: workflow_dispatch jobs: integration: runs-on: ubuntu-latest + strategy: + matrix: + java: [8, 11, 15, 16, 17, 18, 19, 20, 21, 22] steps: - - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v2 - - name: Use Java Version 8 - uses: actions/setup-java@v1 - with: - java-version: 8 + - name: Use Java Version ${{ matrix.java }} + uses: actions/setup-java@v2 + with: + distribution: "zulu" + java-version: ${{ matrix.java }} + cache: "gradle" - - name: Install - run: gradle dependencies + - name: Install + run: gradle dependencies - - name: Test - run: gradle integrationTest - env: - INTEGRATION_TESTS_MNEMONIC: ${{ secrets.MNEMONIC }} + - name: Test + run: gradle integrationTest + env: + INTEGRATION_TESTS_MNEMONIC: ${{ secrets.MNEMONIC }} From 6579a044008cb04b422d074ad984ec79a4da0869 Mon Sep 17 00:00:00 2001 From: alfonsobries Date: Tue, 2 Jul 2024 17:34:22 +0000 Subject: [PATCH 08/17] style: resolve style guide violations --- src/test/java/org/arkecosystem/client/api/WalletsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/arkecosystem/client/api/WalletsTest.java b/src/test/java/org/arkecosystem/client/api/WalletsTest.java index 6545b6e..30d7b98 100644 --- a/src/test/java/org/arkecosystem/client/api/WalletsTest.java +++ b/src/test/java/org/arkecosystem/client/api/WalletsTest.java @@ -90,7 +90,7 @@ void votesWithParams() throws IOException { Map actual = connection.api().wallets.param("page", 1).votes("dummy"); assertTrue((boolean) actual.get("success")); } - + @Test void top() throws IOException { Connection connection = MockHelper.connection(); From cfc65b3e35c7bd8f3d382f9e2ff479c41f907732 Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Thu, 22 Aug 2024 07:35:48 -0600 Subject: [PATCH 09/17] Rename connection to ark client --- .../org/arkecosystem/client/ArkClient.java | 100 ++++++++++++++++++ .../org/arkecosystem/client/Connection.java | 23 ---- 2 files changed, 100 insertions(+), 23 deletions(-) create mode 100644 src/main/java/org/arkecosystem/client/ArkClient.java delete mode 100644 src/main/java/org/arkecosystem/client/Connection.java diff --git a/src/main/java/org/arkecosystem/client/ArkClient.java b/src/main/java/org/arkecosystem/client/ArkClient.java new file mode 100644 index 0000000..95b1c2a --- /dev/null +++ b/src/main/java/org/arkecosystem/client/ArkClient.java @@ -0,0 +1,100 @@ +package org.arkecosystem.client; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import org.arkecosystem.client.api.Api; +import org.arkecosystem.client.http.Client; + +public class ArkClient { + private final Api api; + private final Client client; + private final Map hosts; + + /** + * Constructor to create an instance of ArkClient. + * + * @param hostOrHosts Can be a string representing the host URL or a map with different types of hosts. + */ + public ArkClient(Object hostOrHosts) { + this.hosts = validateHosts(hostOrHosts); + this.client = new Client(this.hosts.get("api")); + this.api = new Api(this.client); + } + + /** + * Method to get the API instance. + * + * @return The API instance. + */ + public Api api() { + return this.api; + } + + /** + * Method to get the HTTP client instance. + * + * @return The HTTP client instance. + */ + public Client client() { + return this.client; + } + + /** + * Method to set a new host for a specific type. + * + * @param host The host URL. + * @param type The type of host (api, transactions, evm). + */ + public void setHost(String host, String type) { + if (!Objects.equals(type, "api") && !Objects.equals(type, "transactions") && !Objects.equals(type, "evm")) { + throw new IllegalArgumentException("Invalid host type."); + } + this.hosts.put(type, host); + } + + /** + * Method to get the current hosts. + * + * @return A map with the current hosts. + */ + public Map getHosts() { + return this.hosts; + } + + /** + * Validate the format of the hosts. + * + * @param hostOrHosts Can be a string or a map. + * @return A validated map of hosts. + */ + private Map validateHosts(Object hostOrHosts) { + Map validatedHosts = new HashMap<>(); + + if (hostOrHosts instanceof String) { + validatedHosts.put("api", (String) hostOrHosts); + } else if (hostOrHosts instanceof Map) { + Map hostsMap = (Map) hostOrHosts; + + if (!hostsMap.containsKey("api")) { + throw new IllegalArgumentException("The hosts map must contain the key 'api'."); + } + + for (Map.Entry entry : hostsMap.entrySet()) { + String key = entry.getKey().toString(); + String value = entry.getValue().toString(); + + if (Objects.equals(key, "api") || Objects.equals(key, "transactions") || Objects.equals(key, "evm")) { + validatedHosts.put(key, value); + } else { + throw new IllegalArgumentException("Invalid host type: " + key); + } + } + } else { + throw new IllegalArgumentException("Invalid host format. Must be a string or a map."); + } + + return validatedHosts; + } +} diff --git a/src/main/java/org/arkecosystem/client/Connection.java b/src/main/java/org/arkecosystem/client/Connection.java deleted file mode 100644 index 425d0de..0000000 --- a/src/main/java/org/arkecosystem/client/Connection.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.arkecosystem.client; - -import java.util.Map; -import org.arkecosystem.client.api.Api; -import org.arkecosystem.client.http.Client; - -public class Connection { - private final Api api; - private final Client client; - - public Connection(Map config) { - this.client = new Client(config.get("host").toString()); - this.api = new Api(this.client); - } - - public Api api() { - return this.api; - } - - public Client client() { - return this.client; - } -} From 0770ccb2ba9e93755680f9b2e401fb035efddf65 Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Thu, 22 Aug 2024 07:41:42 -0600 Subject: [PATCH 10/17] add tests, rename connection manager --- .../arkecosystem/client/ClientManager.java | 114 ++++++++++++++++++ .../client/ConnectionManager.java | 67 ---------- .../arkecosystem/client/ArkClientTest.java | 77 ++++++++++++ .../client/ClientManagerTest.java | 101 ++++++++++++++++ .../client/ConnectionManagerTest.java | 81 ------------- .../arkecosystem/client/ConnectionTest.java | 26 ---- 6 files changed, 292 insertions(+), 174 deletions(-) create mode 100644 src/main/java/org/arkecosystem/client/ClientManager.java delete mode 100644 src/main/java/org/arkecosystem/client/ConnectionManager.java create mode 100644 src/test/java/org/arkecosystem/client/ArkClientTest.java create mode 100644 src/test/java/org/arkecosystem/client/ClientManagerTest.java delete mode 100644 src/test/java/org/arkecosystem/client/ConnectionManagerTest.java delete mode 100644 src/test/java/org/arkecosystem/client/ConnectionTest.java diff --git a/src/main/java/org/arkecosystem/client/ClientManager.java b/src/main/java/org/arkecosystem/client/ClientManager.java new file mode 100644 index 0000000..2e685b2 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/ClientManager.java @@ -0,0 +1,114 @@ +package org.arkecosystem.client; + +import java.util.HashMap; +import java.util.Map; + +public class ClientManager { + private final Map clients; + private String defaultClient = "main"; + + public ClientManager() { + this.clients = new HashMap<>(); + } + + /** + * Get the default client name. + * + * @return The name of the default client. + */ + public String getDefaultClient() { + return this.defaultClient; + } + + /** + * Set the default client name. + * + * @param name The name of the default client to set. + */ + public void setDefaultClient(String name) { + this.defaultClient = name; + } + + /** + * Return all created clients. + * + * @return A map of all created clients. + */ + public Map getClients() { + return this.clients; + } + + /** + * Connect to a given client. + * + * @param host The host URL for the client. + * @param name The name to assign to this client instance. + * @return The newly created ArkClient instance. + */ + public ArkClient connect(String host, String name) { + if (this.clients.containsKey(name)) { + throw new IllegalArgumentException("Client [" + name + "] is already configured."); + } + + this.clients.put(name, new ArkClient(host)); + + return this.clients.get(name); + } + + /** + * Connect to the default client. + * + * @param host The host URL for the client. + * @return The newly created ArkClient instance. + */ + public ArkClient connect(String host) { + return connect(host, "main"); + } + + /** + * Disconnect from a given client. + * + * @param name The name of the client to disconnect. + */ + public void disconnect(String name) { + if (name == null || name.isEmpty()) { + name = getDefaultClient(); + } + + this.clients.remove(name); + } + + /** + * Disconnect from the default client. + */ + public void disconnect() { + disconnect(null); + } + + /** + * Get a client instance by name. + * + * @param name The name of the client to retrieve. + * @return The corresponding ArkClient instance. + */ + public ArkClient client(String name) { + if (name == null || name.isEmpty()) { + name = getDefaultClient(); + } + + if (!this.clients.containsKey(name)) { + throw new IllegalArgumentException("Client [" + name + "] not configured."); + } + + return this.clients.get(name); + } + + /** + * Get the default client instance. + * + * @return The default ArkClient instance. + */ + public ArkClient client() { + return client(null); + } +} diff --git a/src/main/java/org/arkecosystem/client/ConnectionManager.java b/src/main/java/org/arkecosystem/client/ConnectionManager.java deleted file mode 100644 index e10e0a0..0000000 --- a/src/main/java/org/arkecosystem/client/ConnectionManager.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.arkecosystem.client; - -import java.util.HashMap; -import java.util.Map; - -public class ConnectionManager { - private final Map connections; - private String defaultConnection = "main"; - - public ConnectionManager() { - this.connections = new HashMap<>(); - } - - public String getDefaultConnection() { - return this.defaultConnection; - } - - public void setDefaultConnection(String name) { - this.defaultConnection = name; - } - - public Map getConnections() { - return this.connections; - } - - public Connection connect(Map config, String name) { - if (this.connections.containsKey(name)) { - throw new IllegalArgumentException("Connection [" + name + "] is already configured."); - } - - this.connections.put(name, new Connection(config)); - - return this.connections.get(name); - } - - public Connection connect(Map config) { - return connect(config, "main"); - } - - public void disconnect(String name) { - if (name == null || name.isEmpty()) { - name = getDefaultConnection(); - } - - this.connections.remove(name); - } - - public void disconnect() { - disconnect(null); - } - - public Connection connection(String name) { - if (name == null || name.isEmpty()) { - name = getDefaultConnection(); - } - - if (!this.connections.containsKey(name)) { - throw new IllegalArgumentException("Connection [" + name + "] not configured."); - } - - return this.connections.get(name); - } - - public Connection connection() { - return connection(null); - } -} diff --git a/src/test/java/org/arkecosystem/client/ArkClientTest.java b/src/test/java/org/arkecosystem/client/ArkClientTest.java new file mode 100644 index 0000000..17669d1 --- /dev/null +++ b/src/test/java/org/arkecosystem/client/ArkClientTest.java @@ -0,0 +1,77 @@ +package org.arkecosystem.client; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +class ArkClientTest { + + @Test + void apiTest() { + HashMap config = new HashMap<>(); + config.put("host", "dummy"); + + ArkClient client = new ArkClient(config.get("host").toString()); + assertNotNull(client.api()); + } + + @Test + void clientTest() { + HashMap config = new HashMap<>(); + config.put("host", "dummy"); + + ArkClient client = new ArkClient(config.get("host").toString()); + assertNotNull(client.client()); + } + + @Test + void shouldAcceptHostsAsArray() { + Map hosts = new HashMap<>(); + hosts.put("api", "https://dwallets-evm.mainsailhq.com/api"); + hosts.put("transactions", "https://dwallets-evm.mainsailhq.com/tx/api"); + hosts.put("evm", "https://dwallets-evm.mainsailhq.com/evm"); + + ArkClient client = new ArkClient(hosts); + assertEquals(hosts, client.getHosts()); + } + + @Test + void doesNotAcceptHostsArrayWithoutApi() { + Map hosts = new HashMap<>(); + hosts.put("transactions", "https://dwallets-evm.mainsailhq.com/tx/api"); + hosts.put("evm", "https://dwallets-evm.mainsailhq.com/evm"); + + assertThrows(IllegalArgumentException.class, () -> new ArkClient(hosts)); + } + + @Test + void shouldSetHost() { + ArkClient client = new ArkClient("https://old-host.com/api"); + + String newHost = "https://new-host.com/api"; + client.setHost(newHost, "api"); + + assertEquals(newHost, client.getHosts().get("api")); + } + + @Test + void shouldThrowExceptionIfHostTypeIsInvalid() { + ArkClient client = new ArkClient("https://old-host.com/api"); + + assertThrows(IllegalArgumentException.class, () -> client.setHost("https://new-host.com/api", "other")); + } + + @Test + void shouldAcceptCustomHandler() { + HandlerStack handler = HandlerStack.create(); + + ArkClient client = new ArkClient("dummy", handler); + + assertEquals(handler, client.getHttpClient().getConfig("handler")); + } +} diff --git a/src/test/java/org/arkecosystem/client/ClientManagerTest.java b/src/test/java/org/arkecosystem/client/ClientManagerTest.java new file mode 100644 index 0000000..fd90f8e --- /dev/null +++ b/src/test/java/org/arkecosystem/client/ClientManagerTest.java @@ -0,0 +1,101 @@ +package org.arkecosystem.client; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.HashMap; +import org.junit.jupiter.api.Test; + +public class ClientManagerTest { + + @Test + public void connect() { + HashMap map = new HashMap<>(); + map.put("host", "dummy"); + + ClientManager manager = new ClientManager(); + manager.connect(map.get("host").toString(), "dummy-client"); + assertEquals(1, manager.getClients().size()); + assertTrue(manager.getClients().containsKey("dummy-client")); + } + + @Test + public void shouldThrowIfClientAlreadyExists() { + HashMap map = new HashMap<>(); + map.put("host", "dummy"); + + ClientManager manager = new ClientManager(); + manager.connect(map.get("host").toString(), "dummy-client"); + + assertThrows(IllegalArgumentException.class, () -> { + manager.connect(map.get("host").toString(), "dummy-client"); + }); + } + + @Test + public void disconnect() { + HashMap map = new HashMap<>(); + map.put("host", "dummy"); + + ClientManager manager = new ClientManager(); + manager.connect(map.get("host").toString(), "dummy-client"); + assertEquals(1, manager.getClients().size()); + + manager.disconnect("dummy-client"); + assertEquals(0, manager.getClients().size()); + } + + @Test + public void client() { + HashMap map = new HashMap<>(); + map.put("host", "dummy"); + + ClientManager manager = new ClientManager(); + manager.connect(map.get("host").toString(), "dummy-client"); + ArkClient client = manager.client("dummy-client"); + assertNotNull(client); + } + + @Test + public void shouldThrowIfClientDoesNotExist() { + ClientManager manager = new ClientManager(); + + assertThrows(IllegalArgumentException.class, () -> { + manager.client("non-existent-client"); + }); + } + + @Test + public void getDefaultClient() { + ClientManager manager = new ClientManager(); + String actual = manager.getDefaultClient(); + assertEquals("main", actual); + } + + @Test + public void setDefaultClient() { + ClientManager manager = new ClientManager(); + assertEquals("main", manager.getDefaultClient()); + manager.setDefaultClient("dummy-client"); + assertEquals("dummy-client", manager.getDefaultClient()); + } + + @Test + public void getClients() { + ClientManager manager = new ClientManager(); + + manager.connect("https://dummy1.com", "dummy-client-1"); + manager.connect("https://dummy2.com", "dummy-client-2"); + manager.connect("https://dummy3.com", "dummy-client-3"); + + assertEquals(3, manager.getClients().size()); + assertTrue(manager.getClients().containsKey("dummy-client-1")); + assertTrue(manager.getClients().containsKey("dummy-client-2")); + assertTrue(manager.getClients().containsKey("dummy-client-3")); + + manager.disconnect("dummy-client-1"); + manager.disconnect("dummy-client-2"); + manager.disconnect("dummy-client-3"); + + assertEquals(0, manager.getClients().size()); + } +} \ No newline at end of file diff --git a/src/test/java/org/arkecosystem/client/ConnectionManagerTest.java b/src/test/java/org/arkecosystem/client/ConnectionManagerTest.java deleted file mode 100644 index 4ad2f8c..0000000 --- a/src/test/java/org/arkecosystem/client/ConnectionManagerTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.arkecosystem.client; - -import static junit.framework.TestCase.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.HashMap; -import org.arkecosystem.client.api.Api; -import org.junit.jupiter.api.Test; - -public class ConnectionManagerTest { - @Test - public void connect() { - HashMap map = new HashMap<>(); - map.put("host", "dummy"); - - ConnectionManager manager = new ConnectionManager(); - manager.connect(map); - assertEquals(1, manager.getConnections().size()); - } - - @Test - public void disconnect() { - HashMap map = new HashMap<>(); - map.put("host", "dummy"); - - ConnectionManager manager = new ConnectionManager(); - manager.connect(map); - assertEquals(1, manager.getConnections().size()); - manager.disconnect(); - assertEquals(0, manager.getConnections().size()); - } - - @Test - public void connection() { - HashMap map = new HashMap<>(); - map.put("host", "dummy"); - - ConnectionManager manager = new ConnectionManager(); - manager.connect(map); - Connection connection = manager.connection("main"); - assertNotNull(connection); - assertEquals(Api.class, connection.api().getClass()); - } - - @Test - public void getDefaultConnection() { - ConnectionManager manager = new ConnectionManager(); - String actual = manager.getDefaultConnection(); - assertEquals("main", actual); - } - - @Test - public void setDefaultConnection() { - ConnectionManager manager = new ConnectionManager(); - assertEquals("main", manager.getDefaultConnection()); - manager.setDefaultConnection("dummy"); - assertEquals("dummy", manager.getDefaultConnection()); - } - - @Test - public void getConnections() { - ConnectionManager manager = new ConnectionManager(); - - HashMap map = new HashMap<>(); - map.put("host", "dummy"); - - Connection connection1 = manager.connect(map); - assertNotNull(connection1); - - map = new HashMap<>(); - map.put("host", "dummy"); - - Connection connection2 = manager.connect(map, "backup"); - assertNotNull(connection2); - - assertEquals(2, manager.getConnections().size()); - manager.disconnect(); - manager.disconnect("backup"); - assertEquals(0, manager.getConnections().size()); - } -} diff --git a/src/test/java/org/arkecosystem/client/ConnectionTest.java b/src/test/java/org/arkecosystem/client/ConnectionTest.java deleted file mode 100644 index 7cfaf97..0000000 --- a/src/test/java/org/arkecosystem/client/ConnectionTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.arkecosystem.client; - -import static junit.framework.TestCase.assertNotNull; - -import java.util.HashMap; -import org.junit.jupiter.api.Test; - -class ConnectionTest { - @Test - void apiTest() { - HashMap map = new HashMap<>(); - map.put("host", "dummy"); - - Connection connection = new Connection(map); - assertNotNull(connection.api()); - } - - @Test - void clientTest() { - HashMap map = new HashMap<>(); - map.put("host", "dummy"); - - Connection connection = new Connection(map); - assertNotNull(connection.client()); - } -} From fdd41b34805dec98fe84b6948150f804f7fbcc36 Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Thu, 22 Aug 2024 07:51:44 -0600 Subject: [PATCH 11/17] rename tests to use client --- .../org/arkecosystem/client/MockHelper.java | 6 +- .../arkecosystem/client/api/ApiNodesTest.java | 12 ++-- .../client/api/BlockchainTest.java | 8 +-- .../arkecosystem/client/api/BlocksTest.java | 32 +++++------ .../arkecosystem/client/api/CommitsTest.java | 8 +-- .../client/api/DelegatesTest.java | 28 +++++----- .../arkecosystem/client/api/EntitiesTest.java | 1 - .../org/arkecosystem/client/api/NodeTest.java | 28 +++++----- .../arkecosystem/client/api/PeersTest.java | 16 +++--- .../arkecosystem/client/api/RoundsTest.java | 20 +++---- .../client/api/TransactionsTest.java | 44 +++++++-------- .../arkecosystem/client/api/VotesTest.java | 16 +++--- .../arkecosystem/client/api/WalletsTest.java | 56 +++++++++---------- 13 files changed, 137 insertions(+), 138 deletions(-) delete mode 100644 src/test/java/org/arkecosystem/client/api/EntitiesTest.java diff --git a/src/test/java/org/arkecosystem/client/MockHelper.java b/src/test/java/org/arkecosystem/client/MockHelper.java index 5220c6d..8465b53 100644 --- a/src/test/java/org/arkecosystem/client/MockHelper.java +++ b/src/test/java/org/arkecosystem/client/MockHelper.java @@ -5,12 +5,12 @@ import okhttp3.mockwebserver.MockWebServer; public class MockHelper { - public static Connection connection() { + public static ArkClient client() { MockWebServer mockServer = new MockWebServer(); HashMap map = new HashMap<>(); map.put("host", mockServer.url("/").toString()); - Connection connection = new Connection(map); + ArkClient client = new ArkClient(map.get("host").toString()); MockResponse mockedResponse = new MockResponse(); mockedResponse.setResponseCode(200); @@ -18,6 +18,6 @@ public static Connection connection() { mockServer.enqueue(mockedResponse); - return connection; + return client; } } diff --git a/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java b/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java index b0fa9dc..9e35dad 100644 --- a/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java +++ b/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Map; -import org.arkecosystem.client.Connection; +import org.arkecosystem.client.ArkClient; import org.arkecosystem.client.MockHelper; import org.junit.jupiter.api.Test; @@ -12,16 +12,16 @@ public class ApiNodesTest { @Test void all() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().apiNodes.all(); + ArkClient client = MockHelper.client(); + Map actual = client.api().apiNodes.all(); assertTrue((boolean) actual.get("success")); } @Test void allWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().apiNodes.param("page", 1).param("limit", 100).all(); + client.api().apiNodes.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/arkecosystem/client/api/BlockchainTest.java b/src/test/java/org/arkecosystem/client/api/BlockchainTest.java index e9c127c..35e3db2 100644 --- a/src/test/java/org/arkecosystem/client/api/BlockchainTest.java +++ b/src/test/java/org/arkecosystem/client/api/BlockchainTest.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Map; -import org.arkecosystem.client.Connection; +import org.arkecosystem.client.ArkClient; import org.arkecosystem.client.MockHelper; import org.junit.jupiter.api.Test; @@ -12,8 +12,8 @@ public class BlockchainTest { @Test void all() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().blockchain.all(); + ArkClient client = MockHelper.client(); + Map actual = client.api().blockchain.all(); assertTrue((boolean) actual.get("success")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/arkecosystem/client/api/BlocksTest.java b/src/test/java/org/arkecosystem/client/api/BlocksTest.java index fc517e4..564affb 100644 --- a/src/test/java/org/arkecosystem/client/api/BlocksTest.java +++ b/src/test/java/org/arkecosystem/client/api/BlocksTest.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Map; -import org.arkecosystem.client.Connection; +import org.arkecosystem.client.ArkClient; import org.arkecosystem.client.MockHelper; import org.junit.jupiter.api.Test; @@ -12,52 +12,52 @@ public class BlocksTest { @Test void all() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().blocks.all(); + ArkClient client = MockHelper.client(); + Map actual = client.api().blocks.all(); assertTrue((boolean) actual.get("success")); } @Test void allWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().blocks.param("page", 1).param("limit", 100).all(); + client.api().blocks.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @Test void first() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().blocks.first(); + ArkClient client = MockHelper.client(); + Map actual = client.api().blocks.first(); assertTrue((boolean) actual.get("success")); } @Test void last() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().blocks.last(); + ArkClient client = MockHelper.client(); + Map actual = client.api().blocks.last(); assertTrue((boolean) actual.get("success")); } @Test void show() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().blocks.show("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().blocks.show("dummy"); assertTrue((boolean) actual.get("success")); } @Test void transactions() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().blocks.transactions("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().blocks.transactions("dummy"); assertTrue((boolean) actual.get("success")); } @Test void transactionsWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().blocks.param("page", 1).param("limit", 100).transactions("dummy"); + client.api().blocks.param("page", 1).param("limit", 100).transactions("dummy"); assertTrue((boolean) actual.get("success")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/arkecosystem/client/api/CommitsTest.java b/src/test/java/org/arkecosystem/client/api/CommitsTest.java index ceea79d..d605502 100644 --- a/src/test/java/org/arkecosystem/client/api/CommitsTest.java +++ b/src/test/java/org/arkecosystem/client/api/CommitsTest.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Map; -import org.arkecosystem.client.Connection; +import org.arkecosystem.client.ArkClient; import org.arkecosystem.client.MockHelper; import org.junit.jupiter.api.Test; @@ -12,8 +12,8 @@ public class CommitsTest { @Test void show() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().commits.show(123456); + ArkClient client = MockHelper.client(); + Map actual = client.api().commits.show(123456); assertTrue((boolean) actual.get("success")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/arkecosystem/client/api/DelegatesTest.java b/src/test/java/org/arkecosystem/client/api/DelegatesTest.java index ec5850a..0f40bf3 100644 --- a/src/test/java/org/arkecosystem/client/api/DelegatesTest.java +++ b/src/test/java/org/arkecosystem/client/api/DelegatesTest.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Map; -import org.arkecosystem.client.Connection; +import org.arkecosystem.client.ArkClient; import org.arkecosystem.client.MockHelper; import org.junit.jupiter.api.Test; @@ -12,45 +12,45 @@ public class DelegatesTest { @Test void all() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().delegates.all(); + ArkClient client = MockHelper.client(); + Map actual = client.api().delegates.all(); assertTrue((boolean) actual.get("success")); } @Test void allWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().delegates.param("page", 1).param("limit", 100).all(); + client.api().delegates.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @Test void show() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().delegates.show("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().delegates.show("dummy"); assertTrue((boolean) actual.get("success")); } @Test void blocks() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().delegates.blocks("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().delegates.blocks("dummy"); assertTrue((boolean) actual.get("success")); } @Test void voters() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().delegates.voters("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().delegates.voters("dummy"); assertTrue((boolean) actual.get("success")); } @Test void votersWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().delegates.param("page", 1).param("limit", 100).voters("dummy"); + client.api().delegates.param("page", 1).param("limit", 100).voters("dummy"); assertTrue((boolean) actual.get("success")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/arkecosystem/client/api/EntitiesTest.java b/src/test/java/org/arkecosystem/client/api/EntitiesTest.java deleted file mode 100644 index 8b13789..0000000 --- a/src/test/java/org/arkecosystem/client/api/EntitiesTest.java +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/test/java/org/arkecosystem/client/api/NodeTest.java b/src/test/java/org/arkecosystem/client/api/NodeTest.java index df93cbf..61e8c24 100644 --- a/src/test/java/org/arkecosystem/client/api/NodeTest.java +++ b/src/test/java/org/arkecosystem/client/api/NodeTest.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Map; -import org.arkecosystem.client.Connection; +import org.arkecosystem.client.ArkClient; import org.arkecosystem.client.MockHelper; import org.junit.jupiter.api.Test; @@ -12,43 +12,43 @@ public class NodeTest { @Test void feesWithDays() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().node.fees(1); + ArkClient client = MockHelper.client(); + Map actual = client.api().node.fees(1); assertTrue((boolean) actual.get("success")); } @Test void fees() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().node.fees(); + ArkClient client = MockHelper.client(); + Map actual = client.api().node.fees(); assertTrue((boolean) actual.get("success")); } @Test void status() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().node.status(); + ArkClient client = MockHelper.client(); + Map actual = client.api().node.status(); assertTrue((boolean) actual.get("success")); } @Test void syncing() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().node.syncing(); + ArkClient client = MockHelper.client(); + Map actual = client.api().node.syncing(); assertTrue((boolean) actual.get("success")); } @Test void configuration() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().node.configuration(); + ArkClient client = MockHelper.client(); + Map actual = client.api().node.configuration(); assertTrue((boolean) actual.get("success")); } @Test void crypto() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().node.crypto(); + ArkClient client = MockHelper.client(); + Map actual = client.api().node.crypto(); assertTrue((boolean) actual.get("success")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/arkecosystem/client/api/PeersTest.java b/src/test/java/org/arkecosystem/client/api/PeersTest.java index ef727ee..0958192 100644 --- a/src/test/java/org/arkecosystem/client/api/PeersTest.java +++ b/src/test/java/org/arkecosystem/client/api/PeersTest.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Map; -import org.arkecosystem.client.Connection; +import org.arkecosystem.client.ArkClient; import org.arkecosystem.client.MockHelper; import org.junit.jupiter.api.Test; @@ -12,23 +12,23 @@ public class PeersTest { @Test void all() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().peers.all(); + ArkClient client = MockHelper.client(); + Map actual = client.api().peers.all(); assertTrue((boolean) actual.get("success")); } @Test void allWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().peers.param("page", 1).param("limit", 100).all(); + client.api().peers.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @Test void show() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().peers.show("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().peers.show("dummy"); assertTrue((boolean) actual.get("success")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/arkecosystem/client/api/RoundsTest.java b/src/test/java/org/arkecosystem/client/api/RoundsTest.java index f524938..b4c1b24 100644 --- a/src/test/java/org/arkecosystem/client/api/RoundsTest.java +++ b/src/test/java/org/arkecosystem/client/api/RoundsTest.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Map; -import org.arkecosystem.client.Connection; +import org.arkecosystem.client.ArkClient; import org.arkecosystem.client.MockHelper; import org.junit.jupiter.api.Test; @@ -12,30 +12,30 @@ public class RoundsTest { @Test void delegates() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().rounds.delegates(12345); + ArkClient client = MockHelper.client(); + Map actual = client.api().rounds.delegates(12345); assertTrue((boolean) actual.get("success")); } @Test void all() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().rounds.all(); + ArkClient client = MockHelper.client(); + Map actual = client.api().rounds.all(); assertTrue((boolean) actual.get("success")); } @Test void allWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().rounds.param("page", 1).param("limit", 100).all(); + client.api().rounds.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @Test void show() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().rounds.show(12345); + ArkClient client = MockHelper.client(); + Map actual = client.api().rounds.show(12345); assertTrue((boolean) actual.get("success")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/arkecosystem/client/api/TransactionsTest.java b/src/test/java/org/arkecosystem/client/api/TransactionsTest.java index 79970aa..ea6e2e5 100644 --- a/src/test/java/org/arkecosystem/client/api/TransactionsTest.java +++ b/src/test/java/org/arkecosystem/client/api/TransactionsTest.java @@ -5,7 +5,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Map; -import org.arkecosystem.client.Connection; +import org.arkecosystem.client.ArkClient; import org.arkecosystem.client.MockHelper; import org.junit.jupiter.api.Test; @@ -13,73 +13,73 @@ public class TransactionsTest { @Test void all() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().transactions.all(); + ArkClient client = MockHelper.client(); + Map actual = client.api().transactions.all(); assertTrue((boolean) actual.get("success")); } @Test void allWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().transactions.param("page", 1).param("limit", 100).all(); + client.api().transactions.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @Test void create() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().transactions.create(new ArrayList<>()); + ArkClient client = MockHelper.client(); + Map actual = client.api().transactions.create(new ArrayList<>()); assertTrue((boolean) actual.get("success")); } @Test void show() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().transactions.show("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().transactions.show("dummy"); assertTrue((boolean) actual.get("success")); } @Test void allUnconfirmed() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().transactions.allUnconfirmed(); + ArkClient client = MockHelper.client(); + Map actual = client.api().transactions.allUnconfirmed(); assertTrue((boolean) actual.get("success")); } @Test void allUnconfirmedWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().transactions.param("page", 1).allUnconfirmed(); + client.api().transactions.param("page", 1).allUnconfirmed(); assertTrue((boolean) actual.get("success")); } @Test void showUnconfirmed() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().transactions.showUnconfirmed("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().transactions.showUnconfirmed("dummy"); assertTrue((boolean) actual.get("success")); } @Test void types() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().transactions.types(); + ArkClient client = MockHelper.client(); + Map actual = client.api().transactions.types(); assertTrue((boolean) actual.get("success")); } @Test void fees() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().transactions.fees(); + ArkClient client = MockHelper.client(); + Map actual = client.api().transactions.fees(); assertTrue((boolean) actual.get("success")); } @Test void schemas() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().transactions.schemas(); + ArkClient client = MockHelper.client(); + Map actual = client.api().transactions.schemas(); assertTrue((boolean) actual.get("success")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/arkecosystem/client/api/VotesTest.java b/src/test/java/org/arkecosystem/client/api/VotesTest.java index 9ef32f0..c82fe11 100644 --- a/src/test/java/org/arkecosystem/client/api/VotesTest.java +++ b/src/test/java/org/arkecosystem/client/api/VotesTest.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Map; -import org.arkecosystem.client.Connection; +import org.arkecosystem.client.ArkClient; import org.arkecosystem.client.MockHelper; import org.junit.jupiter.api.Test; @@ -12,23 +12,23 @@ public class VotesTest { @Test void all() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().votes.all(); + ArkClient client = MockHelper.client(); + Map actual = client.api().votes.all(); assertTrue((boolean) actual.get("success")); } @Test void allWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().votes.param("page", 1).param("limit", 100).all(); + client.api().votes.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @Test void show() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().votes.show("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().votes.show("dummy"); assertTrue((boolean) actual.get("success")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/arkecosystem/client/api/WalletsTest.java b/src/test/java/org/arkecosystem/client/api/WalletsTest.java index 30d7b98..0201364 100644 --- a/src/test/java/org/arkecosystem/client/api/WalletsTest.java +++ b/src/test/java/org/arkecosystem/client/api/WalletsTest.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.Map; -import org.arkecosystem.client.Connection; +import org.arkecosystem.client.ArkClient; import org.arkecosystem.client.MockHelper; import org.junit.jupiter.api.Test; @@ -12,96 +12,96 @@ public class WalletsTest { @Test void all() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().wallets.all(); + ArkClient client = MockHelper.client(); + Map actual = client.api().wallets.all(); assertTrue((boolean) actual.get("success")); } @Test void allWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().wallets.param("page", 1).param("limit", 100).all(); + client.api().wallets.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @Test void show() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().wallets.show("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().wallets.show("dummy"); assertTrue((boolean) actual.get("success")); } @Test void transactions() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().wallets.transactions("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().wallets.transactions("dummy"); assertTrue((boolean) actual.get("success")); } @Test void transactionsWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().wallets.param("page", 1).transactions("dummy"); + client.api().wallets.param("page", 1).transactions("dummy"); assertTrue((boolean) actual.get("success")); } @Test void sentTransactions() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().wallets.sentTransactions("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().wallets.sentTransactions("dummy"); assertTrue((boolean) actual.get("success")); } @Test void sentTransactionsWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().wallets.param("page", 1).sentTransactions("dummy"); + client.api().wallets.param("page", 1).sentTransactions("dummy"); assertTrue((boolean) actual.get("success")); } @Test void receivedTransactions() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().wallets.receivedTransactions("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().wallets.receivedTransactions("dummy"); assertTrue((boolean) actual.get("success")); } @Test void receivedTransactionsWithParams() throws IOException { - Connection connection = MockHelper.connection(); + ArkClient client = MockHelper.client(); Map actual = - connection.api().wallets.param("page", 1).receivedTransactions("dummy"); + client.api().wallets.param("page", 1).receivedTransactions("dummy"); assertTrue((boolean) actual.get("success")); } @Test void votes() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().wallets.votes("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().wallets.votes("dummy"); assertTrue((boolean) actual.get("success")); } @Test void votesWithParams() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().wallets.param("page", 1).votes("dummy"); + ArkClient client = MockHelper.client(); + Map actual = client.api().wallets.param("page", 1).votes("dummy"); assertTrue((boolean) actual.get("success")); } @Test void top() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().wallets.top(); + ArkClient client = MockHelper.client(); + Map actual = client.api().wallets.top(); assertTrue((boolean) actual.get("success")); } @Test void topWithParams() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().wallets.param("page", 1).top(); + ArkClient client = MockHelper.client(); + Map actual = client.api().wallets.param("page", 1).top(); assertTrue((boolean) actual.get("success")); } -} +} \ No newline at end of file From a469d616e1c26060d9b585b4397c9e5fba0e616b Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Thu, 22 Aug 2024 08:02:54 -0600 Subject: [PATCH 12/17] wip --- .../org/arkecosystem/client/ArkClient.java | 49 +------------- .../arkecosystem/client/api/Transactions.java | 2 +- .../org/arkecosystem/client/http/Client.java | 65 +++++++++++++++++-- 3 files changed, 64 insertions(+), 52 deletions(-) diff --git a/src/main/java/org/arkecosystem/client/ArkClient.java b/src/main/java/org/arkecosystem/client/ArkClient.java index 95b1c2a..3dc3c67 100644 --- a/src/main/java/org/arkecosystem/client/ArkClient.java +++ b/src/main/java/org/arkecosystem/client/ArkClient.java @@ -1,16 +1,12 @@ package org.arkecosystem.client; -import java.util.HashMap; import java.util.Map; -import java.util.Objects; -import java.util.Optional; import org.arkecosystem.client.api.Api; import org.arkecosystem.client.http.Client; public class ArkClient { private final Api api; private final Client client; - private final Map hosts; /** * Constructor to create an instance of ArkClient. @@ -18,8 +14,7 @@ public class ArkClient { * @param hostOrHosts Can be a string representing the host URL or a map with different types of hosts. */ public ArkClient(Object hostOrHosts) { - this.hosts = validateHosts(hostOrHosts); - this.client = new Client(this.hosts.get("api")); + this.client = new Client(hostOrHosts); this.api = new Api(this.client); } @@ -48,10 +43,7 @@ public Client client() { * @param type The type of host (api, transactions, evm). */ public void setHost(String host, String type) { - if (!Objects.equals(type, "api") && !Objects.equals(type, "transactions") && !Objects.equals(type, "evm")) { - throw new IllegalArgumentException("Invalid host type."); - } - this.hosts.put(type, host); + this.client.setHost(host, type); } /** @@ -60,41 +52,6 @@ public void setHost(String host, String type) { * @return A map with the current hosts. */ public Map getHosts() { - return this.hosts; - } - - /** - * Validate the format of the hosts. - * - * @param hostOrHosts Can be a string or a map. - * @return A validated map of hosts. - */ - private Map validateHosts(Object hostOrHosts) { - Map validatedHosts = new HashMap<>(); - - if (hostOrHosts instanceof String) { - validatedHosts.put("api", (String) hostOrHosts); - } else if (hostOrHosts instanceof Map) { - Map hostsMap = (Map) hostOrHosts; - - if (!hostsMap.containsKey("api")) { - throw new IllegalArgumentException("The hosts map must contain the key 'api'."); - } - - for (Map.Entry entry : hostsMap.entrySet()) { - String key = entry.getKey().toString(); - String value = entry.getValue().toString(); - - if (Objects.equals(key, "api") || Objects.equals(key, "transactions") || Objects.equals(key, "evm")) { - validatedHosts.put(key, value); - } else { - throw new IllegalArgumentException("Invalid host type: " + key); - } - } - } else { - throw new IllegalArgumentException("Invalid host format. Must be a string or a map."); - } - - return validatedHosts; + return this.client.getHosts(); } } diff --git a/src/main/java/org/arkecosystem/client/api/Transactions.java b/src/main/java/org/arkecosystem/client/api/Transactions.java index 5026507..6502475 100644 --- a/src/main/java/org/arkecosystem/client/api/Transactions.java +++ b/src/main/java/org/arkecosystem/client/api/Transactions.java @@ -29,7 +29,7 @@ public Map all() throws IOException { public Map create(List> transactions) throws IOException { Map params = new HashMap<>(); params.put("transactions", transactions); - return this.client.post("transactions", params); + return this.client.withApi('transactions').post("transactions", params); } public Map show(String id) throws IOException { diff --git a/src/main/java/org/arkecosystem/client/http/Client.java b/src/main/java/org/arkecosystem/client/http/Client.java index 951b2c9..044b999 100644 --- a/src/main/java/org/arkecosystem/client/http/Client.java +++ b/src/main/java/org/arkecosystem/client/http/Client.java @@ -9,12 +9,13 @@ public class Client { private static final MediaType JSON = MediaType.parse("application/json"); - private final String host; + private final Map hosts; + private String api = "api"; private OkHttpClient client; private final Headers headers; - public Client(String host) { - this.host = host; + public Client(Object hostOrHosts) { + this.hosts = validateHosts(hostOrHosts); this.client = new OkHttpClient(); HashMap headers = new HashMap<>(); @@ -24,7 +25,7 @@ public Client(String host) { } public Map get(String url, Map params) throws IOException { - HttpUrl.Builder httpBuilder = HttpUrl.parse(this.host + url).newBuilder(); + HttpUrl.Builder httpBuilder = HttpUrl.parse(buildUrl(url)).newBuilder(); for (Map.Entry entry : DotHelper.toDot(params).entrySet()) { if (entry.getValue() != null) { @@ -45,7 +46,7 @@ public Map get(String url) throws IOException { public Map post(String url, Map payload) throws IOException { RequestBody body = RequestBody.create(JSON, new Gson().toJson(payload)); - Request request = new Request.Builder().url(this.host + url).post(body).build(); + Request request = new Request.Builder().url(buildUrl(url)).post(body).build(); Response response = client.newCall(request).execute(); return new Gson().fromJson(response.body().string(), Map.class); } @@ -57,4 +58,58 @@ public OkHttpClient getClient() { public void setClient(OkHttpClient client) { this.client = client; } + + public Client withApi(String api) { + this.api = api; + return this; + } + + public void setHost(String host, String type) { + if (!type.equals("api") && !type.equals("transactions") && !type.equals("evm")) { + throw new IllegalArgumentException("Invalid host type."); + } + this.hosts.put(type, host); + } + + public Map getHosts() { + return this.hosts; + } + + private String buildUrl(String path) { + String baseUri = this.hosts.get(api); + + // Reset the API to the default value. + this.api = "api"; + + return baseUri.endsWith("/") ? baseUri + path : baseUri + "/" + path; + } + + private Map validateHosts(Object hostOrHosts) { + Map validatedHosts = new HashMap<>(); + + if (hostOrHosts instanceof String) { + validatedHosts.put("api", (String) hostOrHosts); + } else if (hostOrHosts instanceof Map) { + Map hostsMap = (Map) hostOrHosts; + + if (!hostsMap.containsKey("api")) { + throw new IllegalArgumentException("The hosts map must contain the key 'api'."); + } + + for (Map.Entry entry : hostsMap.entrySet()) { + String key = entry.getKey().toString(); + String value = entry.getValue().toString(); + + if (key.equals("api") || key.equals("transactions") || key.equals("evm")) { + validatedHosts.put(key, value); + } else { + throw new IllegalArgumentException("Invalid host type: " + key); + } + } + } else { + throw new IllegalArgumentException("Invalid host format. Must be a string or a map."); + } + + return validatedHosts; + } } From 65d2e8d38dfebb53cfd6ca982dfedf02b100b5ce Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Thu, 22 Aug 2024 08:17:41 -0600 Subject: [PATCH 13/17] adjust tests --- .../org/arkecosystem/client/api/Transactions.java | 2 +- .../java/org/arkecosystem/client/ArkClientTest.java | 9 --------- .../java/org/arkecosystem/client/MockHelper.java | 12 ++++++++---- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/arkecosystem/client/api/Transactions.java b/src/main/java/org/arkecosystem/client/api/Transactions.java index 6502475..bef1386 100644 --- a/src/main/java/org/arkecosystem/client/api/Transactions.java +++ b/src/main/java/org/arkecosystem/client/api/Transactions.java @@ -29,7 +29,7 @@ public Map all() throws IOException { public Map create(List> transactions) throws IOException { Map params = new HashMap<>(); params.put("transactions", transactions); - return this.client.withApi('transactions').post("transactions", params); + return this.client.withApi("transactions").post("transactions", params); } public Map show(String id) throws IOException { diff --git a/src/test/java/org/arkecosystem/client/ArkClientTest.java b/src/test/java/org/arkecosystem/client/ArkClientTest.java index 17669d1..a007e9d 100644 --- a/src/test/java/org/arkecosystem/client/ArkClientTest.java +++ b/src/test/java/org/arkecosystem/client/ArkClientTest.java @@ -65,13 +65,4 @@ void shouldThrowExceptionIfHostTypeIsInvalid() { assertThrows(IllegalArgumentException.class, () -> client.setHost("https://new-host.com/api", "other")); } - - @Test - void shouldAcceptCustomHandler() { - HandlerStack handler = HandlerStack.create(); - - ArkClient client = new ArkClient("dummy", handler); - - assertEquals(handler, client.getHttpClient().getConfig("handler")); - } } diff --git a/src/test/java/org/arkecosystem/client/MockHelper.java b/src/test/java/org/arkecosystem/client/MockHelper.java index 8465b53..6f44f69 100644 --- a/src/test/java/org/arkecosystem/client/MockHelper.java +++ b/src/test/java/org/arkecosystem/client/MockHelper.java @@ -1,6 +1,7 @@ package org.arkecosystem.client; import java.util.HashMap; +import java.util.Map; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; @@ -8,9 +9,12 @@ public class MockHelper { public static ArkClient client() { MockWebServer mockServer = new MockWebServer(); - HashMap map = new HashMap<>(); - map.put("host", mockServer.url("/").toString()); - ArkClient client = new ArkClient(map.get("host").toString()); + Map hosts = new HashMap<>(); + hosts.put("api", mockServer.url("/api").toString()); + hosts.put("transactions", mockServer.url("/transactions").toString()); + hosts.put("evm", mockServer.url("/evm").toString()); + + ArkClient client = new ArkClient(hosts); MockResponse mockedResponse = new MockResponse(); mockedResponse.setResponseCode(200); @@ -20,4 +24,4 @@ public static ArkClient client() { return client; } -} +} \ No newline at end of file From 89375fd83a5f5a3b220a2004944aa2a0863187f2 Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Thu, 22 Aug 2024 08:19:24 -0600 Subject: [PATCH 14/17] wip --- src/main/java/org/arkecosystem/client/api/Api.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/arkecosystem/client/api/Api.java b/src/main/java/org/arkecosystem/client/api/Api.java index 63f48fa..be1d02d 100644 --- a/src/main/java/org/arkecosystem/client/api/Api.java +++ b/src/main/java/org/arkecosystem/client/api/Api.java @@ -3,8 +3,10 @@ import org.arkecosystem.client.http.Client; public class Api { + public final ApiNodes apiNodes; public final Blockchain blockchain; public final Blocks blocks; + public final Commits commits; public final Delegates delegates; public final Entities entities; public final Node node; @@ -13,12 +15,12 @@ public class Api { public final Transactions transactions; public final Votes votes; public final Wallets wallets; - public final ApiNodes apiNodes; - public final Commits commits; public Api(Client client) { + this.apiNodes = new ApiNodes(client); this.blockchain = new Blockchain(client); this.blocks = new Blocks(client); + this.commits = new Commits(client); this.delegates = new Delegates(client); this.entities = new Entities(client); this.node = new Node(client); @@ -27,7 +29,5 @@ public Api(Client client) { this.transactions = new Transactions(client); this.votes = new Votes(client); this.wallets = new Wallets(client); - this.apiNodes = new ApiNodes(client); - this.commits = new Commits(client); } } From a192116736fbb76c44b1b3d813096142b96cfc1d Mon Sep 17 00:00:00 2001 From: alfonsobries Date: Thu, 22 Aug 2024 14:20:04 +0000 Subject: [PATCH 15/17] style: resolve style guide violations --- .../org/arkecosystem/client/ArkClient.java | 3 ++- .../org/arkecosystem/client/ClientManager.java | 4 +--- .../org/arkecosystem/client/ArkClientTest.java | 7 ++++--- .../arkecosystem/client/ClientManagerTest.java | 18 +++++++++++------- .../org/arkecosystem/client/MockHelper.java | 2 +- .../arkecosystem/client/api/ApiNodesTest.java | 2 +- .../client/api/BlockchainTest.java | 2 +- .../arkecosystem/client/api/BlocksTest.java | 5 ++--- .../arkecosystem/client/api/CommitsTest.java | 2 +- .../arkecosystem/client/api/DelegatesTest.java | 2 +- .../org/arkecosystem/client/api/NodeTest.java | 2 +- .../org/arkecosystem/client/api/PeersTest.java | 5 ++--- .../arkecosystem/client/api/RoundsTest.java | 5 ++--- .../client/api/TransactionsTest.java | 5 ++--- .../org/arkecosystem/client/api/VotesTest.java | 5 ++--- .../arkecosystem/client/api/WalletsTest.java | 5 ++--- 16 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/arkecosystem/client/ArkClient.java b/src/main/java/org/arkecosystem/client/ArkClient.java index 3dc3c67..15669fb 100644 --- a/src/main/java/org/arkecosystem/client/ArkClient.java +++ b/src/main/java/org/arkecosystem/client/ArkClient.java @@ -11,7 +11,8 @@ public class ArkClient { /** * Constructor to create an instance of ArkClient. * - * @param hostOrHosts Can be a string representing the host URL or a map with different types of hosts. + * @param hostOrHosts Can be a string representing the host URL or a map with different types of + * hosts. */ public ArkClient(Object hostOrHosts) { this.client = new Client(hostOrHosts); diff --git a/src/main/java/org/arkecosystem/client/ClientManager.java b/src/main/java/org/arkecosystem/client/ClientManager.java index 2e685b2..0202ca7 100644 --- a/src/main/java/org/arkecosystem/client/ClientManager.java +++ b/src/main/java/org/arkecosystem/client/ClientManager.java @@ -78,9 +78,7 @@ public void disconnect(String name) { this.clients.remove(name); } - /** - * Disconnect from the default client. - */ + /** Disconnect from the default client. */ public void disconnect() { disconnect(null); } diff --git a/src/test/java/org/arkecosystem/client/ArkClientTest.java b/src/test/java/org/arkecosystem/client/ArkClientTest.java index a007e9d..8b6852d 100644 --- a/src/test/java/org/arkecosystem/client/ArkClientTest.java +++ b/src/test/java/org/arkecosystem/client/ArkClientTest.java @@ -1,12 +1,11 @@ package org.arkecosystem.client; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.HashMap; import java.util.Map; - import org.junit.jupiter.api.Test; class ArkClientTest { @@ -63,6 +62,8 @@ void shouldSetHost() { void shouldThrowExceptionIfHostTypeIsInvalid() { ArkClient client = new ArkClient("https://old-host.com/api"); - assertThrows(IllegalArgumentException.class, () -> client.setHost("https://new-host.com/api", "other")); + assertThrows( + IllegalArgumentException.class, + () -> client.setHost("https://new-host.com/api", "other")); } } diff --git a/src/test/java/org/arkecosystem/client/ClientManagerTest.java b/src/test/java/org/arkecosystem/client/ClientManagerTest.java index fd90f8e..f176108 100644 --- a/src/test/java/org/arkecosystem/client/ClientManagerTest.java +++ b/src/test/java/org/arkecosystem/client/ClientManagerTest.java @@ -26,9 +26,11 @@ public void shouldThrowIfClientAlreadyExists() { ClientManager manager = new ClientManager(); manager.connect(map.get("host").toString(), "dummy-client"); - assertThrows(IllegalArgumentException.class, () -> { - manager.connect(map.get("host").toString(), "dummy-client"); - }); + assertThrows( + IllegalArgumentException.class, + () -> { + manager.connect(map.get("host").toString(), "dummy-client"); + }); } @Test @@ -59,9 +61,11 @@ public void client() { public void shouldThrowIfClientDoesNotExist() { ClientManager manager = new ClientManager(); - assertThrows(IllegalArgumentException.class, () -> { - manager.client("non-existent-client"); - }); + assertThrows( + IllegalArgumentException.class, + () -> { + manager.client("non-existent-client"); + }); } @Test @@ -98,4 +102,4 @@ public void getClients() { assertEquals(0, manager.getClients().size()); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/MockHelper.java b/src/test/java/org/arkecosystem/client/MockHelper.java index 6f44f69..c7a9aac 100644 --- a/src/test/java/org/arkecosystem/client/MockHelper.java +++ b/src/test/java/org/arkecosystem/client/MockHelper.java @@ -24,4 +24,4 @@ public static ArkClient client() { return client; } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java b/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java index 9e35dad..1967767 100644 --- a/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java +++ b/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java @@ -24,4 +24,4 @@ void allWithParams() throws IOException { client.api().apiNodes.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/BlockchainTest.java b/src/test/java/org/arkecosystem/client/api/BlockchainTest.java index 35e3db2..42bbd79 100644 --- a/src/test/java/org/arkecosystem/client/api/BlockchainTest.java +++ b/src/test/java/org/arkecosystem/client/api/BlockchainTest.java @@ -16,4 +16,4 @@ void all() throws IOException { Map actual = client.api().blockchain.all(); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/BlocksTest.java b/src/test/java/org/arkecosystem/client/api/BlocksTest.java index 564affb..584b983 100644 --- a/src/test/java/org/arkecosystem/client/api/BlocksTest.java +++ b/src/test/java/org/arkecosystem/client/api/BlocksTest.java @@ -20,8 +20,7 @@ void all() throws IOException { @Test void allWithParams() throws IOException { ArkClient client = MockHelper.client(); - Map actual = - client.api().blocks.param("page", 1).param("limit", 100).all(); + Map actual = client.api().blocks.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @@ -60,4 +59,4 @@ void transactionsWithParams() throws IOException { client.api().blocks.param("page", 1).param("limit", 100).transactions("dummy"); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/CommitsTest.java b/src/test/java/org/arkecosystem/client/api/CommitsTest.java index d605502..1da3631 100644 --- a/src/test/java/org/arkecosystem/client/api/CommitsTest.java +++ b/src/test/java/org/arkecosystem/client/api/CommitsTest.java @@ -16,4 +16,4 @@ void show() throws IOException { Map actual = client.api().commits.show(123456); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/DelegatesTest.java b/src/test/java/org/arkecosystem/client/api/DelegatesTest.java index 0f40bf3..ffe8a5a 100644 --- a/src/test/java/org/arkecosystem/client/api/DelegatesTest.java +++ b/src/test/java/org/arkecosystem/client/api/DelegatesTest.java @@ -53,4 +53,4 @@ void votersWithParams() throws IOException { client.api().delegates.param("page", 1).param("limit", 100).voters("dummy"); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/NodeTest.java b/src/test/java/org/arkecosystem/client/api/NodeTest.java index 61e8c24..2d288d0 100644 --- a/src/test/java/org/arkecosystem/client/api/NodeTest.java +++ b/src/test/java/org/arkecosystem/client/api/NodeTest.java @@ -51,4 +51,4 @@ void crypto() throws IOException { Map actual = client.api().node.crypto(); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/PeersTest.java b/src/test/java/org/arkecosystem/client/api/PeersTest.java index 0958192..64f8575 100644 --- a/src/test/java/org/arkecosystem/client/api/PeersTest.java +++ b/src/test/java/org/arkecosystem/client/api/PeersTest.java @@ -20,8 +20,7 @@ void all() throws IOException { @Test void allWithParams() throws IOException { ArkClient client = MockHelper.client(); - Map actual = - client.api().peers.param("page", 1).param("limit", 100).all(); + Map actual = client.api().peers.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @@ -31,4 +30,4 @@ void show() throws IOException { Map actual = client.api().peers.show("dummy"); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/RoundsTest.java b/src/test/java/org/arkecosystem/client/api/RoundsTest.java index b4c1b24..e4ce579 100644 --- a/src/test/java/org/arkecosystem/client/api/RoundsTest.java +++ b/src/test/java/org/arkecosystem/client/api/RoundsTest.java @@ -27,8 +27,7 @@ void all() throws IOException { @Test void allWithParams() throws IOException { ArkClient client = MockHelper.client(); - Map actual = - client.api().rounds.param("page", 1).param("limit", 100).all(); + Map actual = client.api().rounds.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @@ -38,4 +37,4 @@ void show() throws IOException { Map actual = client.api().rounds.show(12345); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/TransactionsTest.java b/src/test/java/org/arkecosystem/client/api/TransactionsTest.java index ea6e2e5..caa385a 100644 --- a/src/test/java/org/arkecosystem/client/api/TransactionsTest.java +++ b/src/test/java/org/arkecosystem/client/api/TransactionsTest.java @@ -50,8 +50,7 @@ void allUnconfirmed() throws IOException { @Test void allUnconfirmedWithParams() throws IOException { ArkClient client = MockHelper.client(); - Map actual = - client.api().transactions.param("page", 1).allUnconfirmed(); + Map actual = client.api().transactions.param("page", 1).allUnconfirmed(); assertTrue((boolean) actual.get("success")); } @@ -82,4 +81,4 @@ void schemas() throws IOException { Map actual = client.api().transactions.schemas(); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/VotesTest.java b/src/test/java/org/arkecosystem/client/api/VotesTest.java index c82fe11..c97aef7 100644 --- a/src/test/java/org/arkecosystem/client/api/VotesTest.java +++ b/src/test/java/org/arkecosystem/client/api/VotesTest.java @@ -20,8 +20,7 @@ void all() throws IOException { @Test void allWithParams() throws IOException { ArkClient client = MockHelper.client(); - Map actual = - client.api().votes.param("page", 1).param("limit", 100).all(); + Map actual = client.api().votes.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @@ -31,4 +30,4 @@ void show() throws IOException { Map actual = client.api().votes.show("dummy"); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/WalletsTest.java b/src/test/java/org/arkecosystem/client/api/WalletsTest.java index 0201364..e5864e8 100644 --- a/src/test/java/org/arkecosystem/client/api/WalletsTest.java +++ b/src/test/java/org/arkecosystem/client/api/WalletsTest.java @@ -42,8 +42,7 @@ void transactions() throws IOException { @Test void transactionsWithParams() throws IOException { ArkClient client = MockHelper.client(); - Map actual = - client.api().wallets.param("page", 1).transactions("dummy"); + Map actual = client.api().wallets.param("page", 1).transactions("dummy"); assertTrue((boolean) actual.get("success")); } @@ -104,4 +103,4 @@ void topWithParams() throws IOException { Map actual = client.api().wallets.param("page", 1).top(); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} From 4914d31c360ac08a8f4a89e6576a3ca753ebcaf1 Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Thu, 22 Aug 2024 08:20:51 -0600 Subject: [PATCH 16/17] formatting --- .../org/arkecosystem/client/ArkClient.java | 3 ++- .../org/arkecosystem/client/ClientManager.java | 4 +--- .../org/arkecosystem/client/ArkClientTest.java | 7 ++++--- .../arkecosystem/client/ClientManagerTest.java | 18 +++++++++++------- .../org/arkecosystem/client/MockHelper.java | 2 +- .../arkecosystem/client/api/ApiNodesTest.java | 2 +- .../client/api/BlockchainTest.java | 2 +- .../arkecosystem/client/api/BlocksTest.java | 5 ++--- .../arkecosystem/client/api/CommitsTest.java | 2 +- .../arkecosystem/client/api/DelegatesTest.java | 2 +- .../org/arkecosystem/client/api/NodeTest.java | 2 +- .../org/arkecosystem/client/api/PeersTest.java | 5 ++--- .../arkecosystem/client/api/RoundsTest.java | 5 ++--- .../client/api/TransactionsTest.java | 5 ++--- .../org/arkecosystem/client/api/VotesTest.java | 5 ++--- .../arkecosystem/client/api/WalletsTest.java | 5 ++--- 16 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/arkecosystem/client/ArkClient.java b/src/main/java/org/arkecosystem/client/ArkClient.java index 3dc3c67..15669fb 100644 --- a/src/main/java/org/arkecosystem/client/ArkClient.java +++ b/src/main/java/org/arkecosystem/client/ArkClient.java @@ -11,7 +11,8 @@ public class ArkClient { /** * Constructor to create an instance of ArkClient. * - * @param hostOrHosts Can be a string representing the host URL or a map with different types of hosts. + * @param hostOrHosts Can be a string representing the host URL or a map with different types of + * hosts. */ public ArkClient(Object hostOrHosts) { this.client = new Client(hostOrHosts); diff --git a/src/main/java/org/arkecosystem/client/ClientManager.java b/src/main/java/org/arkecosystem/client/ClientManager.java index 2e685b2..0202ca7 100644 --- a/src/main/java/org/arkecosystem/client/ClientManager.java +++ b/src/main/java/org/arkecosystem/client/ClientManager.java @@ -78,9 +78,7 @@ public void disconnect(String name) { this.clients.remove(name); } - /** - * Disconnect from the default client. - */ + /** Disconnect from the default client. */ public void disconnect() { disconnect(null); } diff --git a/src/test/java/org/arkecosystem/client/ArkClientTest.java b/src/test/java/org/arkecosystem/client/ArkClientTest.java index a007e9d..8b6852d 100644 --- a/src/test/java/org/arkecosystem/client/ArkClientTest.java +++ b/src/test/java/org/arkecosystem/client/ArkClientTest.java @@ -1,12 +1,11 @@ package org.arkecosystem.client; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.HashMap; import java.util.Map; - import org.junit.jupiter.api.Test; class ArkClientTest { @@ -63,6 +62,8 @@ void shouldSetHost() { void shouldThrowExceptionIfHostTypeIsInvalid() { ArkClient client = new ArkClient("https://old-host.com/api"); - assertThrows(IllegalArgumentException.class, () -> client.setHost("https://new-host.com/api", "other")); + assertThrows( + IllegalArgumentException.class, + () -> client.setHost("https://new-host.com/api", "other")); } } diff --git a/src/test/java/org/arkecosystem/client/ClientManagerTest.java b/src/test/java/org/arkecosystem/client/ClientManagerTest.java index fd90f8e..f176108 100644 --- a/src/test/java/org/arkecosystem/client/ClientManagerTest.java +++ b/src/test/java/org/arkecosystem/client/ClientManagerTest.java @@ -26,9 +26,11 @@ public void shouldThrowIfClientAlreadyExists() { ClientManager manager = new ClientManager(); manager.connect(map.get("host").toString(), "dummy-client"); - assertThrows(IllegalArgumentException.class, () -> { - manager.connect(map.get("host").toString(), "dummy-client"); - }); + assertThrows( + IllegalArgumentException.class, + () -> { + manager.connect(map.get("host").toString(), "dummy-client"); + }); } @Test @@ -59,9 +61,11 @@ public void client() { public void shouldThrowIfClientDoesNotExist() { ClientManager manager = new ClientManager(); - assertThrows(IllegalArgumentException.class, () -> { - manager.client("non-existent-client"); - }); + assertThrows( + IllegalArgumentException.class, + () -> { + manager.client("non-existent-client"); + }); } @Test @@ -98,4 +102,4 @@ public void getClients() { assertEquals(0, manager.getClients().size()); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/MockHelper.java b/src/test/java/org/arkecosystem/client/MockHelper.java index 6f44f69..c7a9aac 100644 --- a/src/test/java/org/arkecosystem/client/MockHelper.java +++ b/src/test/java/org/arkecosystem/client/MockHelper.java @@ -24,4 +24,4 @@ public static ArkClient client() { return client; } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java b/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java index 9e35dad..1967767 100644 --- a/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java +++ b/src/test/java/org/arkecosystem/client/api/ApiNodesTest.java @@ -24,4 +24,4 @@ void allWithParams() throws IOException { client.api().apiNodes.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/BlockchainTest.java b/src/test/java/org/arkecosystem/client/api/BlockchainTest.java index 35e3db2..42bbd79 100644 --- a/src/test/java/org/arkecosystem/client/api/BlockchainTest.java +++ b/src/test/java/org/arkecosystem/client/api/BlockchainTest.java @@ -16,4 +16,4 @@ void all() throws IOException { Map actual = client.api().blockchain.all(); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/BlocksTest.java b/src/test/java/org/arkecosystem/client/api/BlocksTest.java index 564affb..584b983 100644 --- a/src/test/java/org/arkecosystem/client/api/BlocksTest.java +++ b/src/test/java/org/arkecosystem/client/api/BlocksTest.java @@ -20,8 +20,7 @@ void all() throws IOException { @Test void allWithParams() throws IOException { ArkClient client = MockHelper.client(); - Map actual = - client.api().blocks.param("page", 1).param("limit", 100).all(); + Map actual = client.api().blocks.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @@ -60,4 +59,4 @@ void transactionsWithParams() throws IOException { client.api().blocks.param("page", 1).param("limit", 100).transactions("dummy"); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/CommitsTest.java b/src/test/java/org/arkecosystem/client/api/CommitsTest.java index d605502..1da3631 100644 --- a/src/test/java/org/arkecosystem/client/api/CommitsTest.java +++ b/src/test/java/org/arkecosystem/client/api/CommitsTest.java @@ -16,4 +16,4 @@ void show() throws IOException { Map actual = client.api().commits.show(123456); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/DelegatesTest.java b/src/test/java/org/arkecosystem/client/api/DelegatesTest.java index 0f40bf3..ffe8a5a 100644 --- a/src/test/java/org/arkecosystem/client/api/DelegatesTest.java +++ b/src/test/java/org/arkecosystem/client/api/DelegatesTest.java @@ -53,4 +53,4 @@ void votersWithParams() throws IOException { client.api().delegates.param("page", 1).param("limit", 100).voters("dummy"); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/NodeTest.java b/src/test/java/org/arkecosystem/client/api/NodeTest.java index 61e8c24..2d288d0 100644 --- a/src/test/java/org/arkecosystem/client/api/NodeTest.java +++ b/src/test/java/org/arkecosystem/client/api/NodeTest.java @@ -51,4 +51,4 @@ void crypto() throws IOException { Map actual = client.api().node.crypto(); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/PeersTest.java b/src/test/java/org/arkecosystem/client/api/PeersTest.java index 0958192..64f8575 100644 --- a/src/test/java/org/arkecosystem/client/api/PeersTest.java +++ b/src/test/java/org/arkecosystem/client/api/PeersTest.java @@ -20,8 +20,7 @@ void all() throws IOException { @Test void allWithParams() throws IOException { ArkClient client = MockHelper.client(); - Map actual = - client.api().peers.param("page", 1).param("limit", 100).all(); + Map actual = client.api().peers.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @@ -31,4 +30,4 @@ void show() throws IOException { Map actual = client.api().peers.show("dummy"); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/RoundsTest.java b/src/test/java/org/arkecosystem/client/api/RoundsTest.java index b4c1b24..e4ce579 100644 --- a/src/test/java/org/arkecosystem/client/api/RoundsTest.java +++ b/src/test/java/org/arkecosystem/client/api/RoundsTest.java @@ -27,8 +27,7 @@ void all() throws IOException { @Test void allWithParams() throws IOException { ArkClient client = MockHelper.client(); - Map actual = - client.api().rounds.param("page", 1).param("limit", 100).all(); + Map actual = client.api().rounds.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @@ -38,4 +37,4 @@ void show() throws IOException { Map actual = client.api().rounds.show(12345); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/TransactionsTest.java b/src/test/java/org/arkecosystem/client/api/TransactionsTest.java index ea6e2e5..caa385a 100644 --- a/src/test/java/org/arkecosystem/client/api/TransactionsTest.java +++ b/src/test/java/org/arkecosystem/client/api/TransactionsTest.java @@ -50,8 +50,7 @@ void allUnconfirmed() throws IOException { @Test void allUnconfirmedWithParams() throws IOException { ArkClient client = MockHelper.client(); - Map actual = - client.api().transactions.param("page", 1).allUnconfirmed(); + Map actual = client.api().transactions.param("page", 1).allUnconfirmed(); assertTrue((boolean) actual.get("success")); } @@ -82,4 +81,4 @@ void schemas() throws IOException { Map actual = client.api().transactions.schemas(); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/VotesTest.java b/src/test/java/org/arkecosystem/client/api/VotesTest.java index c82fe11..c97aef7 100644 --- a/src/test/java/org/arkecosystem/client/api/VotesTest.java +++ b/src/test/java/org/arkecosystem/client/api/VotesTest.java @@ -20,8 +20,7 @@ void all() throws IOException { @Test void allWithParams() throws IOException { ArkClient client = MockHelper.client(); - Map actual = - client.api().votes.param("page", 1).param("limit", 100).all(); + Map actual = client.api().votes.param("page", 1).param("limit", 100).all(); assertTrue((boolean) actual.get("success")); } @@ -31,4 +30,4 @@ void show() throws IOException { Map actual = client.api().votes.show("dummy"); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} diff --git a/src/test/java/org/arkecosystem/client/api/WalletsTest.java b/src/test/java/org/arkecosystem/client/api/WalletsTest.java index 0201364..e5864e8 100644 --- a/src/test/java/org/arkecosystem/client/api/WalletsTest.java +++ b/src/test/java/org/arkecosystem/client/api/WalletsTest.java @@ -42,8 +42,7 @@ void transactions() throws IOException { @Test void transactionsWithParams() throws IOException { ArkClient client = MockHelper.client(); - Map actual = - client.api().wallets.param("page", 1).transactions("dummy"); + Map actual = client.api().wallets.param("page", 1).transactions("dummy"); assertTrue((boolean) actual.get("success")); } @@ -104,4 +103,4 @@ void topWithParams() throws IOException { Map actual = client.api().wallets.param("page", 1).top(); assertTrue((boolean) actual.get("success")); } -} \ No newline at end of file +} From 58934742c3c412c5651e93eed5cbbb9a073df1dc Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Fri, 23 Aug 2024 07:57:09 -0600 Subject: [PATCH 17/17] remove duplicated code --- .../arkecosystem/client/api/RoundsTest.java | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/src/test/java/org/arkecosystem/client/api/RoundsTest.java b/src/test/java/org/arkecosystem/client/api/RoundsTest.java index cd58473..e4ce579 100644 --- a/src/test/java/org/arkecosystem/client/api/RoundsTest.java +++ b/src/test/java/org/arkecosystem/client/api/RoundsTest.java @@ -37,26 +37,4 @@ void show() throws IOException { Map actual = client.api().rounds.show(12345); assertTrue((boolean) actual.get("success")); } - - @Test - void all() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().rounds.all(); - assertTrue((boolean) actual.get("success")); - } - - @Test - void allWithParams() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = - connection.api().rounds.param("page", 1).param("limit", 100).all(); - assertTrue((boolean) actual.get("success")); - } - - @Test - void show() throws IOException { - Connection connection = MockHelper.connection(); - Map actual = connection.api().rounds.show(12345); - assertTrue((boolean) actual.get("success")); - } }