diff --git a/.travis.yml b/.travis.yml index 7f50b7c..9a1a271 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,17 @@ -language: groovy +language: java jdk: - - oraclejdk8 - - oraclejdk9 - - oraclejdk10 - - openjdk8 +- oraclejdk8 +- oraclejdk9 +- oraclejdk10 +- openjdk8 before_script: - - chmod +x gradlew +- chmod +x gradlew script: - - ./gradlew check - - ./gradlew jacocoTestReport +- ./gradlew check +- ./gradlew jacocoTestReport after_success: - - bash <(curl -s https://codecov.io/bash) +- bash <(curl -s https://codecov.io/bash) diff --git a/build.gradle b/build.gradle index 40358fc..224a7c5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,16 @@ plugins { - id 'groovy' id 'maven' id 'jacoco' } +apply plugin: 'java' + group 'org.arkecosystem.client' version '0.1.0' repositories { jcenter() + mavenCentral() } task createPom { @@ -30,16 +32,20 @@ task createPom { } dependencies { - compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.5.1' compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.11.0' compile group: 'com.squareup.okhttp3', name: 'mockwebserver', version: '3.11.0' compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5' - testCompile group: 'org.spockframework', name: 'spock-core', version: '1.1-groovy-2.4' - testCompile group: 'junit', name: 'junit', version: '4.12' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1' +} - // Build blows up without this? - compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0' +test { + useJUnitPlatform() + failFast = true + testLogging { + events 'PASSED', 'FAILED', 'SKIPPED' + } } jacocoTestReport { diff --git a/src/main/groovy/org/arkecosystem/client/Connection.groovy b/src/main/groovy/org/arkecosystem/client/Connection.groovy deleted file mode 100644 index fdb5f2e..0000000 --- a/src/main/groovy/org/arkecosystem/client/Connection.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package org.arkecosystem.client - -import org.arkecosystem.client.http.* -import org.arkecosystem.client.api.* - -class Connection { - Client client - int version - - Connection(Map config) { - this.version = config.get('version') - this.client = new Client(config.get('host'), config.get('version')) - } - - AbstractAPI api (String name) { - String className = name[0].toUpperCase() + name[1..-1] - String version = (this.version == 1) ? 'one' : 'two' - - Class - .forName("org.arkecosystem.client.api.$version.$className") - .newInstance this.client - } -} diff --git a/src/main/groovy/org/arkecosystem/client/ConnectionManager.groovy b/src/main/groovy/org/arkecosystem/client/ConnectionManager.groovy deleted file mode 100644 index c73652d..0000000 --- a/src/main/groovy/org/arkecosystem/client/ConnectionManager.groovy +++ /dev/null @@ -1,58 +0,0 @@ -package org.arkecosystem.client - -class ConnectionManager { - String defaultConnection = 'main' - Map connections - - ConnectionManager () { - this.connections = new HashMap() - } - - Connection connect(Map config, String name = 'main') - { - if (this.connections.containsKey(name)) { - throw new IllegalArgumentException("Connection [$name] is already configured.") - } - - this.connections.put(name, new Connection(config)) - - this.connections.get(name) - } - - void disconnect(String name = null) - { - if (!name) { - name = getDefaultConnection() - } - - this.connections.remove(name) - } - - Connection connection(String name = null) - { - if (!name) { - name = getDefaultConnection() - } - - if (!this.connections.containsKey(name)) { - throw new IllegalArgumentException("Connection [$name] not configured.") - } - - this.connections.get(name) - } - - String getDefaultConnection() - { - this.defaultConnection - } - - void setDefaultConnection(String name) - { - this.defaultConnection = name - } - - Map getConnections() - { - this.connections - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/AbstractAPI.groovy b/src/main/groovy/org/arkecosystem/client/api/AbstractAPI.groovy deleted file mode 100644 index 6164e1d..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/AbstractAPI.groovy +++ /dev/null @@ -1,11 +0,0 @@ -package org.arkecosystem.client.api - -import org.arkecosystem.client.http.* - -abstract class AbstractAPI { - Client client - - AbstractAPI(Client client) { - this.client = client - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/one/Accounts.groovy b/src/main/groovy/org/arkecosystem/client/api/one/Accounts.groovy deleted file mode 100644 index 269b9fa..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/one/Accounts.groovy +++ /dev/null @@ -1,51 +0,0 @@ -package org.arkecosystem.client.api.one - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Accounts extends AbstractAPI -{ - Accounts(Client client) { - super(client) - } - - Object all(Map query = [:]) - { - this.client.get('accounts/getAllAccounts', query) - } - - Object show(String address) - { - this.client.get('accounts', [address: address]) - } - - Object count() - { - this.client.get('accounts/count') - } - - Object delegates(String address) - { - this.client.get('accounts/delegates', [address: address]) - } - - Object fee() - { - this.client.get('accounts/delegates/fee') - } - - Object balance(String address) - { - this.client.get('accounts/getBalance', [address: address]) - } - - Object publicKey(String address) - { - this.client.get('accounts/getPublicKey', [address: address]) - } - - Object top(Map query = [:]) - { - this.client.get('accounts/top', query) - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/one/Blocks.groovy b/src/main/groovy/org/arkecosystem/client/api/one/Blocks.groovy deleted file mode 100644 index fc1ab49..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/one/Blocks.groovy +++ /dev/null @@ -1,66 +0,0 @@ -package org.arkecosystem.client.api.one - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Blocks extends AbstractAPI -{ - Blocks(Client client) { - super(client) - } - - Object all(Map query = [:]) - { - this.client.get('blocks', query) - } - - Object show(String id) - { - this.client.get('blocks/get', [id: id]) - } - - Object epoch() - { - this.client.get('blocks/getEpoch') - } - - Object fee() - { - this.client.get('blocks/getFee') - } - - Object fees() - { - this.client.get('blocks/getFees') - } - - Object height() - { - this.client.get('blocks/getHeight') - } - - Object milestone() - { - this.client.get('blocks/getMilestone') - } - - Object nethash() - { - this.client.get('blocks/getNethash') - } - - Object reward() - { - this.client.get('blocks/getReward') - } - - Object status() - { - this.client.get('blocks/getStatus') - } - - Object supply() - { - this.client.get('blocks/getSupply') - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/one/Delegates.groovy b/src/main/groovy/org/arkecosystem/client/api/one/Delegates.groovy deleted file mode 100644 index ff5add6..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/one/Delegates.groovy +++ /dev/null @@ -1,51 +0,0 @@ -package org.arkecosystem.client.api.one - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Delegates extends AbstractAPI -{ - Delegates(Client client) { - super(client) - } - - Object all(Map query = [:]) - { - this.client.get('delegates', query) - } - - Object show(Map id) - { - this.client.get('delegates/get', id) - } - - Object count() - { - this.client.get('delegates/count') - } - - Object fee() - { - this.client.get('delegates/fee') - } - - Object forgedByAccount(String generatorPublicKey) - { - this.client.get('delegates/forging/getForgedByAccount', [generatorPublicKey: generatorPublicKey]) - } - - Object search(String query) - { - this.client.get('delegates/search', [q: query]) - } - - Object voters(String publicKey) - { - this.client.get('delegates/voters', [publicKey: publicKey]) - } - - Object nextForgers() - { - this.client.get('delegates/getNextForgers') - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/one/Loader.groovy b/src/main/groovy/org/arkecosystem/client/api/one/Loader.groovy deleted file mode 100644 index 0988ee1..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/one/Loader.groovy +++ /dev/null @@ -1,26 +0,0 @@ -package org.arkecosystem.client.api.one - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Loader extends AbstractAPI -{ - Loader(Client client) { - super(client) - } - - Object status() - { - this.client.get('loader/status') - } - - Object sync() - { - this.client.get('loader/status/sync') - } - - Object autoconfigure() - { - this.client.get('loader/autoconfigure') - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/one/Peers.groovy b/src/main/groovy/org/arkecosystem/client/api/one/Peers.groovy deleted file mode 100644 index 39deb1d..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/one/Peers.groovy +++ /dev/null @@ -1,26 +0,0 @@ -package org.arkecosystem.client.api.one - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Peers extends AbstractAPI -{ - Peers(Client client) { - super(client) - } - - Object all(Map query = [:]) - { - this.client.get('peers', query) - } - - Object show(String ip, int port) - { - this.client.get('peers/get', [ip: ip, port: port]) - } - - Object version() - { - this.client.get('peers/version') - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/one/Signatures.groovy b/src/main/groovy/org/arkecosystem/client/api/one/Signatures.groovy deleted file mode 100644 index 82a30fc..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/one/Signatures.groovy +++ /dev/null @@ -1,16 +0,0 @@ -package org.arkecosystem.client.api.one - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Signatures extends AbstractAPI -{ - Signatures(Client client) { - super(client) - } - - Object fee() - { - this.client.get('signatures/fee') - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/one/Transactions.groovy b/src/main/groovy/org/arkecosystem/client/api/one/Transactions.groovy deleted file mode 100644 index 7ecc234..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/one/Transactions.groovy +++ /dev/null @@ -1,31 +0,0 @@ -package org.arkecosystem.client.api.one - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Transactions extends AbstractAPI -{ - Transactions(Client client) { - super(client) - } - - Object all(Map query = [:]) - { - this.client.get('transactions', query) - } - - Object show(String id) - { - this.client.get('transactions/get', [id: id]) - } - - Object allUnconfirmed(Map query = [:]) - { - this.client.get('transactions/unconfirmed', query) - } - - Object showUnconfirmed(String id) - { - this.client.get('transactions/unconfirmed/get', [id: id]) - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/two/Blocks.groovy b/src/main/groovy/org/arkecosystem/client/api/two/Blocks.groovy deleted file mode 100644 index 77ef661..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/two/Blocks.groovy +++ /dev/null @@ -1,31 +0,0 @@ -package org.arkecosystem.client.api.two - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Blocks extends AbstractAPI -{ - Blocks(Client client) { - super(client) - } - - Object all() - { - this.client.get('blocks') - } - - Object show(String id) - { - this.client.get("blocks/{id}") - } - - Object transactions(String id) - { - this.client.get("blocks/{id}/transactions") - } - - Object search(Map parameters) - { - this.client.post('blocks/search', parameters) - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/two/Delegates.groovy b/src/main/groovy/org/arkecosystem/client/api/two/Delegates.groovy deleted file mode 100644 index f98b656..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/two/Delegates.groovy +++ /dev/null @@ -1,31 +0,0 @@ -package org.arkecosystem.client.api.two - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Delegates extends AbstractAPI -{ - Delegates(Client client) { - super(client) - } - - Object all() - { - this.client.get('delegates') - } - - Object show(String id) - { - this.client.get("delegates/{id}") - } - - Object blocks(String id) - { - this.client.get("delegates/{id}/blocks") - } - - Object voters(String id) - { - this.client.get("delegates/{id}/voters") - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/two/Node.groovy b/src/main/groovy/org/arkecosystem/client/api/two/Node.groovy deleted file mode 100644 index 8a9adb6..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/two/Node.groovy +++ /dev/null @@ -1,26 +0,0 @@ -package org.arkecosystem.client.api.two - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Node extends AbstractAPI -{ - Node(Client client) { - super(client) - } - - Object status() - { - this.client.get('node/status') - } - - Object syncing() - { - this.client.get('node/syncing') - } - - Object configuration() - { - this.client.get('node/configuration') - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/two/Peers.groovy b/src/main/groovy/org/arkecosystem/client/api/two/Peers.groovy deleted file mode 100644 index c058b44..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/two/Peers.groovy +++ /dev/null @@ -1,21 +0,0 @@ -package org.arkecosystem.client.api.two - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Peers extends AbstractAPI -{ - Peers(Client client) { - super(client) - } - - Object all() - { - this.client.get('peers') - } - - Object show(String ip) - { - this.client.get("peers/{ip}") - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/two/Transactions.groovy b/src/main/groovy/org/arkecosystem/client/api/two/Transactions.groovy deleted file mode 100644 index 68f5da4..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/two/Transactions.groovy +++ /dev/null @@ -1,46 +0,0 @@ -package org.arkecosystem.client.api.two - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Transactions extends AbstractAPI -{ - Transactions(Client client) { - super(client) - } - - Object all() - { - this.client.get('transactions') - } - - Object create(Map transactions) - { - this.client.post('transactions', transactions) - } - - Object show(String id) - { - this.client.get("transactions/{id}") - } - - Object allUnconfirmed() - { - this.client.get('transactions/unconfirmed') - } - - Object showUnconfirmed(String id) - { - this.client.get("transactions/unconfirmed/{id}") - } - - Object search(Map parameters) - { - this.client.post('transactions/search', parameters) - } - - Object types() - { - this.client.get('transactions/types') - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/two/Votes.groovy b/src/main/groovy/org/arkecosystem/client/api/two/Votes.groovy deleted file mode 100644 index a2da80d..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/two/Votes.groovy +++ /dev/null @@ -1,21 +0,0 @@ -package org.arkecosystem.client.api.two - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Votes extends AbstractAPI -{ - Votes(Client client) { - super(client) - } - - Object all() - { - this.client.get('votes') - } - - Object show(String id) - { - this.client.get("votes/{id}") - } -} diff --git a/src/main/groovy/org/arkecosystem/client/api/two/Wallets.groovy b/src/main/groovy/org/arkecosystem/client/api/two/Wallets.groovy deleted file mode 100644 index dcdbcf7..0000000 --- a/src/main/groovy/org/arkecosystem/client/api/two/Wallets.groovy +++ /dev/null @@ -1,51 +0,0 @@ -package org.arkecosystem.client.api.two - -import org.arkecosystem.client.api.AbstractAPI -import org.arkecosystem.client.http.Client - -class Wallets extends AbstractAPI -{ - Wallets(Client client) { - super(client) - } - - Object all() - { - this.client.get('wallets') - } - - Object show(String id) - { - this.client.get("wallets/{id}") - } - - Object transactions(String id) - { - this.client.get("wallets/{id}/transactions") - } - - Object sentTransactions(String id) - { - this.client.get("wallets/{id}/transactions/sent") - } - - Object receivedTransactions(String id) - { - this.client.get("wallets/{id}/transactions/received") - } - - Object votes(String id) - { - this.client.get("wallets/{id}/votes") - } - - Object search(Map parameters) - { - this.client.post('wallets/search', parameters) - } - - Object top() - { - this.client.get('wallets/top') - } -} diff --git a/src/main/groovy/org/arkecosystem/client/http/Client.groovy b/src/main/groovy/org/arkecosystem/client/http/Client.groovy deleted file mode 100644 index 0c980e0..0000000 --- a/src/main/groovy/org/arkecosystem/client/http/Client.groovy +++ /dev/null @@ -1,47 +0,0 @@ -package org.arkecosystem.client.http - -import okhttp3.* -import com.google.gson.Gson - -class Client { - String host - int version - - OkHttpClient client - MediaType JSON = MediaType.parse("application/json charset=utf-8") - - Client (String host, int version) { - this.host = host - this.version = version - this.client = new OkHttpClient() - } - - Object get(String url, Map params = [:]) throws IOException { - HttpUrl.Builder httpBuider = HttpUrl.parse(this.host + url).newBuilder() - - if (params != null) { - params.entrySet().each { Map.Entry param -> - httpBuider.addQueryParameter(param.getKey(), param.getValue().toString()) - } - } - - Request request = new Request.Builder().url(httpBuider.build()).build() - - Response response = client.newCall(request).execute() - - return new Gson().fromJson(response.body().string(), Object.class) - } - - Object 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() - - Response response = client.newCall(request).execute() - - return new Gson().fromJson(response.body().string(), Object.class) - } -} diff --git a/src/main/java/org/arkecosystem/client/Connection.java b/src/main/java/org/arkecosystem/client/Connection.java new file mode 100644 index 0000000..d83c927 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/Connection.java @@ -0,0 +1,28 @@ +package org.arkecosystem.client; + +import org.arkecosystem.client.api.AbstractAPI; +import org.arkecosystem.client.api.one.One; +import org.arkecosystem.client.api.two.Two; +import org.arkecosystem.client.http.Client; + +import java.util.Map; + +public class Connection { + + private Client client; + private int version; + + private T api; + + public Connection(Map config) { + this.version = ((int) (config.get("version"))); + this.client = new Client(config.get("host").toString(), (int) config.get("version")); + + this.api = (T) ((this.version == 1) ? new One(this.client) : new Two(this.client)); + } + + public T api() { + return this.api; + } + +} diff --git a/src/main/java/org/arkecosystem/client/ConnectionManager.java b/src/main/java/org/arkecosystem/client/ConnectionManager.java new file mode 100644 index 0000000..fcc45c5 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/ConnectionManager.java @@ -0,0 +1,70 @@ +package org.arkecosystem.client; + +import org.arkecosystem.client.api.AbstractAPI; + +import java.util.HashMap; +import java.util.Map; + +public class ConnectionManager { + private 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 (Connection) 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 (Connection) this.connections.get(name); + } + + public Connection connection() { + return connection(null); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/AbstractAPI.java b/src/main/java/org/arkecosystem/client/api/AbstractAPI.java new file mode 100644 index 0000000..301830d --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/AbstractAPI.java @@ -0,0 +1,12 @@ +package org.arkecosystem.client.api; + +import org.arkecosystem.client.http.Client; + +public abstract class AbstractAPI { + + protected Client client; + + public AbstractAPI(Client client) { + this.client = client; + } +} diff --git a/src/main/java/org/arkecosystem/client/api/one/Accounts.java b/src/main/java/org/arkecosystem/client/api/one/Accounts.java new file mode 100644 index 0000000..b5126b3 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/one/Accounts.java @@ -0,0 +1,65 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class Accounts { + Client client; + + public Accounts(Client client) { + this.client = client; + } + + public LinkedTreeMap all(Map query) throws IOException { + return this.client.get("accounts/getAllAccounts", query); + } + + public LinkedTreeMap all() throws IOException { + return this.all(new HashMap()); + } + + public LinkedTreeMap show(String address) throws IOException { + HashMap map = new HashMap<>(); + map.put("address", address); + return this.client.get("accounts", map); + } + + public LinkedTreeMap count() throws IOException { + return this.client.get("accounts/count"); + } + + public LinkedTreeMap delegates(String address) throws IOException { + HashMap map = new HashMap<>(); + map.put("address", address); + return this.client.get("accounts/delegates", map); + } + + public LinkedTreeMap fee() throws IOException { + return this.client.get("accounts/delegates/fee"); + } + + public LinkedTreeMap balance(String address) throws IOException { + HashMap map = new HashMap<>(); + map.put("address", address); + return this.client.get("accounts/getBalance", map); + } + + public LinkedTreeMap publicKey(String address) throws IOException { + HashMap map = new HashMap<>(); + map.put("address", address); + return this.client.get("accounts/getPublicKey", map); + } + + public LinkedTreeMap top(Map query) throws IOException { + return this.client.get("accounts/top", query); + } + + public LinkedTreeMap top() throws IOException { + return top(new HashMap()); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/one/Blocks.java b/src/main/java/org/arkecosystem/client/api/one/Blocks.java new file mode 100644 index 0000000..db74590 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/one/Blocks.java @@ -0,0 +1,67 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class Blocks { + Client client; + + public Blocks(Client client) { + this.client = client; + } + + public LinkedTreeMap all(Map query) throws IOException { + return this.client.get("blocks", query); + } + + public LinkedTreeMap all() throws IOException { + return this.all(new HashMap()); + } + + public LinkedTreeMap show(String id) throws IOException { + HashMap map = new HashMap<>(); + map.put("id", id); + return this.client.get("blocks/get", map); + } + + public LinkedTreeMap epoch() throws IOException { + return this.client.get("blocks/getEpoch"); + } + + public LinkedTreeMap fee() throws IOException { + return this.client.get("blocks/getFee"); + } + + public LinkedTreeMap fees() throws IOException { + return this.client.get("blocks/getFees"); + } + + public LinkedTreeMap height() throws IOException { + return this.client.get("blocks/getHeight"); + } + + public LinkedTreeMap milestone() throws IOException { + return this.client.get("blocks/getMilestone"); + } + + public LinkedTreeMap nethash() throws IOException { + return this.client.get("blocks/getNethash"); + } + + public LinkedTreeMap reward() throws IOException { + return this.client.get("blocks/getReward"); + } + + public LinkedTreeMap status() throws IOException { + return this.client.get("blocks/getStatus"); + } + + public LinkedTreeMap supply() throws IOException { + return this.client.get("blocks/getSupply"); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/one/Delegates.java b/src/main/java/org/arkecosystem/client/api/one/Delegates.java new file mode 100644 index 0000000..1b066a3 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/one/Delegates.java @@ -0,0 +1,59 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class Delegates { + Client client; + + public Delegates(Client client) { + this.client = client; + } + + public LinkedTreeMap all(Map query) throws IOException { + return this.client.get("delegates", query); + } + + public LinkedTreeMap all() throws IOException { + return this.all(new HashMap()); + } + + public LinkedTreeMap show(Map id) throws IOException { + return this.client.get("delegates/get", id); + } + + public LinkedTreeMap count() throws IOException { + return this.client.get("delegates/count"); + } + + public LinkedTreeMap fee() throws IOException { + return this.client.get("delegates/fee"); + } + + public LinkedTreeMap forgedByAccount(String generatorPublicKey) throws IOException { + HashMap map = new HashMap<>(); + map.put("generatorPublicKey", generatorPublicKey); + return this.client.get("delegates/forging/getForgedByAccount", map); + } + + public LinkedTreeMap search(String query) throws IOException { + HashMap map = new HashMap<>(); + map.put("q", query); + return this.client.get("delegates/search", map); + } + + public LinkedTreeMap voters(String publicKey) throws IOException { + HashMap map = new HashMap<>(); + map.put("publicKey", publicKey); + return this.client.get("delegates/voters", map); + } + + public LinkedTreeMap nextForgers() throws IOException { + return this.client.get("delegates/getNextForgers"); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/one/Loader.java b/src/main/java/org/arkecosystem/client/api/one/Loader.java new file mode 100644 index 0000000..78bdf57 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/one/Loader.java @@ -0,0 +1,27 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; + +public class Loader { + Client client; + + public Loader(Client client) { + this.client = client; + } + + public LinkedTreeMap status() throws IOException { + return this.client.get("loader/status"); + } + + public LinkedTreeMap sync() throws IOException { + return this.client.get("loader/status/sync"); + } + + public LinkedTreeMap autoconfigure() throws IOException { + return this.client.get("loader/autoconfigure"); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/one/One.java b/src/main/java/org/arkecosystem/client/api/one/One.java new file mode 100644 index 0000000..1885608 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/one/One.java @@ -0,0 +1,26 @@ +package org.arkecosystem.client.api.one; + +import org.arkecosystem.client.api.AbstractAPI; +import org.arkecosystem.client.http.Client; + +public class One extends AbstractAPI { + + public Accounts accounts; + public Blocks blocks; + public Delegates delegates; + public Loader loader; + public Peers peers; + public Signatures signatures; + public Transactions transactions; + + public One(Client client) { + super(client); + this.accounts = new Accounts(client); + this.blocks = new Blocks(client); + this.delegates = new Delegates(client); + this.loader = new Loader(client); + this.peers = new Peers(client); + this.signatures = new Signatures(client); + this.transactions = new Transactions(client); + } +} diff --git a/src/main/java/org/arkecosystem/client/api/one/Peers.java b/src/main/java/org/arkecosystem/client/api/one/Peers.java new file mode 100644 index 0000000..76a7047 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/one/Peers.java @@ -0,0 +1,36 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class Peers { + Client client; + + public Peers(Client client) { + this.client = client; + } + + public LinkedTreeMap all(Map query) throws IOException { + return this.client.get("peers", query); + } + + public LinkedTreeMap all() throws IOException { + return this.all(new HashMap()); + } + + public LinkedTreeMap show(String ip, int port) throws IOException { + HashMap map = new HashMap<>(); + map.put("ip", ip); + map.put("port", port); + return this.client.get("peers/get", map); + } + + public LinkedTreeMap version() throws IOException { + return this.client.get("peers/version"); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/one/Signatures.java b/src/main/java/org/arkecosystem/client/api/one/Signatures.java new file mode 100644 index 0000000..023ecc4 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/one/Signatures.java @@ -0,0 +1,19 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; + +public class Signatures { + Client client; + + public Signatures(Client client) { + this.client = client; + } + + public LinkedTreeMap fee() throws IOException { + return this.client.get("signatures/fee"); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/one/Transactions.java b/src/main/java/org/arkecosystem/client/api/one/Transactions.java new file mode 100644 index 0000000..9409512 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/one/Transactions.java @@ -0,0 +1,45 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class Transactions { + Client client; + + public Transactions(Client client) { + this.client = client; + } + + public LinkedTreeMap all(Map query) throws IOException { + return this.client.get("transactions", query); + } + + public LinkedTreeMap all() throws IOException { + return this.all(new HashMap()); + } + + public LinkedTreeMap show(String id) throws IOException { + HashMap map = new HashMap<>(); + map.put("id", id); + return this.client.get("transactions/get", map); + } + + public LinkedTreeMap allUnconfirmed(Map query) throws IOException { + return this.client.get("transactions/unconfirmed", query); + } + + public LinkedTreeMap allUnconfirmed() throws IOException { + return this.allUnconfirmed(new HashMap()); + } + + public LinkedTreeMap showUnconfirmed(String id) throws IOException { + HashMap map = new HashMap<>(); + map.put("id", id); + return this.client.get("transactions/unconfirmed/get", map); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/two/Blocks.java b/src/main/java/org/arkecosystem/client/api/two/Blocks.java new file mode 100644 index 0000000..5993f4e --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/two/Blocks.java @@ -0,0 +1,32 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; +import java.util.Map; + +public class Blocks { + Client client; + + public Blocks(Client client) { + this.client = client; + } + + public LinkedTreeMap all() throws IOException { + return this.client.get("blocks"); + } + + public LinkedTreeMap show(String id) throws IOException { + return this.client.get("blocks/" + id); + } + + public LinkedTreeMap transactions(String id) throws IOException { + return this.client.get("blocks/" + id + "/transactions"); + } + + public LinkedTreeMap search(Map parameters) throws IOException { + return this.client.post("blocks/search", parameters); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/two/Delegates.java b/src/main/java/org/arkecosystem/client/api/two/Delegates.java new file mode 100644 index 0000000..8e2eb33 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/two/Delegates.java @@ -0,0 +1,31 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; + +public class Delegates { + Client client; + + public Delegates(Client client) { + this.client = client; + } + + public LinkedTreeMap all() throws IOException { + return this.client.get("delegates"); + } + + public LinkedTreeMap show(String id) throws IOException { + return this.client.get("delegates/" + id); + } + + public LinkedTreeMap blocks(String id) throws IOException { + return this.client.get("delegates/" + id + "/blocks"); + } + + public LinkedTreeMap voters(String id) throws IOException { + return this.client.get("delegates/" + id + "/voters"); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/two/Node.java b/src/main/java/org/arkecosystem/client/api/two/Node.java new file mode 100644 index 0000000..c0008f5 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/two/Node.java @@ -0,0 +1,27 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; + +public class Node { + Client client; + + public Node(Client client) { + this.client = client; + } + + public LinkedTreeMap status() throws IOException { + return this.client.get("node/status"); + } + + public LinkedTreeMap syncing() throws IOException { + return this.client.get("node/syncing"); + } + + public LinkedTreeMap configuration() throws IOException { + return this.client.get("node/configuration"); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/two/Peers.java b/src/main/java/org/arkecosystem/client/api/two/Peers.java new file mode 100644 index 0000000..dfb08da --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/two/Peers.java @@ -0,0 +1,23 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; + +public class Peers { + Client client; + + public Peers(Client client) { + this.client = client; + } + + public LinkedTreeMap all() throws IOException { + return this.client.get("peers"); + } + + public LinkedTreeMap show(String ip) throws IOException { + return this.client.get("peers/" + ip); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/two/Transactions.java b/src/main/java/org/arkecosystem/client/api/two/Transactions.java new file mode 100644 index 0000000..cb67f97 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/two/Transactions.java @@ -0,0 +1,44 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; +import java.util.Map; + +public class Transactions { + Client client; + + public Transactions(Client client) { + this.client = client; + } + + public LinkedTreeMap all() throws IOException { + return this.client.get("transactions"); + } + + public LinkedTreeMap create(Map transactions) throws IOException { + return this.client.post("transactions", transactions); + } + + public LinkedTreeMap show(String id) throws IOException { + return this.client.get("transactions/" + id); + } + + public LinkedTreeMap allUnconfirmed() throws IOException { + return this.client.get("transactions/unconfirmed"); + } + + public LinkedTreeMap showUnconfirmed(String id) throws IOException { + return this.client.get("transactions/unconfirmed/" + id); + } + + public LinkedTreeMap search(Map parameters) throws IOException { + return this.client.post("blocks/search", parameters); + } + + public LinkedTreeMap types() throws IOException { + return this.client.get("transactions/types"); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/two/Two.java b/src/main/java/org/arkecosystem/client/api/two/Two.java new file mode 100644 index 0000000..47e7918 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/two/Two.java @@ -0,0 +1,26 @@ +package org.arkecosystem.client.api.two; + +import org.arkecosystem.client.api.AbstractAPI; +import org.arkecosystem.client.http.Client; + +public class Two extends AbstractAPI { + + public Blocks blocks; + public Delegates delegates; + public Node node; + public Peers peers; + public Transactions transactions; + public Votes votes; + public Wallets wallets; + + public Two(Client client) { + super(client); + this.blocks = new Blocks(client); + this.delegates = new Delegates(client); + this.node = new Node(client); + this.peers = new Peers(client); + this.transactions = new Transactions(client); + this.votes = new Votes(client); + this.wallets = new Wallets(client); + } +} diff --git a/src/main/java/org/arkecosystem/client/api/two/Votes.java b/src/main/java/org/arkecosystem/client/api/two/Votes.java new file mode 100644 index 0000000..6bda858 --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/two/Votes.java @@ -0,0 +1,23 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; + +public class Votes { + Client client; + + public Votes(Client client) { + this.client = client; + } + + public LinkedTreeMap all() throws IOException { + return this.client.get("votes"); + } + + public LinkedTreeMap show(String ip) throws IOException { + return this.client.get("votes/" + ip); + } + +} diff --git a/src/main/java/org/arkecosystem/client/api/two/Wallets.java b/src/main/java/org/arkecosystem/client/api/two/Wallets.java new file mode 100644 index 0000000..51855de --- /dev/null +++ b/src/main/java/org/arkecosystem/client/api/two/Wallets.java @@ -0,0 +1,48 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.http.Client; + +import java.io.IOException; +import java.util.Map; + +public class Wallets { + Client client; + + public Wallets(Client client) { + this.client = client; + } + + public LinkedTreeMap all() throws IOException { + return this.client.get("wallets"); + } + + public LinkedTreeMap show(String ip) throws IOException { + return this.client.get("wallets/" + ip); + } + + public LinkedTreeMap transactions(String ip) throws IOException { + return this.client.get("wallets/" + ip + "/transactions"); + } + + public LinkedTreeMap sentTransactions(String ip) throws IOException { + return this.client.get("wallets/" + ip + "/transactions/sent"); + } + + public LinkedTreeMap receivedTransactions(String ip) throws IOException { + return this.client.get("wallets/" + ip + "/transactions/received"); + } + + public LinkedTreeMap votes(String ip) throws IOException { + return this.client.get("wallets/" + ip + "/votes"); + } + + public LinkedTreeMap search(Map parameters) throws IOException { + return this.client.post("wallets/search", parameters); + } + + public LinkedTreeMap top() throws IOException { + return this.client.get("wallets/top"); + } + +} diff --git a/src/main/java/org/arkecosystem/client/http/Client.java b/src/main/java/org/arkecosystem/client/http/Client.java new file mode 100644 index 0000000..4ca1a1d --- /dev/null +++ b/src/main/java/org/arkecosystem/client/http/Client.java @@ -0,0 +1,56 @@ +package org.arkecosystem.client.http; + +import com.google.gson.Gson; +import com.google.gson.internal.LinkedTreeMap; +import okhttp3.*; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class Client { + private String host; + private int version; + private OkHttpClient client; + private MediaType JSON = MediaType.parse("application/json charset=utf-8"); + + public Client(String host, int version) { + this.host = host; + this.version = version; + this.client = new OkHttpClient(); + } + + public LinkedTreeMap get(String url, Map params) throws IOException { + HttpUrl.Builder httpBuider = HttpUrl.parse(this.host + url).newBuilder(); + + if (params != null) { + for (Map.Entry entry : params.entrySet()) { + httpBuider.addQueryParameter(entry.getKey(), entry.getValue().toString()); + } + } + + Request request = new Request.Builder().url(httpBuider.build()).build(); + Response response = client.newCall(request).execute(); + return new Gson().fromJson(response.body().string(), new LinkedTreeMap().getClass()); + } + + public LinkedTreeMap get(String url) throws IOException { + return get(url, new HashMap()); + } + + public LinkedTreeMap 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(); + Response response = client.newCall(request).execute(); + return new Gson().fromJson(response.body().string(), new LinkedTreeMap().getClass()); + } + + public OkHttpClient getClient() { + return client; + } + + public void setClient(OkHttpClient client) { + this.client = client; + } + +} diff --git a/src/test/groovy/org/arkecosystem/client/ConnectionManagerTest.groovy b/src/test/groovy/org/arkecosystem/client/ConnectionManagerTest.groovy deleted file mode 100644 index 39feee9..0000000 --- a/src/test/groovy/org/arkecosystem/client/ConnectionManagerTest.groovy +++ /dev/null @@ -1,67 +0,0 @@ -package org.arkecosystem.client - -import spock.lang.Specification -import org.arkecosystem.client.* - -class ConnectionManagerTest extends Specification { - def "connect"() { - setup: - def manager = new ConnectionManager() - when: - def connection = manager.connect([host: 'dummy', version: 1]) - then: - connection - } - - def "disconnect"() { - setup: - def manager = new ConnectionManager() - when: - manager.connect([host: 'dummy', version: 1]) - then: - manager.connection('main') - manager.getConnections().size() == 1 - manager.disconnect() - manager.getConnections().size() == 0 - } - - def "connection"() { - setup: - def manager = new ConnectionManager() - when: - manager.connect([host: 'dummy', version: 1]) - then: - manager.connection('main') - } - - def "getDefaultConnection"() { - setup: - def manager = new ConnectionManager() - when: - def actual = manager.getDefaultConnection() - then: - actual == 'main' - } - - def "setDefaultConnection"() { - setup: - def manager = new ConnectionManager() - when: - manager.connect([host: 'dummy', version: 1]) - then: - manager.getDefaultConnection() == 'main' - manager.setDefaultConnection('dummy') - manager.getDefaultConnection() == 'dummy' - } - - def "getConnections"() { - setup: - def manager = new ConnectionManager() - when: - manager.connect([host: 'dummy', version: 1]) - then: - manager.getConnections().size() == 1 - manager.disconnect() - manager.getConnections().size() == 0 - } -} diff --git a/src/test/groovy/org/arkecosystem/client/MockHelper.groovy b/src/test/groovy/org/arkecosystem/client/MockHelper.groovy deleted file mode 100644 index 916e25a..0000000 --- a/src/test/groovy/org/arkecosystem/client/MockHelper.groovy +++ /dev/null @@ -1,22 +0,0 @@ -package org.arkecosystem.client - -import okhttp3.mockwebserver.* - -class MockHelper { - static Connection connection(int version = 1) { - MockWebServer mockServer = new MockWebServer() - - Connection connection = new Connection([ - host: mockServer.url('/').toString(), - version: version - ]) - - MockResponse mockedResponse = new MockResponse() - mockedResponse.setResponseCode(200) - mockedResponse.setBody("{\"success\":true}") - - mockServer.enqueue(mockedResponse) - - connection - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/one/AccountsTest.groovy b/src/test/groovy/org/arkecosystem/client/api/one/AccountsTest.groovy deleted file mode 100644 index a71fd59..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/one/AccountsTest.groovy +++ /dev/null @@ -1,78 +0,0 @@ -package org.arkecosystem.client.api.one - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class AccountsTest extends Specification { - def "all"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('accounts').all() - then: - actual.success == true - } - - def "show"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('accounts').show("dummy") - then: - actual.success == true - } - - def "count"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('accounts').count() - then: - actual.success == true - } - - def "delegates"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('accounts').delegates("dummy") - then: - actual.success == true - } - - def "fee"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('accounts').fee() - then: - actual.success == true - } - - def "balance"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('accounts').balance("dummy") - then: - actual.success == true - } - - def "publicKey"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('accounts').publicKey("dummy") - then: - actual.success == true - } - - def "top"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('accounts').top() - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/one/BlocksTest.groovy b/src/test/groovy/org/arkecosystem/client/api/one/BlocksTest.groovy deleted file mode 100644 index bedada6..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/one/BlocksTest.groovy +++ /dev/null @@ -1,105 +0,0 @@ -package org.arkecosystem.client.api.one - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class BlocksTest extends Specification { - def "all"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('blocks').all() - then: - actual.success == true - } - - def "show"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('blocks').show("dummy") - then: - actual.success == true - } - - def "epoch"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('blocks').epoch() - then: - actual.success == true - } - - def "fee"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('blocks').fee() - then: - actual.success == true - } - - def "fees"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('blocks').fees() - then: - actual.success == true - } - - def "height"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('blocks').height() - then: - actual.success == true - } - - def "milestone"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('blocks').milestone() - then: - actual.success == true - } - - def "nethash"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('blocks').nethash() - then: - actual.success == true - } - - def "reward"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('blocks').reward() - then: - actual.success == true - } - - def "status"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('blocks').status() - then: - actual.success == true - } - - def "supply"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('blocks').supply() - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/one/DelegatesTest.groovy b/src/test/groovy/org/arkecosystem/client/api/one/DelegatesTest.groovy deleted file mode 100644 index 67e201d..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/one/DelegatesTest.groovy +++ /dev/null @@ -1,78 +0,0 @@ -package org.arkecosystem.client.api.one - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class DelegatesTest extends Specification { - def "all"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('delegates').all() - then: - actual.success == true - } - - def "show"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('delegates').show([username: "dummy"]) - then: - actual.success == true - } - - def "count"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('delegates').count() - then: - actual.success == true - } - - def "fee"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('delegates').fee() - then: - actual.success == true - } - - def "forgedByAccount"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('delegates').forgedByAccount() - then: - actual.success == true - } - - def "search"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('delegates').search("dummy") - then: - actual.success == true - } - - def "voters"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('delegates').voters("dummy") - then: - actual.success == true - } - - def "nextForgers"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('delegates').nextForgers() - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/one/LoaderTest.groovy b/src/test/groovy/org/arkecosystem/client/api/one/LoaderTest.groovy deleted file mode 100644 index 120715b..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/one/LoaderTest.groovy +++ /dev/null @@ -1,33 +0,0 @@ -package org.arkecosystem.client.api.one - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class LoaderTest extends Specification { - def "status"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('loader').status() - then: - actual.success == true - } - - def "sync"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('loader').sync() - then: - actual.success == true - } - - def "autoconfigure"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('loader').autoconfigure() - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/one/PeersTest.groovy b/src/test/groovy/org/arkecosystem/client/api/one/PeersTest.groovy deleted file mode 100644 index 1a2f2dc..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/one/PeersTest.groovy +++ /dev/null @@ -1,33 +0,0 @@ -package org.arkecosystem.client.api.one - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class PeersTest extends Specification { - def "all"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('peers').all() - then: - actual.success == true - } - - def "show"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('peers').show("ip", 1234) - then: - actual.success == true - } - - def "version"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('peers').version() - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/one/SignaturesTest.groovy b/src/test/groovy/org/arkecosystem/client/api/one/SignaturesTest.groovy deleted file mode 100644 index db45e0e..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/one/SignaturesTest.groovy +++ /dev/null @@ -1,15 +0,0 @@ -package org.arkecosystem.client.api.one - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class SignaturesTest extends Specification { - def "fee"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('signatures').fee() - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/one/TransactionsTest.groovy b/src/test/groovy/org/arkecosystem/client/api/one/TransactionsTest.groovy deleted file mode 100644 index 1f69268..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/one/TransactionsTest.groovy +++ /dev/null @@ -1,24 +0,0 @@ -package org.arkecosystem.client.api.one - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class TransactionsTest extends Specification { - def "all"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('transactions').all() - then: - actual.success == true - } - - def "show"() { - setup: - def connection = MockHelper.connection() - when: - def actual = connection.api('transactions').show('038716f2d525f2f1a4f02f85b7e51c7cf46420c1505ffceee7495b5271a205ad') - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/two/BlocksTest.groovy b/src/test/groovy/org/arkecosystem/client/api/two/BlocksTest.groovy deleted file mode 100644 index b1daf15..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/two/BlocksTest.groovy +++ /dev/null @@ -1,42 +0,0 @@ -package org.arkecosystem.client.api.two - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class BlocksTest extends Specification { - def "all"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('wallets').all() - then: - actual.success == true - } - - def "show"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('wallets').show("dummy") - then: - actual.success == true - } - - def "transactions"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('wallets').transactions("dummy") - then: - actual.success == true - } - - def "search"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('wallets').search() - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/two/DelegatesTest.groovy b/src/test/groovy/org/arkecosystem/client/api/two/DelegatesTest.groovy deleted file mode 100644 index fd1d787..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/two/DelegatesTest.groovy +++ /dev/null @@ -1,42 +0,0 @@ -package org.arkecosystem.client.api.two - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class DelegatesTest extends Specification { - def "all"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('delegates').all() - then: - actual.success == true - } - - def "show"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('delegates').show("dummy") - then: - actual.success == true - } - - def "blocks"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('delegates').blocks("dummy") - then: - actual.success == true - } - - def "voters"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('delegates').voters("dummy") - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/two/NodeTest.groovy b/src/test/groovy/org/arkecosystem/client/api/two/NodeTest.groovy deleted file mode 100644 index 1809f4c..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/two/NodeTest.groovy +++ /dev/null @@ -1,33 +0,0 @@ -package org.arkecosystem.client.api.two - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class NodeTest extends Specification { - def "status"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('node').status() - then: - actual.success == true - } - - def "syncing"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('node').syncing() - then: - actual.success == true - } - - def "configuration"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('node').configuration() - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/two/PeersTest.groovy b/src/test/groovy/org/arkecosystem/client/api/two/PeersTest.groovy deleted file mode 100644 index 3fa1c3d..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/two/PeersTest.groovy +++ /dev/null @@ -1,24 +0,0 @@ -package org.arkecosystem.client.api.two - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class PeersTest extends Specification { - def "all"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('peers').all() - then: - actual.success == true - } - - def "show"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('peers').show("dummy") - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/two/TransactionsTest.groovy b/src/test/groovy/org/arkecosystem/client/api/two/TransactionsTest.groovy deleted file mode 100644 index 4e6a9bd..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/two/TransactionsTest.groovy +++ /dev/null @@ -1,69 +0,0 @@ -package org.arkecosystem.client.api.two - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class TransactionsTest extends Specification { - def "all"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('transactions').all() - then: - actual.success == true - } - - // def "create"() { - // setup: - // def connection = MockHelper.connection(2) - // when: - // def actual = connection.api('transactions').create() - // then: - // actual.success == true - // } - - def "show"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('transactions').show("dummy") - then: - actual.success == true - } - - def "allUnconfirmed"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('transactions').allUnconfirmed() - then: - actual.success == true - } - - def "showUnconfirmed"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('transactions').showUnconfirmed("dummy") - then: - actual.success == true - } - - def "search"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('transactions').search() - then: - actual.success == true - } - - def "types"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('transactions').types() - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/two/VotesTest.groovy b/src/test/groovy/org/arkecosystem/client/api/two/VotesTest.groovy deleted file mode 100644 index 6e977b1..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/two/VotesTest.groovy +++ /dev/null @@ -1,24 +0,0 @@ -package org.arkecosystem.client.api.two - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class VotesTest extends Specification { - def "all"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('votes').all() - then: - actual.success == true - } - - def "show"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('votes').show("dummy") - then: - actual.success == true - } -} diff --git a/src/test/groovy/org/arkecosystem/client/api/two/WalletsTest.groovy b/src/test/groovy/org/arkecosystem/client/api/two/WalletsTest.groovy deleted file mode 100644 index 7b3cfdb..0000000 --- a/src/test/groovy/org/arkecosystem/client/api/two/WalletsTest.groovy +++ /dev/null @@ -1,78 +0,0 @@ -package org.arkecosystem.client.api.two - -import spock.lang.Specification -import org.arkecosystem.client.MockHelper - -class WalletsTest extends Specification { - def "all"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('wallets').all() - then: - actual.success == true - } - - def "show"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('wallets').show("dummy") - then: - actual.success == true - } - - def "transactions"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('wallets').transactions("dummy") - then: - actual.success == true - } - - def "sentTransactions"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('wallets').sentTransactions("dummy") - then: - actual.success == true - } - - def "receivedTransactions"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('wallets').receivedTransactions("dummy") - then: - actual.success == true - } - - def "votes"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('wallets').votes("dummy") - then: - actual.success == true - } - - def "search"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('wallets').search() - then: - actual.success == true - } - - def "top"() { - setup: - def connection = MockHelper.connection(2) - when: - def actual = connection.api('wallets').top() - then: - actual.success == true - } -} diff --git a/src/test/java/org/arkecosystem/client/ConnectionManagerTest.java b/src/test/java/org/arkecosystem/client/ConnectionManagerTest.java new file mode 100644 index 0000000..2a1eaad --- /dev/null +++ b/src/test/java/org/arkecosystem/client/ConnectionManagerTest.java @@ -0,0 +1,88 @@ +package org.arkecosystem.client; + +import org.arkecosystem.client.api.one.One; +import org.arkecosystem.client.api.two.Two; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; + +import static junit.framework.TestCase.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ConnectionManagerTest { + + @Test + public void connect() { + HashMap map = new HashMap<>(); + map.put("host", "dummy"); + map.put("version", 1); + + ConnectionManager manager = new ConnectionManager(); + manager.connect(map); + assertEquals(1, manager.getConnections().size()); + } + + @Test + public void disconnect() { + HashMap map = new HashMap<>(); + map.put("host", "dummy"); + map.put("version", 1); + + ConnectionManager manager = new ConnectionManager(); + manager.connect(map); + assertEquals(1, manager.getConnections().size()); + manager.disconnect(); + assertEquals(0, manager.getConnections().size()); + } + + public void connection() { + HashMap map = new HashMap<>(); + map.put("host", "dummy"); + map.put("version", 1); + + ConnectionManager manager = new ConnectionManager(); + manager.connect(map); + Connection connection = manager.connection("main"); + assertNotNull(connection); + assertEquals(One.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"); + map.put("version", 1); + + Connection connection1 = manager.connect(map); + assertNotNull(connection1); + + map = new HashMap<>(); + map.put("host", "dummy"); + map.put("version", 2); + + 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/MockHelper.java b/src/test/java/org/arkecosystem/client/MockHelper.java new file mode 100644 index 0000000..5a28354 --- /dev/null +++ b/src/test/java/org/arkecosystem/client/MockHelper.java @@ -0,0 +1,31 @@ +package org.arkecosystem.client; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import org.arkecosystem.client.api.AbstractAPI; + +import java.util.HashMap; + +public class MockHelper { + public static Connection connection(int version) { + MockWebServer mockServer = new MockWebServer(); + + HashMap map = new HashMap<>(); + map.put("host", mockServer.url("/").toString()); + map.put("version", version); + Connection connection = new Connection(map); + + MockResponse mockedResponse = new MockResponse(); + mockedResponse.setResponseCode(200); + mockedResponse.setBody("{\"success\":true}"); + + mockServer.enqueue(mockedResponse); + + return connection; + } + + public static Connection connection() { + return (Connection) MockHelper.connection(1); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/one/AccountsTest.java b/src/test/java/org/arkecosystem/client/api/one/AccountsTest.java new file mode 100644 index 0000000..e2d268c --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/one/AccountsTest.java @@ -0,0 +1,71 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class AccountsTest { + + @Test + public void all() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().accounts.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void show() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().accounts.show("dummy"); + assertTrue((boolean) actual.get("success")); + } + + + @Test + public void count() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().accounts.count(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void delegates() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().accounts.delegates("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void fee() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().accounts.fee(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void balance() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().accounts.balance("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void publicKey() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().accounts.publicKey("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void top() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().accounts.top(); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/one/BlocksTest.java b/src/test/java/org/arkecosystem/client/api/one/BlocksTest.java new file mode 100644 index 0000000..c4ad4be --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/one/BlocksTest.java @@ -0,0 +1,91 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class BlocksTest { + + @Test + public void all() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().blocks.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void show() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().blocks.show("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void epoch() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().blocks.epoch(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void fee() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().blocks.fee(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void fees() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().blocks.fees(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void height() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().blocks.height(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void milestone() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().blocks.milestone(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void nethash() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().blocks.nethash(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void reward() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().blocks.reward(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void status() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().blocks.status(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void supply() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().blocks.supply(); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/one/DelegatesTest.java b/src/test/java/org/arkecosystem/client/api/one/DelegatesTest.java new file mode 100644 index 0000000..ab33313 --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/one/DelegatesTest.java @@ -0,0 +1,73 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.HashMap; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class DelegatesTest { + + @Test + public void all() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().delegates.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void show() throws IOException { + Connection connection = MockHelper.connection(); + HashMap map = new HashMap<>(); + map.put("username", "dummy"); + LinkedTreeMap actual = connection.api().delegates.show(map); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void count() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().delegates.count(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void fee() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().delegates.fee(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void forgedByAccount() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().delegates.forgedByAccount("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void search() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().delegates.search("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void voters() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().delegates.voters("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void nextForgers() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().delegates.nextForgers(); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/one/LoaderTest.java b/src/test/java/org/arkecosystem/client/api/one/LoaderTest.java new file mode 100644 index 0000000..e4fec64 --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/one/LoaderTest.java @@ -0,0 +1,35 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class LoaderTest { + + @Test + public void status() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().loader.status(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void sync() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().loader.sync(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void autoconfigure() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().loader.autoconfigure(); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/one/PeersTest.java b/src/test/java/org/arkecosystem/client/api/one/PeersTest.java new file mode 100644 index 0000000..3be19d5 --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/one/PeersTest.java @@ -0,0 +1,35 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PeersTest { + + @Test + public void all() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().peers.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void show() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().peers.show("ip", 1234); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void version() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().peers.version(); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/one/SignaturesTest.java b/src/test/java/org/arkecosystem/client/api/one/SignaturesTest.java new file mode 100644 index 0000000..4e21b64 --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/one/SignaturesTest.java @@ -0,0 +1,21 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SignaturesTest { + + @Test + public void fee() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().signatures.fee(); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/one/TransactionsTest.java b/src/test/java/org/arkecosystem/client/api/one/TransactionsTest.java new file mode 100644 index 0000000..cdb3193 --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/one/TransactionsTest.java @@ -0,0 +1,28 @@ +package org.arkecosystem.client.api.one; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class TransactionsTest { + + @Test + public void all() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().transactions.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + public void show() throws IOException { + Connection connection = MockHelper.connection(); + LinkedTreeMap actual = connection.api().transactions.show("038716f2d525f2f1a4f02f85b7e51c7cf46420c1505ffceee7495b5271a205ad"); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/two/BlocksTest.java b/src/test/java/org/arkecosystem/client/api/two/BlocksTest.java new file mode 100644 index 0000000..d1b01ab --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/two/BlocksTest.java @@ -0,0 +1,43 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.HashMap; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class BlocksTest { + + @Test + void all() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().blocks.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + void show() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().blocks.show("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + void transactions() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().blocks.transactions("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + void search() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().blocks.search(new HashMap<>()); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/two/DelegatesTest.java b/src/test/java/org/arkecosystem/client/api/two/DelegatesTest.java new file mode 100644 index 0000000..efbaa67 --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/two/DelegatesTest.java @@ -0,0 +1,42 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class DelegatesTest { + + @Test + void all() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().delegates.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + void show() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().delegates.show("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + void blocks() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().delegates.blocks("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + void voters() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().delegates.voters("dummy"); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/two/NodeTest.java b/src/test/java/org/arkecosystem/client/api/two/NodeTest.java new file mode 100644 index 0000000..18ae07f --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/two/NodeTest.java @@ -0,0 +1,35 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class NodeTest { + + @Test + void status() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().node.status(); + assertTrue((boolean) actual.get("success")); + } + + @Test + void syncing() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().node.syncing(); + assertTrue((boolean) actual.get("success")); + } + + @Test + void configuration() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().node.configuration(); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/two/PeersTest.java b/src/test/java/org/arkecosystem/client/api/two/PeersTest.java new file mode 100644 index 0000000..3635f43 --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/two/PeersTest.java @@ -0,0 +1,28 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PeersTest { + + @Test + void all() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().peers.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + void show() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().peers.show("dummy"); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/two/TransactionsTest.java b/src/test/java/org/arkecosystem/client/api/two/TransactionsTest.java new file mode 100644 index 0000000..8213d6b --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/two/TransactionsTest.java @@ -0,0 +1,64 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.HashMap; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class TransactionsTest { + + @Test + void all() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().transactions.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + void create() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().transactions.create(new HashMap<>()); + assertTrue((boolean) actual.get("success")); + } + + @Test + void show() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().transactions.show("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + void allUnconfirmed() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().transactions.allUnconfirmed(); + assertTrue((boolean) actual.get("success")); + } + + @Test + void showUnconfirmed() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().transactions.showUnconfirmed("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + void search() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().transactions.search(new HashMap<>()); + assertTrue((boolean) actual.get("success")); + } + + @Test + void types() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().transactions.types(); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/two/VotesTest.java b/src/test/java/org/arkecosystem/client/api/two/VotesTest.java new file mode 100644 index 0000000..8266baf --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/two/VotesTest.java @@ -0,0 +1,28 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class VotesTest { + + @Test + void all() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().votes.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + void show() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().votes.show("dummy"); + assertTrue((boolean) actual.get("success")); + } + +} diff --git a/src/test/java/org/arkecosystem/client/api/two/WalletsTest.java b/src/test/java/org/arkecosystem/client/api/two/WalletsTest.java new file mode 100644 index 0000000..1ca2b10 --- /dev/null +++ b/src/test/java/org/arkecosystem/client/api/two/WalletsTest.java @@ -0,0 +1,71 @@ +package org.arkecosystem.client.api.two; + +import com.google.gson.internal.LinkedTreeMap; +import org.arkecosystem.client.Connection; +import org.arkecosystem.client.MockHelper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.HashMap; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class WalletsTest { + + @Test + void all() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().wallets.all(); + assertTrue((boolean) actual.get("success")); + } + + @Test + void show() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().wallets.show("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + void transactions() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().wallets.transactions("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + void sentTransactions() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().wallets.sentTransactions("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + void receivedTransactions() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().wallets.receivedTransactions("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + void votes() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().wallets.votes("dummy"); + assertTrue((boolean) actual.get("success")); + } + + @Test + void search() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().wallets.search(new HashMap<>()); + assertTrue((boolean) actual.get("success")); + } + + @Test + void top() throws IOException { + Connection connection = MockHelper.connection(2); + LinkedTreeMap actual = connection.api().wallets.top(); + assertTrue((boolean) actual.get("success")); + } + +}