Search in sources :

Example 6 with Metadata

use of io.nem.symbol.sdk.model.metadata.Metadata in project nem2-sdk-java by nemtech.

the class MetadataRepositoryVertxImplTest method getMetadata.

@Test
public void getMetadata() throws Exception {
    MetadataInfoDTO metadataDTO = getMetadataEntriesDTO().getData().get(0);
    mockRemoteCall(metadataDTO);
    Metadata metadata = repository.getMetadata("abc").toFuture().get();
    assertMetadata(metadataDTO, metadata);
}
Also used : Metadata(io.nem.symbol.sdk.model.metadata.Metadata) MetadataInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.MetadataInfoDTO) Test(org.junit.jupiter.api.Test)

Example 7 with Metadata

use of io.nem.symbol.sdk.model.metadata.Metadata in project nem2-sdk-java by nemtech.

the class MetadataTransactionServiceTest method shouldCreateAccountMetadataTransactionFactory.

@Test
void shouldCreateAccountMetadataTransactionFactory() throws Exception {
    BigInteger metadataKey = BigInteger.valueOf(10);
    String oldValue = "The original Message";
    String newValue = "the new Message";
    Metadata metadata = new Metadata("someId", 1, "compositeHash", sourceAddress, targetAccount.getAddress(), metadataKey, MetadataType.ACCOUNT, StringEncoder.getBytes(oldValue), null);
    MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetAddress(targetAccount.getAddress()).metadataType(MetadataType.ACCOUNT);
    Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.just(new Page<>(Collections.singletonList(metadata))));
    AccountMetadataTransactionFactory result = service.createAccountMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress).toFuture().get();
    Assertions.assertEquals(metadataKey, result.getScopedMetadataKey());
    Assertions.assertNotEquals(oldValue, StringEncoder.getString(result.getValue()));
    Assertions.assertNotEquals(newValue, StringEncoder.getString(result.getValue()));
    Assertions.assertEquals(StringEncoder.getBytes(newValue).length - StringEncoder.getBytes(oldValue).length, result.getValueSizeDelta());
    Assertions.assertEquals(targetAccount.getAddress(), result.getTargetAddress());
    Mockito.verify(metadataRepositoryMock).search(Mockito.eq(criteria));
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) BigInteger(java.math.BigInteger) AccountMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory) Page(io.nem.symbol.sdk.api.Page) Test(org.junit.jupiter.api.Test)

Example 8 with Metadata

use of io.nem.symbol.sdk.model.metadata.Metadata in project nem2-sdk-java by nemtech.

the class MetadataTransactionServiceTest method shouldCreateMosaicMetadataTransactionFactory.

@Test
void shouldCreateMosaicMetadataTransactionFactory() throws Exception {
    BigInteger metadataKey = BigInteger.valueOf(10);
    String oldValue = "The original Message";
    String newValue = "the new Message";
    Metadata metadata = new Metadata("someId", 1, "compositeHash", sourceAddress, targetAccount.getAddress(), metadataKey, MetadataType.MOSAIC, StringEncoder.getBytes(oldValue), mosaicId.getIdAsHex());
    MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetId(mosaicId).metadataType(MetadataType.MOSAIC);
    Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.just(new Page<>(Collections.singletonList(metadata))));
    MosaicMetadataTransactionFactory result = service.createMosaicMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, mosaicId).toFuture().get();
    Assertions.assertEquals(metadataKey, result.getScopedMetadataKey());
    Assertions.assertNotEquals(oldValue, StringEncoder.getString(result.getValue()));
    Assertions.assertNotEquals(newValue, StringEncoder.getString(result.getValue()));
    Assertions.assertEquals(StringEncoder.getBytes(newValue).length - StringEncoder.getBytes(oldValue).length, result.getValueSizeDelta());
    Assertions.assertEquals(targetAccount.getAddress(), result.getTargetAddress());
    Assertions.assertEquals(mosaicId.getId(), result.getTargetMosaicId().getId());
    Mockito.verify(metadataRepositoryMock).search(Mockito.eq(criteria));
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) BigInteger(java.math.BigInteger) Page(io.nem.symbol.sdk.api.Page) MosaicMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransactionFactory) Test(org.junit.jupiter.api.Test)

Example 9 with Metadata

use of io.nem.symbol.sdk.model.metadata.Metadata 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 10 with Metadata

use of io.nem.symbol.sdk.model.metadata.Metadata in project nem2-sdk-java by nemtech.

the class MetadataRepositoryOkHttpImplTest method getMetadata.

@Test
public void getMetadata() throws Exception {
    MetadataInfoDTO metadataDTO = getMetadataEntriesDTO().getData().get(0);
    mockRemoteCall(metadataDTO);
    Metadata metadata = repository.getMetadata("abc").toFuture().get();
    assertMetadata(metadataDTO, metadata);
}
Also used : Metadata(io.nem.symbol.sdk.model.metadata.Metadata) MetadataInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MetadataInfoDTO) Test(org.junit.jupiter.api.Test)

Aggregations

Metadata (io.nem.symbol.sdk.model.metadata.Metadata)19 MetadataSearchCriteria (io.nem.symbol.sdk.api.MetadataSearchCriteria)14 BigInteger (java.math.BigInteger)9 Test (org.junit.jupiter.api.Test)9 Page (io.nem.symbol.sdk.api.Page)5 Address (io.nem.symbol.sdk.model.account.Address)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 MetadataInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.MetadataInfoDTO)3 MetadataRepository (io.nem.symbol.sdk.api.MetadataRepository)2 MetadataType (io.nem.symbol.sdk.model.metadata.MetadataType)2 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)2 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)2 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)2 MosaicMetadataTransactionFactory (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransactionFactory)2 NamespaceMetadataTransactionFactory (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransactionFactory)2 MetadataInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MetadataInfoDTO)2 MetadataPage (io.nem.symbol.sdk.openapi.vertx.model.MetadataPage)2 ConvertUtils (io.nem.symbol.core.utils.ConvertUtils)1 MapperUtils (io.nem.symbol.core.utils.MapperUtils)1