Search in sources :

Example 1 with ListenerSubscribeMessage

use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.

the class ListenerOkHttp method subscribeTo.

protected void subscribeTo(String channel) {
    final ListenerSubscribeMessage subscribeMessage = new ListenerSubscribeMessage(this.getUid(), channel);
    this.webSocket.send(getJsonHelper().print(subscribeMessage));
}
Also used : ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)

Example 2 with ListenerSubscribeMessage

use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.

the class ListenerOkHttpTest method confirmAndGetError.

@Test
public void confirmAndGetError() throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, JsonObject.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), networkType);
    String channelName = ListenerChannel.CONFIRMED_ADDED.toString();
    List<Transaction> transactions = new ArrayList<>();
    listener.confirmed(address).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, channelName + "/" + address.plain());
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test)

Example 3 with ListenerSubscribeMessage

use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.

the class ListenerOkHttpTest method aggregateBondedAddedHash.

@Test
public void aggregateBondedAddedHash() throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, JsonObject.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), networkType);
    String channelName = ListenerChannel.AGGREGATE_BONDED_ADDED.toString();
    List<Transaction> transactions = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    listener.aggregateBondedAddedOrError(address, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
    String topic = channelName + "/" + address.plain();
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, topic)));
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + address.plain())));
    handle(transactionInfoDtoJsonObject, topic);
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(0, exceptions.size());
    Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test)

Example 4 with ListenerSubscribeMessage

use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.

the class ListenerOkHttpTest method shouldFilterOutHandleStatus.

@Test
public void shouldFilterOutHandleStatus() throws InterruptedException, ExecutionException, TimeoutException {
    Account account1 = Account.generateNewAccount(networkType);
    Account account2 = Account.generateNewAccount(networkType);
    AtomicReference<TransactionStatusError> reference = new AtomicReference<>();
    simulateWebSocketStartup();
    Assertions.assertNotNull(listener.status(account2.getAddress()).subscribe(reference::set));
    Map<String, Object> message = new HashMap<>();
    message.put("hash", "1234hash");
    message.put("address", account1.getAddress().encoded());
    message.put("code", "some error");
    message.put("deadline", 5555);
    handle(message, "status/" + account1.getAddress().plain());
    Assertions.assertNull(reference.get());
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + account2.getAddress().plain())));
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) TransactionStatusError(io.nem.symbol.sdk.model.transaction.TransactionStatusError) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) JsonObject(com.google.gson.JsonObject) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test)

Example 5 with ListenerSubscribeMessage

use of io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage in project nem2-sdk-java by nemtech.

the class ListenerOkHttpTest method confirmedUsingHashUsingAlias.

@Test
public void confirmedUsingHashUsingAlias() throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, JsonObject.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), networkType);
    NamespaceId alias = NamespaceId.createFromId(BigInteger.TEN);
    String channelName = ListenerChannel.CONFIRMED_ADDED.toString();
    List<Transaction> transactions = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    listener.confirmedOrError(alias, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, channelName + "/" + alias.plain());
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(0, exceptions.size());
    Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + alias.plain())));
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + alias.plain())));
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test)

Aggregations

ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)24 ArrayList (java.util.ArrayList)18 Address (io.nem.symbol.sdk.model.account.Address)15 Test (org.junit.jupiter.api.Test)14 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 JsonObject (com.google.gson.JsonObject)10 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)10 HashMap (java.util.HashMap)10 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)9 ValueSource (org.junit.jupiter.params.provider.ValueSource)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 Observable (io.reactivex.Observable)7 TransactionInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO)6 TransactionInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO)5 TransactionMetaDTO (io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO)5 Account (io.nem.symbol.sdk.model.account.Account)4 TransactionStatusError (io.nem.symbol.sdk.model.transaction.TransactionStatusError)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Map (java.util.Map)3