Update ClientTests.java

This commit is contained in:
Xiaomin Zhu 2020-03-04 02:54:43 +08:00
parent e332bb0866
commit 161018f40c

View File

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