Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,57 @@ on:
- "master"
- "develop"
pull_request:
types: [ready_for_review, synchronize, opened]
types: [ ready_for_review, synchronize, opened ]

jobs:
format:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- name: Merge Conflict finder
uses: olivernybroe/action-conflict-finder@v1.1

- name: Use Java Version 8
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: 8
cache: 'gradle'

- name: Format code
run: gradle format

- name: Commit fixed code
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "style: resolve style guide violations"
branch: ${{ github.head_ref }}

unit:
runs-on: ubuntu-latest
strategy:
matrix:
# test against latest update of each major Java version, as well as specific updates of LTS versions:
java: [ 8, 9, 10, 11, 12, 13 ]
# test against the latest update of each major Java version, as well as specific updates of LTS versions:
java: [ 8, 11, 15, 16 ]

steps:
- uses: actions/checkout@v1
- name: Use Java Version ${{ matrix.java }}
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Install
run: gradle dependencies
- name: Test
run: gradle test && gradle jacocoTestReport
- name: Codecov
run: bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }}
- uses: actions/checkout@v2

- name: Use Java Version ${{ matrix.java }}
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}

- name: Install
run: gradle dependencies

- name: Test
run: gradle test && gradle jacocoTestReport

- name: Codecov
run: bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;
import java.util.Map;

import org.arkecosystem.client.http.Client;

