@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); }
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()); }
public void update(NegotiationTransmission entity) throws CantUpdateRecordDataBaseException { if (entity == null) { throw new IllegalArgumentException("The entity is required, can not be null"); } try { DatabaseTable outgoingNotificationtable = getDatabaseTable(); DatabaseTableRecord emptyRecord = getDatabaseTable().getEmptyRecord(); /* * 1- Create the record to the entity */ DatabaseTableRecord entityRecord = loadRecordAsSendNegotiationTransmission(emptyRecord, entity); /** 2.- Create a new transaction and execute */ DatabaseTransaction transaction = database.newTransaction(); // Set filter outgoingNotificationtable.addUUIDFilter( NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_TRANSMISSION_ID_COLUMN_NAME, entity.getTransmissionId(), DatabaseFilterType.EQUAL); // // outgoingNotificationtable.addUUIDFilter(NegotiationTransmissionNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_TRANSACTION_ID_COLUMN_NAME, entity.getTransactionId(), DatabaseFilterType.EQUAL); // // outgoingNotificationtable.addUUIDFilter(NegotiationTransmissionNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_NEGOTIATION_ID_COLUMN_NAME, entity.getNegotiationId(), DatabaseFilterType.EQUAL); transaction.addRecordToUpdate(outgoingNotificationtable, entityRecord); database.executeTransaction(transaction); } catch (DatabaseTransactionFailedException databaseTransactionFailedException) { // Register the failure. StringBuilder contextBuilder = new StringBuilder(); contextBuilder .append("Database Name: ") .append(NegotiationTransmissionNetworkServiceDatabaseConstants.DATA_BASE_NAME); String context = contextBuilder.toString(); String possibleCause = "The record do not exist"; CantUpdateRecordDataBaseException cantUpdateRecordDataBaseException = new CantUpdateRecordDataBaseException( CantUpdateRecordDataBaseException.DEFAULT_MESSAGE, databaseTransactionFailedException, context, possibleCause); throw cantUpdateRecordDataBaseException; // } catch (CantBuildDataBaseRecordException e) { // CantUpdateRecordDataBaseException cantUpdateRecordDataBaseException = new // CantUpdateRecordDataBaseException(CantUpdateRecordDataBaseException.DEFAULT_MESSAGE, e, "", // ""); // throw cantUpdateRecordDataBaseException; } }
@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); }
// @Override public void update(ActorAssetNetworkServiceRecord entity) throws CantUpdateRecordDataBaseException { if (entity == null) { throw new IllegalArgumentException("The entity is required, can not be null"); } try { DatabaseTable incomingNotificationtable = getDatabaseTable(); DatabaseTableRecord emptyRecord = getDatabaseTable().getEmptyRecord(); /* * 1- Create the record to the entity */ DatabaseTableRecord entityRecord = buildDatabaseRecord(emptyRecord, entity); /** 2.- Create a new transaction and execute */ DatabaseTransaction transaction = database.newTransaction(); // Set filter incomingNotificationtable.addUUIDFilter( AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_ID_COLUMN_NAME, entity.getId(), DatabaseFilterType.EQUAL); transaction.addRecordToUpdate(incomingNotificationtable, entityRecord); database.executeTransaction(transaction); } catch (DatabaseTransactionFailedException databaseTransactionFailedException) { // Register the failure. StringBuffer contextBuffer = new StringBuffer(); contextBuffer.append( "Database Name: " + AssetUserNetworkServiceDatabaseConstants.DATA_BASE_NAME); String context = contextBuffer.toString(); String possibleCause = "The record do not exist"; CantUpdateRecordDataBaseException cantUpdateRecordDataBaseException = new CantUpdateRecordDataBaseException( CantUpdateRecordDataBaseException.DEFAULT_MESSAGE, databaseTransactionFailedException, context, possibleCause); throw cantUpdateRecordDataBaseException; } catch (CantBuildDataBaseRecordException e) { CantUpdateRecordDataBaseException cantUpdateRecordDataBaseException = new CantUpdateRecordDataBaseException( CantUpdateRecordDataBaseException.DEFAULT_MESSAGE, e, "", ""); throw cantUpdateRecordDataBaseException; } }
/** * Insert new public keys into the detailed monitor table * * @param accountId * @param keys * @throws CantExecuteDatabaseOperationException */ public void updateDetailMaintainerStats(int accountId, List<ECKey> keys, int currentGeneratedKeys) throws CantExecuteDatabaseOperationException { /** 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); DatabaseTransaction transaction = database.newTransaction(); /** * I will insert each key. Since I don't want to repeat inserting keys, I will only insert the * keys which position is after currentGeneratedKeys value */ int i = 1; for (ECKey key : keys) { if (i >= currentGeneratedKeys) { DatabaseTableRecord record = databaseTable.getEmptyRecord(); record.setIntegerValue( AssetsOverBitcoinCryptoVaultDatabaseConstants .KEY_MAINTENANCE_DETAIL_ACCOUNT_ID_COLUMN_NAME, accountId); record.setIntegerValue( AssetsOverBitcoinCryptoVaultDatabaseConstants .KEY_MAINTENANCE_DETAIL_KEY_DEPTH_COLUMN_NAME, i); record.setStringValue( AssetsOverBitcoinCryptoVaultDatabaseConstants .KEY_MAINTENANCE_DETAIL_PUBLIC_KEY_COLUMN_NAME, key.getPublicKeyAsHex()); transaction.addRecordToInsert(databaseTable, record); } i++; } /** once I collected all records, I will insert them in a single transaction */ try { database.executeTransaction(transaction); } catch (DatabaseTransactionFailedException e) { throw new CantExecuteDatabaseOperationException( CantExecuteDatabaseOperationException.DEFAULT_MESSAGE, e, "error inserting records in transaction.", null); } }
public void saveBankMoneyRestockTransactionData(BankMoneyTransaction bankMoneyTransaction) throws DatabaseOperationException, MissingBankMoneyRestockDataException { try { database = openDatabase(); DatabaseTransaction transaction = database.newTransaction(); // TODO: Solo para prueba ya que priceReference viene null desde android revisar con Nelson bankMoneyTransaction.setPriceReference(new BigDecimal(0)); /*//TODO:Revisar con guillermo que el accountNumber viene null bankMoneyTransaction.setBankAccount("123456"); */ DatabaseTable table = getDatabaseTable( BussinessTransactionBankMoneyRestockDatabaseConstants.BANK_MONEY_STOCK_TABLE_NAME); DatabaseTableRecord bankMoneyRestockRecord = getBankMoneyRestockRecord(bankMoneyTransaction); DatabaseTableFilter filter = table.getEmptyTableFilter(); filter.setType(DatabaseFilterType.EQUAL); filter.setValue(bankMoneyTransaction.getTransactionId().toString()); filter.setColumn( BussinessTransactionBankMoneyRestockDatabaseConstants .BANK_MONEY_RESTOCK_TRANSACTION_ID_COLUMN_NAME); if (isNewRecord(table, filter)) transaction.addRecordToInsert(table, bankMoneyRestockRecord); else { table.addStringFilter(filter.getColumn(), filter.getValue(), filter.getType()); transaction.addRecordToUpdate(table, bankMoneyRestockRecord); } // I execute the transaction and persist the database side of the asset. database.executeTransaction(transaction); database.closeDatabase(); } catch (Exception e) { if (database != null) database.closeDatabase(); throw new DatabaseOperationException( DatabaseOperationException.DEFAULT_MESSAGE, e, "Error trying to save the Bank Money Restock Transaction in the database.", null); } }