Search in sources :

Example 21 with MetadataSearchCriteria

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

the class NamespaceMetadataServiceIntegrationTest method assertMetadata.

private void assertMetadata(NamespaceId targetNamespaceId, BigInteger key, String value, MetadataRepository metadataRepository, Account signerAccount) {
    MetadataSearchCriteria criteria = new MetadataSearchCriteria().targetId(targetNamespaceId).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 22 with MetadataSearchCriteria

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

the class MetadataTransactionServiceTest method shouldNotCreateNamespaceMetadataTransactionFactoryWhenBug.

@Test
public void shouldNotCreateNamespaceMetadataTransactionFactoryWhenBug() {
    BigInteger metadataKey = BigInteger.valueOf(10);
    String newValue = "the new Message";
    MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetId(namespaceId).metadataType(MetadataType.NAMESPACE);
    IllegalArgumentException expectedException = new IllegalArgumentException("Some unexpected error");
    Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.error(expectedException));
    IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> ExceptionUtils.propagate(() -> service.createNamespaceMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, namespaceId).toFuture().get()));
    Assertions.assertEquals(expectedException, exception);
    Mockito.verify(metadataRepositoryMock).search(criteria);
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 23 with MetadataSearchCriteria

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

the class MetadataTransactionServiceTest method shouldCreateNamespaceMetadataTransactionFactory.

@Test
void shouldCreateNamespaceMetadataTransactionFactory() 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.NAMESPACE, StringEncoder.getBytes(oldValue), namespaceId.getIdAsHex());
    MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetId(namespaceId).metadataType(MetadataType.NAMESPACE);
    Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.just(new Page<>(Collections.singletonList(metadata))));
    NamespaceMetadataTransactionFactory result = service.createNamespaceMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, namespaceId).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(namespaceId.getId(), result.getTargetNamespaceId().getId());
    Mockito.verify(metadataRepositoryMock).search(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) NamespaceMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransactionFactory) Test(org.junit.jupiter.api.Test)

Example 24 with MetadataSearchCriteria

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

the class MetadataTransactionServiceTest method shouldCreateMosaicMetadataTransactionFactoryUsingAlias.

@Test
void shouldCreateMosaicMetadataTransactionFactoryUsingAlias() 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, mosaicAlias).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(mosaicAlias, result.getTargetMosaicId());
    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 25 with MetadataSearchCriteria

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

the class MetadataTransactionServiceTest method shouldCreateNamespaceMetadataTransactionFactoryWhenNotFound.

@Test
void shouldCreateNamespaceMetadataTransactionFactoryWhenNotFound() throws Exception {
    BigInteger metadataKey = BigInteger.valueOf(10);
    String newValue = "the new Message";
    MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetId(namespaceId).metadataType(MetadataType.NAMESPACE);
    Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.just(new Page<>(Collections.emptyList())));
    NamespaceMetadataTransactionFactory result = service.createNamespaceMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, namespaceId).toFuture().get();
    Assertions.assertEquals(metadataKey, result.getScopedMetadataKey());
    Assertions.assertArrayEquals(StringEncoder.getBytes(newValue), result.getValue());
    Assertions.assertEquals(StringEncoder.getBytes(newValue).length, result.getValueSizeDelta());
    Assertions.assertEquals(targetAccount.getAddress(), result.getTargetAddress());
    Assertions.assertEquals(namespaceId.getId(), result.getTargetNamespaceId().getId());
    Mockito.verify(metadataRepositoryMock).search(criteria);
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) BigInteger(java.math.BigInteger) Page(io.nem.symbol.sdk.api.Page) NamespaceMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransactionFactory) Test(org.junit.jupiter.api.Test)

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