public class Blockchain {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/arkecosystem/client/api/Blocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

import org.arkecosystem.client.http.Client;

public class Blocks implements SupportsParams<Blocks> {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/arkecosystem/client/api/Entities.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.arkecosystem.client.api;

import org.arkecosystem.client.http.Client;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import org.arkecosystem.client.http.Client;

public class Entities implements SupportsParams<Entities> {
public class Entities implements SupportsParams<Entities> {
private final Client client;

private final Map<String, Object> params = new LinkedHashMap<>();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/arkecosystem/client/api/Locks.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public Map<String, Object> searchUnlocked() throws IOException {
return this.client.post("locks/unlocked", params);
}

public Map<String, Object> searchUnlocked(Map<String, Object> parameters)
throws IOException {
public Map<String, Object> searchUnlocked(Map<String, Object> parameters) throws IOException {
return this.client.post("locks/unlocked", parameters);
}
}
1 change: 0 additions & 1 deletion src/main/java/org/arkecosystem/client/api/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.arkecosystem.client.http.Client;

public class Node {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/arkecosystem/client/api/Peers.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

import org.arkecosystem.client.http.Client;

public class Peers implements SupportsParams<Peers> {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/arkecosystem/client/api/Rounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;
import java.util.Map;

import org.arkecosystem.client.http.Client;

public class Rounds {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
public interface SupportsParams<T> {

T param(String name, Object value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.arkecosystem.client.http.Client;

public class Transactions implements SupportsParams<Transactions> {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/arkecosystem/client/api/Votes.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

import org.arkecosystem.client.http.Client;

public class Votes implements SupportsParams<Votes> {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/arkecosystem/client/api/Wallets.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

import org.arkecosystem.client.http.Client;

public class Wallets implements SupportsParams<Wallets> {
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/arkecosystem/client/http/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public Client(String host) {
this.headers = Headers.of(headers);
}

public Map<String, Object> get(String url, Map<String, Object> params)
throws IOException {
public Map<String, Object> get(String url, Map<String, Object> params) throws IOException {
HttpUrl.Builder httpBuilder = HttpUrl.parse(this.host + url).newBuilder();

for (Map.Entry<String, String> entry : DotHelper.toDot(params).entrySet()) {
Expand All @@ -37,8 +36,7 @@ public Map<String, Object> get(String url, Map<String, Object> params)
new Request.Builder().headers(this.headers).url(httpBuilder.build()).build();

Response response = client.newCall(request).execute();
return new Gson()
.fromJson(response.body().string(), Map.class);
return new Gson().fromJson(response.body().string(), Map.class);
}

public Map<String, Object> get(String url) throws IOException {
Expand All @@ -49,8 +47,7 @@ public Map<String, Object> post(String url, Map<String, Object> payload) throws
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(), Map.class);
return new Gson().fromJson(response.body().string(), Map.class);
}

public OkHttpClient getClient() {
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/arkecosystem/client/http/DotHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ public static Map<String, String> toDot(Map<String, Object> params) {
}

@SuppressWarnings("unchecked")
private static Map<String, String> toDot(Map<String, Object> params, Map<String, String> accum, String prepend) {
private static Map<String, String> toDot(
Map<String, Object> params, Map<String, String> accum, String prepend) {
for (Map.Entry<String, Object> entry : params.entrySet()) {
if (entry.getValue() instanceof Map) {
accum.putAll(toDot((Map<String, Object>) entry.getValue(), accum, prepend + entry.getKey() + "."));
accum.putAll(
toDot(
(Map<String, Object>) entry.getValue(),
accum,
prepend + entry.getKey() + "."));
} else if (entry.getValue() instanceof List) {
Map<String, Object> stringObjectMap = listAsMapWithNumericKeys((List<?>) entry.getValue());
Map<String, Object> stringObjectMap =
listAsMapWithNumericKeys((List<?>) entry.getValue());
toDot(stringObjectMap, accum, prepend + entry.getKey() + ".");
} else if (entry.getValue() != null) {
accum.put(prepend + entry.getKey(), entry.getValue().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.io.IOException;
import java.util.Map;

import org.arkecosystem.client.Connection;
import org.arkecosystem.client.MockHelper;
import org.junit.jupiter.api.Test;
Expand Down
13 changes: 4 additions & 9 deletions src/test/java/org/arkecosystem/client/api/BlocksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.io.IOException;
import java.util.Map;

import org.arkecosystem.client.Connection;
import org.arkecosystem.client.MockHelper;
import org.junit.jupiter.api.Test;
Expand All @@ -21,10 +20,8 @@ void all() throws IOException {
@Test
void allWithParams() throws IOException {
Connection connection = MockHelper.connection();
Map<String, Object> actual = connection.api().blocks
.param("page", 1)
.param("limit", 100)
.all();
Map<String, Object> actual =
connection.api().blocks.param("page", 1).param("limit", 100).all();
assertTrue((boolean) actual.get("success"));
}

Expand Down Expand Up @@ -59,10 +56,8 @@ void transactions() throws IOException {
@Test
void transactionsWithParams() throws IOException {
Connection connection = MockHelper.connection();
Map<String, Object> actual = connection.api().blocks
.param("page", 1)
.param("limit", 100)
.transactions("dummy");
Map<String, Object> actual =
connection.api().blocks.param("page", 1).param("limit", 100).transactions("dummy");
assertTrue((boolean) actual.get("success"));
}
}
19 changes: 6 additions & 13 deletions src/test/java/org/arkecosystem/client/api/DelegatesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.arkecosystem.client.Connection;
import org.arkecosystem.client.MockHelper;
import org.junit.jupiter.api.Test;
Expand All @@ -22,10 +21,8 @@ void all() throws IOException {
@Test
void allWithParams() throws IOException {
Connection connection = MockHelper.connection();
Map<String, Object> actual = connection.api().delegates
.param("page", 1)
.param("limit", 100)
.all();
Map<String, Object> actual =
connection.api().delegates.param("page", 1).param("limit", 100).all();
assertTrue((boolean) actual.get("success"));
}

Expand Down Expand Up @@ -53,10 +50,8 @@ void voters() throws IOException {
@Test
void votersWithParams() throws IOException {
Connection connection = MockHelper.connection();
Map<String, Object> actual = connection.api().delegates
.param("page", 1)
.param("limit", 100)
.voters("dummy");
Map<String, Object> actual =
connection.api().delegates.param("page", 1).param("limit", 100).voters("dummy");
assertTrue((boolean) actual.get("success"));
}

Expand All @@ -70,10 +65,8 @@ void search() throws IOException {
@Test
void searchWithParams() throws IOException {
Connection connection = MockHelper.connection();
Map<String, Object> actual = connection.api().delegates
.param("page", 1)
.param("limit", 100)
.search();
Map<String, Object> actual =
connection.api().delegates.param("page", 1).param("limit", 100).search();
assertTrue((boolean) actual.get("success"));
}
}
15 changes: 6 additions & 9 deletions src/test/java/org/arkecosystem/client/api/EntitiesTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.arkecosystem.client.api;

import org.arkecosystem.client.Connection;
import org.arkecosystem.client.MockHelper;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertTrue;
import org.arkecosystem.client.Connection;
import org.arkecosystem.client.MockHelper;
import org.junit.jupiter.api.Test;

public class EntitiesTest {

Expand All @@ -21,10 +20,8 @@ void all() throws IOException {
@Test
void allWithParams() throws IOException {
Connection connection = MockHelper.connection();
Map<String, Object> actual = connection.api().entities
.param("page", 1)
.param("limit", 100)
.all();
Map<String, Object> actual =
connection.api().entities.param("page", 1).param("limit", 100).all();
assertTrue((boolean) actual.get("success"));
}

Expand Down
15 changes: 4 additions & 11 deletions src/test/java/org/arkecosystem/client/api/LocksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.arkecosystem.client.Connection;
import org.arkecosystem.client.MockHelper;
import org.junit.jupiter.api.Test;
Expand All @@ -22,10 +21,8 @@ void all() throws IOException {
@Test
void allWithParams() throws IOException {
Connection connection = MockHelper.connection();
Map<String, Object> actual = connection.api().locks
.param("page", 1)
.param("limit", 100)
.all();
Map<String, Object> actual =
connection.api().locks.param("page", 1).param("limit", 100).all();
assertTrue((boolean) actual.get("success"));
}

Expand All @@ -39,18 +36,14 @@ void show() throws IOException {
@Test
void searchUnlocked() throws IOException {
Connection connection = MockHelper.connection();
Map<String, Object> actual =
connection.api().locks.searchUnlocked(new HashMap<>());
Map<String, Object> actual = connection.api().locks.searchUnlocked(new HashMap<>());
assertTrue((boolean) actual.get("success"));
}

@Test
void searchUnlockedWithParams() throws IOException {
Connection connection = MockHelper.connection();
Map<String, Object> actual =
connection.api().locks
.param("page", 1)
.searchUnlocked();
Map<String, Object> actual = connection.api().locks.param("page", 1).searchUnlocked();
assertTrue((boolean) actual.get("success"));
}
}
1 change: 0 additions & 1 deletion src/test/java/org/arkecosystem/client/api/NodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.io.IOException;
import java.util.Map;

import org.arkecosystem.client.Connection;
import org.arkecosystem.client.MockHelper;
import org.junit.jupiter.api.Test;
Expand Down
Loading