Update ClientTests.java
This commit is contained in:
parent
e332bb0866
commit
161018f40c
@ -1,7 +1,7 @@
|
|||||||
package bdledger.api;
|
package bdledger.api;
|
||||||
|
|
||||||
import bdchain.api.grpc.txledger.GetLedgersResponse;
|
import bdledger.api.grpc.ledger.GetLedgersResponse;
|
||||||
import bdchain.api.grpc.common.TransactionType;
|
import bdledger.api.grpc.common.TransactionType;
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
import org.junit.jupiter.api.AfterAll;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
@ -14,35 +14,35 @@ import java.util.stream.IntStream;
|
|||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@DisplayName("Transaction Ledger tests")
|
@DisplayName("Transaction Ledger tests")
|
||||||
class TransactionLedgerClientTests {
|
class ClientTests {
|
||||||
|
|
||||||
private static final String ledger = "test";
|
private static final String ledger = "test";
|
||||||
private String[] ledgers = new String[] {"first", "second", "third"};
|
private String[] ledgers = new String[]{"first", "second", "third"};
|
||||||
|
|
||||||
private static TransactionLedgerClient tlClient;
|
private static Client client;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void initAll() {
|
static void initAll() {
|
||||||
tlClient = new TransactionLedgerClient("localhost", 10000);
|
client = new Client("localhost", 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("ClientVersion#1")
|
@DisplayName("ClientVersion#1")
|
||||||
void clientVersion1() throws InterruptedException, ExecutionException {
|
void clientVersion1() throws InterruptedException, ExecutionException {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"TxLedgerGo/v0.0.1alpha/darwin/go1.11", tlClient.clientVersion().get().getVersion());
|
"TxLedgerGo/v0.0.1alpha/darwin/go1.11", client.clientVersion().get().getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("CreateLedger#1")
|
@DisplayName("CreateLedger#1")
|
||||||
void createLedger1() throws InterruptedException, ExecutionException {
|
void createLedger1() throws InterruptedException, ExecutionException {
|
||||||
assertTrue(tlClient.createLedger(ledger).get().getOk());
|
assertTrue(client.createLedger(ledger).get().getOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("CreateLedger#2")
|
@DisplayName("CreateLedger#2")
|
||||||
void createLedger2() {
|
void createLedger2() {
|
||||||
Throwable e = assertThrows(Exception.class, () -> tlClient.createLedger("").get());
|
Throwable e = assertThrows(Exception.class, () -> client.createLedger("").get());
|
||||||
Status s = Status.fromThrowable(e);
|
Status s = Status.fromThrowable(e);
|
||||||
assertEquals(Status.Code.INVALID_ARGUMENT, s.getCode());
|
assertEquals(Status.Code.INVALID_ARGUMENT, s.getCode());
|
||||||
assertEquals("name must not be empty", s.getDescription());
|
assertEquals("name must not be empty", s.getDescription());
|
||||||
@ -51,9 +51,9 @@ class TransactionLedgerClientTests {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("GetLedgers#1")
|
@DisplayName("GetLedgers#1")
|
||||||
void getLedgers1() throws InterruptedException, ExecutionException {
|
void getLedgers1() throws InterruptedException, ExecutionException {
|
||||||
GetLedgersResponse r = tlClient.getLedgers().get();
|
GetLedgersResponse r = client.getLedgers().get();
|
||||||
assertEquals(3, r.getLedgersCount());
|
assertEquals(3, r.getLedgersCount());
|
||||||
String[] expected = new String[] {"first", "second", "third"};
|
String[] expected = new String[]{"first", "second", "third"};
|
||||||
assertAll(
|
assertAll(
|
||||||
IntStream.range(0, 3).boxed().map(i -> () -> assertEquals(ledgers[i], r.getLedgers(i))));
|
IntStream.range(0, 3).boxed().map(i -> () -> assertEquals(ledgers[i], r.getLedgers(i))));
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ class TransactionLedgerClientTests {
|
|||||||
void sendTransaction1() throws InterruptedException, ExecutionException {
|
void sendTransaction1() throws InterruptedException, ExecutionException {
|
||||||
String hash =
|
String hash =
|
||||||
Utils.byteArrayToHexString(
|
Utils.byteArrayToHexString(
|
||||||
tlClient
|
client
|
||||||
.sendTransaction(
|
.sendTransaction(
|
||||||
ledger,
|
ledger,
|
||||||
TransactionType.MESSAGE,
|
TransactionType.MESSAGE,
|
||||||
@ -83,7 +83,7 @@ class TransactionLedgerClientTests {
|
|||||||
assertThrows(
|
assertThrows(
|
||||||
Exception.class,
|
Exception.class,
|
||||||
() ->
|
() ->
|
||||||
tlClient
|
client
|
||||||
.sendTransaction(ledger, TransactionType.MESSAGE, null, "50bada55", null)
|
.sendTransaction(ledger, TransactionType.MESSAGE, null, "50bada55", null)
|
||||||
.get());
|
.get());
|
||||||
Status s = Status.fromThrowable(e);
|
Status s = Status.fromThrowable(e);
|
||||||
@ -93,6 +93,6 @@ class TransactionLedgerClientTests {
|
|||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
static void teadDwonAll() throws InterruptedException {
|
static void teadDwonAll() throws InterruptedException {
|
||||||
tlClient.shutdown();
|
client.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user