Search in sources :

Example 16 with MetadataSearchCriteria

use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.

the class MetadataRepositoryOkHttpImplTest method search.

@Test
public void search() throws Exception {
    Address address = Address.generateRandom(networkType);
    MetadataPage dto = getMetadataEntriesDTO();
    mockRemoteCall(dto);
    List<Metadata> resultList = repository.search(new MetadataSearchCriteria().sourceAddress(address)).toFuture().get().getData();
    assertMetadataList(dto, resultList);
}
Also used : MetadataPage(io.nem.symbol.sdk.openapi.okhttp_gson.model.MetadataPage) MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) Test(org.junit.jupiter.api.Test)

Example 17 with MetadataSearchCriteria

use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.

the class MosaicMetadataIntegrationTest method addMetadataToMosaic.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void addMetadataToMosaic(RepositoryType type) {
    MosaicId targetMosaicId = createMosaic(type);
    NamespaceId alias = setMosaicAlias(type, targetMosaicId, "mosaicalias" + targetMosaicId.getIdAsHex().toLowerCase());
    String message = "This is the message in the mosaic!";
    BigInteger key = BigInteger.TEN;
    MosaicMetadataTransaction transaction = MosaicMetadataTransactionFactory.create(getNetworkType(), getDeadline(), testAccount.getAddress(), alias, key, StringEncoder.getBytes(message)).maxFee(maxFee).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(transaction.toAggregate(testAccount.getPublicAccount()))).maxFee(maxFee).build();
    AggregateTransaction announceCorrectly = announceAndValidate(type, testAccount, aggregateTransaction);
    Assertions.assertEquals(aggregateTransaction.getType(), announceCorrectly.getType());
    Assertions.assertEquals(testAccount.getPublicAccount(), announceCorrectly.getSigner().get());
    Assertions.assertEquals(1, announceCorrectly.getInnerTransactions().size());
    Assertions.assertEquals(transaction.getType(), announceCorrectly.getInnerTransactions().get(0).getType());
    MosaicMetadataTransaction processedTransaction = (MosaicMetadataTransaction) announceCorrectly.getInnerTransactions().get(0);
    Assertions.assertEquals(transaction.getTargetMosaicId(), processedTransaction.getTargetMosaicId());
    Assertions.assertEquals(transaction.getValueSizeDelta(), processedTransaction.getValueSizeDelta());
    Assertions.assertEquals(transaction.getScopedMetadataKey(), processedTransaction.getScopedMetadataKey());
    System.out.println(targetMosaicId.getIdAsHex());
    System.out.println(key);
    sleep(5000);
    List<Metadata> metadata = get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().targetId(targetMosaicId).metadataType(MetadataType.MOSAIC))).getData();
    assertMetadata(targetMosaicId, transaction, metadata);
    assertMetadata(targetMosaicId, transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().targetId(targetMosaicId).metadataType(MetadataType.MOSAIC).scopedMetadataKey(key))).getData());
    assertMetadata(targetMosaicId, transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().sourceAddress(testAccount.getAddress()).targetId(targetMosaicId).metadataType(MetadataType.MOSAIC).scopedMetadataKey(key))).getData());
    assertMetadata(targetMosaicId, transaction, metadata);
    Assertions.assertArrayEquals(StringEncoder.getBytes(message), processedTransaction.getValue());
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with MetadataSearchCriteria

use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.

the class AccountMetadataServiceIntegrationTest method assertMetadata.

private void assertMetadata(BigInteger key, String value, MetadataRepository metadataRepository) {
    MetadataSearchCriteria criteria = new MetadataSearchCriteria().scopedMetadataKey(key).sourceAddress(signerAccount.getAddress());
    Metadata originalMetadata = get(metadataRepository.search(criteria)).getData().get(0);
    Assertions.assertEquals(value, originalMetadata.getValue());
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) Metadata(io.nem.symbol.sdk.model.metadata.Metadata)

Example 19 with MetadataSearchCriteria

use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.

the class MetadataRepositoryVertxImplTest method search.

@Test
public void search() throws Exception {
    Address address = Address.generateRandom(networkType);
    MetadataPage dto = getMetadataEntriesDTO();
    mockRemoteCall(dto);
    List<Metadata> resultList = repository.search(new MetadataSearchCriteria().sourceAddress(address)).toFuture().get().getData();
    assertMetadataList(dto, resultList);
}
Also used : MetadataPage(io.nem.symbol.sdk.openapi.vertx.model.MetadataPage) MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) Test(org.junit.jupiter.api.Test)

Example 20 with MetadataSearchCriteria

use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.

the class MosaicMetadataServiceIntegrationTest method assertMetadata.

private void assertMetadata(MosaicId targetMosaicId, BigInteger key, String value, MetadataRepository metadataRepository, Account signerAccount, Account targetAccount) {
    MetadataSearchCriteria criteria = new MetadataSearchCriteria().targetId(targetMosaicId).targetAddress(targetAccount.getAddress()).scopedMetadataKey(key).sourceAddress(signerAccount.getAddress());
    Metadata originalMetadata = get(metadataRepository.search(criteria)).getData().get(0);
    Assertions.assertEquals(value, originalMetadata.getValue());
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) Metadata(io.nem.symbol.sdk.model.metadata.Metadata)

Aggregations

MetadataSearchCriteria (io.nem.symbol.sdk.api.MetadataSearchCriteria)25 BigInteger (java.math.BigInteger)19 Test (org.junit.jupiter.api.Test)15 Metadata (io.nem.symbol.sdk.model.metadata.Metadata)14 Page (io.nem.symbol.sdk.api.Page)8 Address (io.nem.symbol.sdk.model.account.Address)5 MosaicMetadataTransactionFactory (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransactionFactory)4 NamespaceMetadataTransactionFactory (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransactionFactory)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 MetadataRepository (io.nem.symbol.sdk.api.MetadataRepository)3 RepositoryCallException (io.nem.symbol.sdk.api.RepositoryCallException)3 MetadataType (io.nem.symbol.sdk.model.metadata.MetadataType)3 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)3 AccountMetadataTransactionFactory (io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory)3 ConvertUtils (io.nem.symbol.core.utils.ConvertUtils)2 MetadataTransactionService (io.nem.symbol.sdk.api.MetadataTransactionService)2 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)2 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)2 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)2