public void setUpDataBase() throws Exception { when(mockPluginDatabaseSystem.openDatabase(any(UUID.class), anyString())) .thenReturn(mockDatabase); when(mockDatabaseFactory.newTableFactory(any(UUID.class), anyString())) .thenReturn(mockFactoryTable); when(mockDatabase.getTable(anyString())).thenReturn(mockDatabaseTable); when(mockDatabaseTable.getEmptyRecord()).thenReturn(mockDatabaseTableRecord); when(mockDatabase.newTransaction()).thenReturn(mockTransaction); subAppResourcesDAO = new SubAppResourcesInstallationNetworkServiceDAO(mockPluginDatabaseSystem); subAppResourcesDAO = new SubAppResourcesInstallationNetworkServiceDAO(mockPluginDatabaseSystem); String path = "path1"; String skinName = "skinName1"; String navigationStructureVersion = "version1"; repository = new Repository(skinName, navigationStructureVersion, path); subAppResourcesDAO.initializeDatabase( UUID.randomUUID(), SubAppResourcesNetworkServiceDatabaseConstants.DATABASE_NAME); skinId = UUID.randomUUID(); subAppResourcesDAO.createRepository(repository, skinId); when(mockDatabase.getTable(anyString())).thenReturn(mockDatabaseTable); mockDatabaseTable.setUUIDFilter( SubAppResourcesNetworkServiceDatabaseConstants.REPOSITORIES_SKIN_ID_COLUMN_NAME, skinId, DatabaseFilterType.EQUAL); mockDatabaseTable.loadToMemory(); when(mockDatabaseTable.getRecords()).thenReturn(databaseTableRecordList); when(databaseTableRecordList.get(anyInt())).thenReturn(mockDatabaseTableRecord); when(mockDatabaseTableRecord.getStringValue(anyString())).thenReturn(anyString()); }
/** * Gets the amount of transaction in ProtocolStatus as Pending Notified from the specified table * * @param transactionType * @return * @throws CantExecuteDatabaseOperationException */ public int getPendingNotifiedTransactions(TransactionTypes transactionType) throws CantExecuteDatabaseOperationException { DatabaseTable databaseTable; if (transactionType == TransactionTypes.OUTGOING) { databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_TABLE_NAME); databaseTable.setStringFilter( BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_PROTOCOL_STATUS_COLUMN_NAME, ProtocolStatus.TO_BE_NOTIFIED.getCode(), DatabaseFilterType.EQUAL); } else { databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_TABLE_NAME); databaseTable.setStringFilter( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_PROTOCOL_STATUS_COLUMN_NAME, ProtocolStatus.TO_BE_NOTIFIED.getCode(), DatabaseFilterType.EQUAL); } try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } /** I return the amount of records. */ return databaseTable.getRecords().size(); }
/** * Gets both incoming and outgoing transactions hash stored in the database * * @return * @throws CantExecuteDatabaseOperationException */ public Set<String> getStoredStransactionsHash() throws CantExecuteDatabaseOperationException { Set<String> transactionsSet = new HashSet<>(); /** Loads and puts in the transactionsSet the list of stored Hashes */ DatabaseTable databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_TABLE_NAME); try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } for (DatabaseTableRecord record : databaseTable.getRecords()) { transactionsSet.add( record.getStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_HASH_COLUMN_NAME)); } /** Loads and puts in the transactionsSet the list of stored Hashes */ databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_TABLE_NAME); try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } for (DatabaseTableRecord record : databaseTable.getRecords()) { transactionsSet.add( record.getStringValue( BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_HASH_COLUMN_NAME)); } return transactionsSet; }
private void setUpMockitoRules() throws Exception { when(mockDatabase.getDatabaseFactory()).thenReturn(mockDatabaseFactory); when(mockDatabaseTable.getEmptyRecord()).thenReturn(mockDatabaseTableRecord); when(mockDatabase.getTable( AssetIssuingTransactionDatabaseConstants.DIGITAL_ASSET_TRANSACTION_TABLE_NAME)) .thenReturn(mockDatabaseTable); when(mockDatabase.getTable( AssetIssuingTransactionDatabaseConstants .DIGITAL_ASSET_TRANSACTION_ASSET_ISSUING_TABLE_NAME)) .thenReturn(mockDatabaseTable2); when(mockDatabaseTable2.getEmptyRecord()).thenReturn(mockDatabaseTableRecord); when(mockDatabaseTable2.getRecords()).thenReturn(records); when(pluginDatabaseSystem.openDatabase( pluginId, AssetIssuingTransactionDatabaseConstants.DIGITAL_ASSET_TRANSACTION_DATABASE)) .thenReturn(mockDatabase); when(deviceUser.getPublicKey()).thenReturn("myPublicKey"); when(deviceUserManager.getLoggedInDeviceUser()).thenReturn(deviceUser); when(actorAssetIssuerManager.getActorAssetIssuer()).thenReturn(actorAssetIssuer); when(eventManager.getNewListener( EventType.INCOMING_ASSET_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER)) .thenReturn(fermatEventListener1); when(eventManager.getNewListener( EventType.INCOMING_ASSET_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER)) .thenReturn(fermatEventListener2); when(eventManager.getNewListener( EventType.INCOMING_ASSET_REVERSED_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER)) .thenReturn(fermatEventListener3); when(eventManager.getNewListener( EventType.INCOMING_ASSET_REVERSED_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER)) .thenReturn(fermatEventListener4); when(pluginFileSystem.createTextFile( this.pluginId, "digital-asset-issuing/publicKey", "name.xml", FilePrivacy.PUBLIC, FileLifeSpan.PERMANENT)) .thenReturn(pluginTextFile); when(bitcoinWalletManager.loadWallet(this.walletPublicKey)).thenReturn(bitcoinWalletWallet); when(bitcoinWalletWallet.getBalance(BalanceType.AVAILABLE)).thenReturn(bitcoinWalletBalance); when(bitcoinWalletBalance.getBalance()).thenReturn(bitcoinWalletAvailableBalance); when(assetVaultManager.getNewAssetVaultCryptoAddress(this.blockchainNetworkType)) .thenReturn(cryptoAddress); // doNothing().when(assetIssuingPluginRoot).issueAssets(digitalAsset, 1, walletPublicKey, // blockchainNetworkType); }
/** * Gets the pending transaction data from the specified table * * @param transactionType * @return */ private List<TransactionProtocolData> getPendingTransactionProtocolData( TransactionTypes transactionType) throws CantExecuteDatabaseOperationException { DatabaseTable databaseTable; String transactionIdColumnName; List<TransactionProtocolData> transactionProtocolDataList = new ArrayList<>(); if (transactionType == TransactionTypes.INCOMING) { databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_TABLE_NAME); databaseTable.setStringFilter( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_PROTOCOL_STATUS_COLUMN_NAME, ProtocolStatus.TO_BE_NOTIFIED.getCode(), DatabaseFilterType.EQUAL); transactionIdColumnName = BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_TRX_ID_COLUMN_NAME; } else { databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_TABLE_NAME); databaseTable.setStringFilter( BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_PROTOCOL_STATUS_COLUMN_NAME, ProtocolStatus.TO_BE_NOTIFIED.getCode(), DatabaseFilterType.EQUAL); transactionIdColumnName = BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_TRX_ID_COLUMN_NAME; } try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } /** Will form the TransactionProtocolData object from the records */ for (DatabaseTableRecord record : databaseTable.getRecords()) { TransactionProtocolData transactionProtocolData = new TransactionProtocolData(); transactionProtocolData.setTransactionId( UUID.fromString(record.getStringValue(transactionIdColumnName))); transactionProtocolData.setCryptoTransaction( getCryptoTransactionFromRecord(transactionType, record)); transactionProtocolData.setAction(Action.APPLY); transactionProtocolData.setTimestamp( System.currentTimeMillis() / 1000L); // todo I need to convert the stored saved date to long transactionProtocolDataList.add(transactionProtocolData); } return transactionProtocolDataList; }
public final List<DeveloperDatabaseTableRecord> getDatabaseTableContent( final DeveloperObjectFactory developerObjectFactory, final DeveloperDatabaseTable developerDatabaseTable) { final List<DeveloperDatabaseTableRecord> returnedRecords = new ArrayList<>(); final DatabaseTable selectedTable = database.getTable(developerDatabaseTable.getName()); try { selectedTable.loadToMemory(); final List<DatabaseTableRecord> records = selectedTable.getRecords(); for (final DatabaseTableRecord row : records) { final List<String> developerRow = new ArrayList<>(); for (DatabaseRecord field : row.getValues()) developerRow.add(field.getValue()); returnedRecords.add( developerObjectFactory.getNewDeveloperDatabaseTableRecord(developerRow)); } } catch (CantLoadTableToMemoryException cantLoadTableToMemory) { return returnedRecords; } catch (Exception e) { return returnedRecords; } return returnedRecords; }
/** * Saves and outgoing transaction into the database * * @param hash * @param cryptoStatus * @param blockDepth * @param addressTo * @param addressFrom * @param value * @param op_Return * @param protocolStatus * @throws CantExecuteDatabaseOperationException */ public void saveNewOutgoingTransaction( String hash, CryptoStatus cryptoStatus, int blockDepth, CryptoAddress addressTo, CryptoAddress addressFrom, long value, String op_Return, ProtocolStatus protocolStatus) throws CantExecuteDatabaseOperationException { DatabaseTable databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_TABLE_NAME); DatabaseTableRecord record = databaseTable.getEmptyRecord(); /** generates the trx_id */ UUID trxId = UUID.randomUUID(); record.setUUIDValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_TRX_ID_COLUMN_NAME, trxId); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_HASH_COLUMN_NAME, hash); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_CRYPTO_STATUS_COLUMN_NAME, cryptoStatus.getCode()); record.setIntegerValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_BLOCK_DEPTH_COLUMN_NAME, blockDepth); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_ADDRESS_TO_COLUMN_NAME, addressTo.getAddress()); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_ADDRESS_FROM_COLUMN_NAME, addressFrom.getAddress()); record.setDoubleValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_VALUE_COLUMN_NAME, value); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_OP_RETURN_COLUMN_NAME, op_Return); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_PROTOCOL_STATUS_COLUMN_NAME, protocolStatus.getCode()); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_LAST_UPDATE_COLUMN_NAME, getCurrentDateTime()); try { databaseTable.insertRecord(record); } catch (CantInsertRecordException e) { StringBuilder outputMessage = new StringBuilder( "There was an error inserting a new transaction in the Outgoing Transactions Table. Transaction record is:"); outputMessage.append(System.lineSeparator()); outputMessage.append(XMLParser.parseObject(record)); throw new CantExecuteDatabaseOperationException( CantExecuteDatabaseOperationException.DEFAULT_MESSAGE, e, outputMessage.toString(), "database issue."); } }
public List<DeveloperDatabaseTableRecord> getDatabaseTableContent( DeveloperObjectFactory developerObjectFactory, DeveloperDatabaseTable developerDatabaseTable) { /** Will get the records for the given table */ List<DeveloperDatabaseTableRecord> returnedRecords = new ArrayList<DeveloperDatabaseTableRecord>(); /** I load the passed table name from the SQLite database. */ DatabaseTable selectedTable = database.getTable(developerDatabaseTable.getName()); try { selectedTable.loadToMemory(); List<DatabaseTableRecord> records = selectedTable.getRecords(); for (DatabaseTableRecord row : records) { List<String> developerRow = new ArrayList<String>(); /** for each row in the table list */ for (DatabaseRecord field : row.getValues()) { /** I get each row and save them into a List<String> */ developerRow.add(field.getValue()); } /** I create the Developer Database record */ returnedRecords.add( developerObjectFactory.getNewDeveloperDatabaseTableRecord(developerRow)); } /** return the list of DeveloperRecords for the passed table. */ } catch (CantLoadTableToMemoryException cantLoadTableToMemory) { /** if there was an error, I will returned an empty list. */ database.closeDatabase(); return returnedRecords; } catch (Exception e) { database.closeDatabase(); return returnedRecords; } database.closeDatabase(); return returnedRecords; }
public boolean isGenesisTransactionRegistered(String genesisTransaction) throws CantExecuteQueryException { try { this.database = openDatabase(); DatabaseTable databaseTable; databaseTable = database.getTable(AssetReceptionDatabaseConstants.ASSET_RECEPTION_TABLE_NAME); databaseTable.addStringFilter( AssetReceptionDatabaseConstants.ASSET_RECEPTION_GENESIS_TRANSACTION_COLUMN_NAME, genesisTransaction, DatabaseFilterType.EQUAL); databaseTable.loadToMemory(); return !databaseTable.getRecords().isEmpty(); } catch (CantLoadTableToMemoryException exception) { throw new CantExecuteQueryException( "Error executing query in DB.", exception, "Checking if genesis transaction exists in database.", "Cannot load table to memory."); } catch (Exception exception) { throw new CantExecuteQueryException( CantExecuteQueryException.DEFAULT_MESSAGE, FermatException.wrapException(exception), "Checking if genesis transaction exits in database.", "Unexpected exception"); } }
private List<String> getValueListFromTableByColumn( String referenceValue, String table, String referenceColumn, String returningColumn) throws CantCheckAssetReceptionProgressException { try { this.database = openDatabase(); DatabaseTable databaseTable; List<String> returningList = new ArrayList<>(); databaseTable = database.getTable(table); databaseTable.addStringFilter(referenceColumn, referenceValue, DatabaseFilterType.EQUAL); databaseTable.loadToMemory(); for (DatabaseTableRecord record : databaseTable.getRecords()) { returningList.add(record.getStringValue(returningColumn)); } return returningList; } catch (CantLoadTableToMemoryException exception) { throw new CantCheckAssetReceptionProgressException( exception, "Getting " + referenceColumn + " list", "Cannot load table to memory"); } catch (CantExecuteDatabaseOperationException exception) { throw new CantCheckAssetReceptionProgressException( exception, "Getting " + referenceColumn + " list", "Cannot open or find the Asset Reception database"); } catch (Exception exception) { throw new CantCheckAssetReceptionProgressException( FermatException.wrapException(exception), "Getting " + referenceColumn + " list", "Unexpected exception"); } }
private boolean isAssetsByReceptionStatus(ReceptionStatus receptionStatus) throws CantExecuteQueryException { try { this.database = openDatabase(); DatabaseTable databaseTable; databaseTable = database.getTable(AssetReceptionDatabaseConstants.ASSET_RECEPTION_TABLE_NAME); databaseTable.addStringFilter( AssetReceptionDatabaseConstants.ASSET_RECEPTION_RECEPTION_STATUS_COLUMN_NAME, receptionStatus.getCode(), DatabaseFilterType.EQUAL); databaseTable.addStringFilter( AssetReceptionDatabaseConstants.ASSET_RECEPTION_CRYPTO_STATUS_COLUMN_NAME, CryptoStatus.PENDING_SUBMIT.getCode(), DatabaseFilterType.EQUAL); databaseTable.loadToMemory(); return !databaseTable.getRecords().isEmpty(); } catch (CantLoadTableToMemoryException exception) { throw new CantExecuteQueryException( "Error executing query in DB.", exception, "Getting assets by reception status.", "Cannot load table to memory."); } catch (Exception exception) { throw new CantExecuteQueryException( CantExecuteQueryException.DEFAULT_MESSAGE, FermatException.wrapException(exception), "Getting assets by reception status.", "Unexpected exception"); } }
@Override public int getPublicKeyPosition(String address) throws CantExecuteDatabaseOperationException { DatabaseTable databaseTable = database.getTable( AssetsOverBitcoinCryptoVaultDatabaseConstants.KEY_MAINTENANCE_DETAIL_TABLE_NAME); databaseTable.addStringFilter( AssetsOverBitcoinCryptoVaultDatabaseConstants.KEY_MAINTENANCE_DETAIL_ADDRESS_COLUMN_NAME, address, DatabaseFilterType.EQUAL); try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } List<DatabaseTableRecord> databaseTableRecords = databaseTable.getRecords(); if (databaseTableRecords.size() != 0) { return databaseTableRecords .get(0) .getIntegerValue( AssetsOverBitcoinCryptoVaultDatabaseConstants .KEY_MAINTENANCE_DETAIL_KEY_DEPTH_COLUMN_NAME); } else return 0; }
public void setUpMockitoRules() throws Exception { when(mockPluginDatabaseSystem.openDatabase(pluginId, pluginId.toString())) .thenReturn(mockDatabase); when(mockExtraUserActorDatabaseFactory.createDatabase(pluginId, pluginId.toString())) .thenReturn(mockDatabase); when(mockDatabase.getTable(ExtraUserActorDatabaseConstants.EXTRA_USER_TABLE_NAME)) .thenReturn(mockTable); when(mockTable.getRecords()).thenReturn(mockRecords); when(mockRecords.get(anyInt())).thenReturn(mockTableRecord); when(mockPluginFileSystem.getBinaryFile( any(UUID.class), anyString(), anyString(), any(FilePrivacy.class), any(FileLifeSpan.class))) .thenReturn(mockBinaryFile); when(mockPluginFileSystem.getTextFile( any(UUID.class), anyString(), anyString(), any(FilePrivacy.class), any(FileLifeSpan.class))) .thenReturn(mockFile); when(mockBinaryFile.getContent()).thenReturn(new byte[100]); }
/** * Gets the next It to be used to create a new HierarchyAccountId * * @return */ public int getNextAvailableHierarchyAccountId() throws CantExecuteDatabaseOperationException { DatabaseTable databaseTable = database.getTable(AssetsOverBitcoinCryptoVaultDatabaseConstants.KEY_ACCOUNTS_TABLE_NAME); try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } /** returns the next available Id to be used. */ List<DatabaseTableRecord> databaseTableRecords = databaseTable.getRecords(); if (databaseTableRecords.isEmpty()) return 0; else { int hierarchyAccountId = 0; for (DatabaseTableRecord record : databaseTableRecords) { if (record.getIntegerValue( AssetsOverBitcoinCryptoVaultDatabaseConstants.KEY_ACCOUNTS_ID_COLUMN_NAME) > hierarchyAccountId) hierarchyAccountId = record.getIntegerValue( AssetsOverBitcoinCryptoVaultDatabaseConstants.KEY_ACCOUNTS_ID_COLUMN_NAME); } return hierarchyAccountId + 1; } }
@Before public void setUp() throws Exception { bitcoinCryptoVault = new BitcoinCryptoVault(userPublicKey); bitcoinCryptoVault.setPluginFileSystem(pluginFileSystem); bitcoinCryptoVault.setPluginDatabaseSystem(pluginDatabaseSystem); bitcoinCryptoVault.setPluginFileSystem(pluginFileSystem); bitcoinCryptoVault.setUserPublicKey(userPublicKey); bitcoinCryptoVault.setDatabase(mockDatabase); bitcoinCryptoVault.setPluginId(pluginId); bitcoinCryptoVault.setLogManager(mockLogManager); when(pluginFileSystem.createTextFile( pluginId, userPublicKey, userPublicKey.toString() + ".vault", FilePrivacy.PRIVATE, FileLifeSpan.PERMANENT)) .thenReturn(mockPluginTextFile); bitcoinCryptoVault.loadOrCreateVault(); when(pluginDatabaseSystem.openDatabase(pluginId, userPublicKey)).thenReturn(mockDatabase); when(mockDatabase.getTable(anyString())).thenReturn(mockTable); when(mockDatabase.newTransaction()).thenReturn(mockDatabaseTransaction); when(mockTable.getRecords()).thenReturn(mockRecords); Mockito.doReturn(mockRecord).when(mockRecords).get(0); }
private boolean isPendingEventsBySource(EventSource eventSource) throws CantExecuteQueryException { try { this.database = openDatabase(); DatabaseTable databaseTable; databaseTable = database.getTable( AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_TABLE_NAME); databaseTable.addStringFilter( AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_STATUS_COLUMN_NAME, EventStatus.PENDING.getCode(), DatabaseFilterType.EQUAL); databaseTable.addStringFilter( AssetReceptionDatabaseConstants.ASSET_RECEPTION_EVENTS_RECORDED_SOURCE_COLUMN_NAME, eventSource.getCode(), DatabaseFilterType.EQUAL); databaseTable.loadToMemory(); return !databaseTable.getRecords().isEmpty(); } catch (CantLoadTableToMemoryException exception) { throw new CantExecuteQueryException( "Error executing query in DB.", exception, "Getting pending events.", "Cannot load table to memory."); } catch (Exception exception) { throw new CantExecuteQueryException( CantExecuteQueryException.DEFAULT_MESSAGE, FermatException.wrapException(exception), "Getting pending events.", "Unexpected exception"); } }
public boolean isPendingTransactions(CryptoStatus cryptoStatus) throws CantExecuteQueryException { try { this.database = openDatabase(); DatabaseTable databaseTable; databaseTable = database.getTable(AssetReceptionDatabaseConstants.ASSET_RECEPTION_TABLE_NAME); databaseTable.addStringFilter( AssetReceptionDatabaseConstants.ASSET_RECEPTION_PROTOCOL_STATUS_COLUMN_NAME, ProtocolStatus.TO_BE_NOTIFIED.getCode(), DatabaseFilterType.EQUAL); databaseTable.addStringFilter( AssetReceptionDatabaseConstants.ASSET_RECEPTION_CRYPTO_STATUS_COLUMN_NAME, cryptoStatus.getCode(), DatabaseFilterType.EQUAL); databaseTable.loadToMemory(); return !databaseTable.getRecords().isEmpty(); } catch (CantLoadTableToMemoryException exception) { throw new CantExecuteQueryException( "Error executing query in DB.", exception, "Getting pending transactions.", "Cannot load table to memory."); } catch (Exception exception) { throw new CantExecuteQueryException( CantExecuteQueryException.DEFAULT_MESSAGE, FermatException.wrapException(exception), "Getting pending transactions.", "Unexpected exception"); } }
private void setUpMockitoRules() throws Exception { when(mockDatabase.getDatabaseFactory()).thenReturn(mockDatabaseFactory); when(mockDatabaseTable.getEmptyRecord()).thenReturn(mockDatabaseTableRecord); when(mockDatabase.getTable(AssetIssuingDatabaseConstants.ASSET_ISSUING_TABLE_NAME)) .thenReturn(mockDatabaseTable); when(pluginDatabaseSystem.openDatabase( pluginId, AssetIssuingDatabaseConstants.ASSET_ISSUING_DATABASE)) .thenReturn(mockDatabase); // when(mockExtraUserActorDatabaseFactory.createDatabase(pluginId, // pluginId.toString())).thenReturn(mockDatabase); when(deviceUser.getPublicKey()).thenReturn("myPublicKey"); when(deviceUserManager.getLoggedInDeviceUser()).thenReturn(deviceUser); when(eventManager.getNewListener( EventType.INCOMING_ASSET_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER)) .thenReturn(fermatEventListener1); when(eventManager.getNewListener( EventType.INCOMING_ASSET_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER)) .thenReturn(fermatEventListener2); when(eventManager.getNewListener( EventType.INCOMING_ASSET_REVERSED_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER)) .thenReturn(fermatEventListener3); when(eventManager.getNewListener( EventType.INCOMING_ASSET_REVERSED_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER)) .thenReturn(fermatEventListener4); when(eventManager.getNewListener(EventType.RECEIVED_NEW_DIGITAL_ASSET_METADATA_NOTIFICATION)) .thenReturn(fermatEventListener5); when(actorAssetIssuerManager.getActorAssetIssuer()).thenReturn(actorAssetIssuer); }
private void mockitoRules() throws Exception { when(database.getTable(AssetIssuingDatabaseConstants.ASSET_ISSUING_TABLE_NAME)) .thenReturn(databaseTable); when(databaseTable.getRecords()).thenReturn(records); when(databaseTableRecord.getIntegerValue( AssetIssuingDatabaseConstants.ASSET_ISSUING_ASSETS_COMPLETED_COLUMN_NAME)) .thenReturn(issuedAssetsExpected); }
/** * Gets the crypto Status list that are in pending status from the specified table. * * @param transactionType * @return */ public Set<CryptoStatus> getPendingCryptoStatus(TransactionTypes transactionType) throws CantExecuteDatabaseOperationException { DatabaseTable databaseTable; String cryptoStatusColumnName; Set<CryptoStatus> cryptoStatuses = new HashSet<>(); /** Will set up filters and column names depending on the transaction type. */ if (transactionType == TransactionTypes.OUTGOING) { databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_TABLE_NAME); databaseTable.setStringFilter( BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_PROTOCOL_STATUS_COLUMN_NAME, ProtocolStatus.TO_BE_NOTIFIED.getCode(), DatabaseFilterType.EQUAL); cryptoStatusColumnName = BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_CRYPTO_STATUS_COLUMN_NAME; } else { databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_TABLE_NAME); databaseTable.setStringFilter( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_PROTOCOL_STATUS_COLUMN_NAME, ProtocolStatus.TO_BE_NOTIFIED.getCode(), DatabaseFilterType.EQUAL); cryptoStatusColumnName = BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_CRYPTO_STATUS_COLUMN_NAME; } try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } /** get all the CryptoStatus and remove duplicates as Im storing them in a set. */ for (DatabaseTableRecord record : databaseTable.getRecords()) { try { CryptoStatus cryptoStatus = CryptoStatus.getByCode(record.getStringValue(cryptoStatusColumnName)); cryptoStatuses.add(cryptoStatus); } catch (InvalidParameterException e) { e.printStackTrace(); } } return cryptoStatuses; }
private void mockitoRules() throws Exception { when(database.getTable(AssetIssuingDatabaseConstants.ASSET_ISSUING_METADATA_TABLE)) .thenReturn(databaseTable); when(databaseTable.getRecords()).thenReturn(records); when(databaseTableRecord.getStringValue( AssetIssuingDatabaseConstants.ASSET_ISSUING_GENESIS_TRANSACTION_COLUMN_NAME)) .thenReturn(genesisTransactionExpected); }
@Test public void GetBalance_GeneralException_ReturnsAvailableBalance() throws Exception { when(mockDatabase.getTable(BitcoinWalletDatabaseConstants.BITCOIN_WALLET_BALANCE_TABLE_NAME)) .thenReturn(null); catchException(testBalance).getBalance(); assertThat(caughtException()).isNotNull().isInstanceOf(CantCalculateBalanceException.class); }
/** * Updates the Key detailed table for this account and key, with the passed addres * * @param hierarchyAccountId * @param ecKey * @param cryptoAddress * @param blockchainNetworkType */ public void updateKeyDetailedStatsWithNewAddress( int hierarchyAccountId, ECKey ecKey, CryptoAddress cryptoAddress, BlockchainNetworkType blockchainNetworkType) throws CantExecuteDatabaseOperationException, UnexpectedResultReturnedFromDatabaseException { /** If we are not allowed to save detailed information then we will exit */ if (!VaultKeyMaintenanceParameters.STORE_DETAILED_KEY_INFORMATION) return; DatabaseTable databaseTable = database.getTable( AssetsOverBitcoinCryptoVaultDatabaseConstants.KEY_MAINTENANCE_DETAIL_TABLE_NAME); databaseTable.addStringFilter( AssetsOverBitcoinCryptoVaultDatabaseConstants.KEY_MAINTENANCE_DETAIL_ACCOUNT_ID_COLUMN_NAME, String.valueOf(hierarchyAccountId), DatabaseFilterType.EQUAL); databaseTable.addStringFilter( AssetsOverBitcoinCryptoVaultDatabaseConstants.KEY_MAINTENANCE_DETAIL_PUBLIC_KEY_COLUMN_NAME, ecKey.getPublicKeyAsHex(), DatabaseFilterType.EQUAL); try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } if (databaseTable.getRecords().size() == 0) { StringBuilder output = new StringBuilder("The key " + ecKey.toString()); output.append(System.lineSeparator()); output.append("which generated the address " + cryptoAddress.getAddress()); output.append(System.lineSeparator()); output.append("is not a key derived from the vault."); throw new UnexpectedResultReturnedFromDatabaseException( null, output.toString(), "Vault derivation miss match"); } DatabaseTableRecord record = databaseTable.getRecords().get(0); record.setStringValue( AssetsOverBitcoinCryptoVaultDatabaseConstants.KEY_MAINTENANCE_DETAIL_ADDRESS_COLUMN_NAME, cryptoAddress.getAddress()); record.setStringValue( AssetsOverBitcoinCryptoVaultDatabaseConstants .KEY_MAINTENANCE_DETAIL_BLOCKCHAIN_NETWORK_TYPE_COLUMN_NAME, blockchainNetworkType.getCode()); try { databaseTable.updateRecord(record); } catch (CantUpdateRecordException e) { throw new CantExecuteDatabaseOperationException( CantExecuteDatabaseOperationException.DEFAULT_MESSAGE, e, "error updating record", "database issue"); } }
private void insertInitialBalancesRecord(final Database database) throws CantInsertRecordException { DatabaseTable balancesTable = database.getTable( BitcoinLossProtectedWalletDatabaseConstants.LOSS_PROTECTED_WALLET_BALANCE_TABLE_NAME); List<DatabaseTableRecord> initialListRecord = constructBalanceInitialRecord(balancesTable); for (DatabaseTableRecord initalRecord : initialListRecord) { balancesTable.insertRecord(initalRecord); } }
@Before public void setUpMockitoRules() { when(mockDatabase.getTable(BitcoinWalletDatabaseConstants.BITCOIN_WALLET_BALANCE_TABLE_NAME)) .thenReturn(mockTable); when(mockTable.getRecords()).thenReturn(mockRecords); when(mockRecords.get(0)).thenReturn(mockRecord); when(mockRecord.getLongValue( BitcoinWalletDatabaseConstants.BITCOIN_WALLET_BALANCE_TABLE_BOOK_BALANCE_COLUMN_NAME)) .thenReturn(mockBookBalance); }
private void setUpMockitoGeneralRules() throws Exception { when(mockPluginDatabaseSystem.createDatabase( pluginId, IntraWalletUserActorDatabaseConstants.INTRA_WALLET_USER_DATABASE_NAME)) .thenReturn(mockDatabase); when(mockDatabase.getDatabaseFactory()).thenReturn(mockDatabaseFactory); when(mockDatabaseFactory.newTableFactory( pluginId, IntraWalletUserActorDatabaseConstants.INTRA_WALLET_USER_TABLE_NAME)) .thenReturn(mockIntraUserTableFactory); when(mockDatabase.getTable(IntraWalletUserActorDatabaseConstants.INTRA_WALLET_USER_TABLE_NAME)) .thenReturn(mockTable); when(mockTable.getEmptyRecord()).thenReturn(mockTableRecord); }
@Test public void test() { List<DatabaseTableRecord> records = mock(ArrayList.class); when(database.getTable(anyString())).thenReturn(table); when(database.newTransaction()).thenReturn(transaction); when(table.getRecords()).thenReturn(records); when(table.getEmptyRecord()).thenReturn(record); when(records.isEmpty()).thenReturn(true); VaultEventListeners eventListeners = new VaultEventListeners(database, errorManager, eventManager, logManager); eventListeners.onCoinsReceived(wallet, tx, Coin.CENT, Coin.CENT); }
public void setUpMockitoRules() throws Exception { when(mockDatabase.getDatabaseFactory()).thenReturn(mockDatabaseFactory); when(mockDatabaseTable.getEmptyRecord()).thenReturn(mockDatabaseTableRecord); when(mockDatabase.getTable(CryptoIndexDatabaseConstants.CRYPTO_INDEX_TABLE_NAME)) .thenReturn(mockDatabaseTable); when(mockPluginDatabaseSystem.openDatabase( pluginId, CryptoIndexDatabaseConstants.CRYPTO_INDEX_DATABASE_NAME)) .thenReturn(mockDatabase); when(mockCryptoIndexDatabaseFactory.createDatabase( pluginId, CryptoIndexDatabaseConstants.CRYPTO_INDEX_DATABASE_NAME)) .thenReturn(mockDatabase); cryptoIndexDao = new CryptoIndexDao(mockPluginDatabaseSystem, pluginId); }
/** * searches for the public key and notifies if is exists. * * @param redeemPointPublicKey * @return */ public boolean isExistingRedeemPoint(String redeemPointPublicKey) throws CantExecuteDatabaseOperationException { DatabaseTable databaseTable = database.getTable(AssetsOverBitcoinCryptoVaultDatabaseConstants.KEY_ACCOUNTS_TABLE_NAME); databaseTable.addStringFilter( AssetsOverBitcoinCryptoVaultDatabaseConstants.KEY_ACCOUNTS_DESCRIPTION_COLUMN_NAME, redeemPointPublicKey, DatabaseFilterType.EQUAL); try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } return !databaseTable.getRecords().isEmpty(); }
/** * If the transaction exists in the IncomingTransactions table it will return true, otherwise it * will return false * * @param txHash * @return */ public boolean isIncomingTransaction(String txHash) throws CantExecuteDatabaseOperationException { DatabaseTable databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_TABLE_NAME); databaseTable.setStringFilter( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_HASH_COLUMN_NAME, txHash, DatabaseFilterType.EQUAL); try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } if (databaseTable.getRecords().size() > 0) return true; else return false; }