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..15669fb --- /dev/null +++ b/src/main/java/org/arkecosystem/client/ArkClient.java @@ -0,0 +1,58 @@ +package org.arkecosystem.client; + +import java.util.Map; +import org.arkecosystem.client.api.Api; +import org.arkecosystem.client.http.Client; + +public class ArkClient { + private final Api api; + private final Client client; + + /** + * 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.client = new Client(hostOrHosts); + 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) { + this.client.setHost(host, type); + } + + /** + * Method to get the current hosts. + * + * @return A map with the current hosts. + */ + public Map getHosts() { + return this.client.getHosts(); + } +} 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..0202ca7 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/ClientManager.java @@ -0,0 +1,112 @@ +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/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; - } -} 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/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); } } diff --git a/src/main/java/org/arkecosystem/client/api/Transactions.java b/src/main/java/org/arkecosystem/client/api/Transactions.java index 5026507..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.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; + } } 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..8b6852d --- /dev/null +++ b/src/test/java/org/arkecosystem/client/ArkClientTest.java @@ -0,0 +1,69 @@ +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 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")); + } +} 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..f176108 --- /dev/null +++ b/src/test/java/org/arkecosystem/client/ClientManagerTest.java @@ -0,0 +1,105 @@ +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()); + } +} 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()); - } -} diff --git a/src/test/java/org/arkecosystem/client/MockHelper.java b/src/test/java/org/arkecosystem/client/MockHelper.java index 5220c6d..c7a9aac 100644 --- a/src/test/java/org/arkecosystem/client/MockHelper.java +++ b/src/test/java/org/arkecosystem/client/MockHelper.java @@ -1,16 +1,20 @@ package org.arkecosystem.client; import java.util.HashMap; +import java.util.Map; import okhttp3.mockwebserver.MockResponse; 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); + 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); @@ -18,6 +22,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..1967767 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")); } } diff --git a/src/test/java/org/arkecosystem/client/api/BlockchainTest.java b/src/test/java/org/arkecosystem/client/api/BlockchainTest.java index e9c127c..42bbd79 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")); } } diff --git a/src/test/java/org/arkecosystem/client/api/BlocksTest.java b/src/test/java/org/arkecosystem/client/api/BlocksTest.java index fc517e4..584b983 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,51 @@ 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(); - Map actual = - connection.api().blocks.param("page", 1).param("limit", 100).all(); + ArkClient client = MockHelper.client(); + Map actual = 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")); } } diff --git a/src/test/java/org/arkecosystem/client/api/CommitsTest.java b/src/test/java/org/arkecosystem/client/api/CommitsTest.java index ceea79d..1da3631 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")); } } diff --git a/src/test/java/org/arkecosystem/client/api/DelegatesTest.java b/src/test/java/org/arkecosystem/client/api/DelegatesTest.java index ec5850a..ffe8a5a 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")); } } 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..2d288d0 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")); } } diff --git a/src/test/java/org/arkecosystem/client/api/PeersTest.java b/src/test/java/org/arkecosystem/client/api/PeersTest.java index ef727ee..64f8575 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,22 @@ 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(); - Map actual = - connection.api().peers.param("page", 1).param("limit", 100).all(); + ArkClient client = MockHelper.client(); + Map actual = 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")); } } diff --git a/src/test/java/org/arkecosystem/client/api/RoundsTest.java b/src/test/java/org/arkecosystem/client/api/RoundsTest.java index f524938..e4ce579 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,29 @@ 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(); - Map actual = - connection.api().rounds.param("page", 1).param("limit", 100).all(); + ArkClient client = MockHelper.client(); + Map actual = 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")); } } diff --git a/src/test/java/org/arkecosystem/client/api/TransactionsTest.java b/src/test/java/org/arkecosystem/client/api/TransactionsTest.java index 79970aa..caa385a 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,72 @@ 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(); - Map actual = - connection.api().transactions.param("page", 1).allUnconfirmed(); + ArkClient client = MockHelper.client(); + Map actual = 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")); } } diff --git a/src/test/java/org/arkecosystem/client/api/VotesTest.java b/src/test/java/org/arkecosystem/client/api/VotesTest.java index 9ef32f0..c97aef7 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,22 @@ 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(); - Map actual = - connection.api().votes.param("page", 1).param("limit", 100).all(); + ArkClient client = MockHelper.client(); + Map actual = 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")); } } diff --git a/src/test/java/org/arkecosystem/client/api/WalletsTest.java b/src/test/java/org/arkecosystem/client/api/WalletsTest.java index 30d7b98..e5864e8 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,95 @@ 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(); - Map actual = - connection.api().wallets.param("page", 1).transactions("dummy"); + ArkClient client = MockHelper.client(); + Map actual = 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")); } }