use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.
the class MetadataTransactionServiceTest method shouldNotCreateMosaicMetadataTransactionFactoryWhenBug.
@Test
public void shouldNotCreateMosaicMetadataTransactionFactoryWhenBug() {
BigInteger metadataKey = BigInteger.valueOf(10);
String newValue = "the new Message";
MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetId(mosaicId).metadataType(MetadataType.MOSAIC);
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.createMosaicMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, mosaicId).toFuture().get()));
Assertions.assertEquals(expectedException, exception);
Mockito.verify(metadataRepositoryMock).search(criteria);
}
use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.
the class MetadataTransactionServiceTest method shouldNotCreateNamespaceMetadataTransactionFactoryWhenAnyOtherRemoteException.
@Test
void shouldNotCreateNamespaceMetadataTransactionFactoryWhenAnyOtherRemoteException() {
BigInteger metadataKey = BigInteger.valueOf(10);
String newValue = "the new Message";
RepositoryCallException expectedException = new RepositoryCallException("Some other problem.", 500, null);
MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetId(namespaceId).metadataType(MetadataType.NAMESPACE);
Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.error(expectedException));
RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> ExceptionUtils.propagate(() -> service.createNamespaceMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, namespaceId).toFuture().get()));
Assertions.assertEquals(expectedException, exception);
Mockito.verify(metadataRepositoryMock).search(criteria);
}
use of io.nem.symbol.sdk.api.MetadataSearchCriteria 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));
}
use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.
the class MetadataTransactionServiceTest method shouldNotCreateAccountMetadataTransactionFactoryWhenAnyOtherRemoteException.
@Test
void shouldNotCreateAccountMetadataTransactionFactoryWhenAnyOtherRemoteException() {
BigInteger metadataKey = BigInteger.valueOf(10);
String newValue = "the new Message";
RepositoryCallException expectedException = new RepositoryCallException("Some other problem.", 500, null);
MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetAddress(targetAccount.getAddress()).metadataType(MetadataType.ACCOUNT);
Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.error(expectedException));
RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> ExceptionUtils.propagate(() -> service.createAccountMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress).toFuture().get()));
Assertions.assertEquals(expectedException, exception);
Mockito.verify(metadataRepositoryMock).search(Mockito.eq(criteria));
}
use of io.nem.symbol.sdk.api.MetadataSearchCriteria 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));
}
Aggregations