示例#1
0
  @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);
  }
示例#2
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 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]);
  }
  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);
  }
  @Before
  public void setUp() throws Exception {
    testOwnerId = UUID.randomUUID();
    when(mockPluginDatabaseSystem.openDatabase(any(UUID.class), anyString()))
        .thenReturn(mockDatabase);

    when(mockDatabaseFactory.newTableFactory(any(UUID.class), anyString())).thenReturn(mockTable);
    subAppResourcesInstallationNetworkServiceDAO =
        new SubAppResourcesInstallationNetworkServiceDAO(mockPluginDatabaseSystem);
  }
  @Before
  public void setUp() throws Exception {
    pluginId = UUID.randomUUID();

    when(mockPluginDatabaseSystem.openDatabase(
            pluginId, IntraWalletUserActorDatabaseConstants.INTRA_WALLET_USER_DATABASE_NAME))
        .thenReturn(mockDatabase);

    setUpMockitoGeneralRules();
  }
示例#7
0
 private Database openDatabase() throws CantExecuteDatabaseOperationException {
   try {
     return pluginDatabaseSystem.openDatabase(
         pluginId, AssetReceptionDatabaseConstants.ASSET_RECEPTION_DATABASE);
   } catch (CantOpenDatabaseException | DatabaseNotFoundException exception) {
     throw new CantExecuteDatabaseOperationException(
         exception,
         "Opening the Asset Reception Transaction Database",
         "Error in database plugin.");
   }
 }
示例#8
0
  @Test
  public void Initialize_RegistryProperlySet_MethodSuccesfullyInvoked() throws Exception {
    when(mockPluginDatabaseSystem.openDatabase(
            testId, IncomingExtraUserDataBaseConstants.INCOMING_EXTRA_USER_DATABASE))
        .thenReturn(mockDatabase);

    testRegistry = new IncomingExtraUserRegistry();
    testRegistry.setErrorManager(mockErrorManager);
    testRegistry.setPluginDatabaseSystem(mockPluginDatabaseSystem);
    catchException(testRegistry).initialize(testId);
    assertThat(caughtException()).isNull();
  }
 @Test
 public void test_Throws_CantCheckAssetIssuingProgressException() throws Exception {
   when(pluginDatabaseSystem.openDatabase(
           pluginId, AssetIssuingDatabaseConstants.ASSET_ISSUING_DATABASE))
       .thenThrow(new CantOpenDatabaseException("error"));
   catchException(assetIssuingDAO).getGenesisTransactionsFromDigitalAssetsReceived();
   Exception thrown = caughtException();
   assertThat(thrown).isNotNull().isInstanceOf(CantCheckAssetIssuingProgressException.class);
   assertThat(thrown.getCause())
       .isNotNull()
       .isInstanceOf(CantExecuteDatabaseOperationException.class);
 }
  @Before
  public void init() throws Exception {

    pluginId = UUID.randomUUID();
    when(pluginDatabaseSystem.openDatabase(
            pluginId, AssetDistributionDatabaseConstants.ASSET_DISTRIBUTION_DATABASE))
        .thenReturn(database);
    mockAssetDistributionDao = new AssetDistributionDao(pluginDatabaseSystem, pluginId);
    records = new LinkedList<>();
    records.add(databaseTableRecord);
    setUpGeneralMockitoRules();
  }
示例#11
0
  @Test
  public void
      initializeDatabaseTest_ErrorNoFound_ThrowsCantInitializeNetworkServicesWalletResourcesDatabaseException()
          throws Exception {

    when(mockPluginDatabaseSystem.openDatabase(any(UUID.class), anyString()))
        .thenThrow(DatabaseNotFoundException.class);
    catchException(subAppResourcesInstallationNetworkServiceDAO)
        .initializeDatabase(
            testOwnerId, SubAppResourcesNetworkServiceDatabaseConstants.DATABASE_NAME);
    assertThat(CatchException.<Exception>caughtException()).isNotNull();
  }
示例#12
0
 @Test
 public void Initialize_CantOpenDatabase_ThrowsCantInitializeCryptoRegistryException()
     throws Exception {
   when(mockPluginDatabaseSystem.openDatabase(
           testId, IncomingExtraUserDataBaseConstants.INCOMING_EXTRA_USER_DATABASE))
       .thenThrow(new CantOpenDatabaseException("MOCK", null, null, null));
   testRegistry = new IncomingExtraUserRegistry();
   testRegistry.setErrorManager(mockErrorManager);
   testRegistry.setPluginDatabaseSystem(mockPluginDatabaseSystem);
   catchException(testRegistry).initialize(testId);
   assertThat(caughtException()).isInstanceOf(CantInitializeCryptoRegistryException.class);
 }
 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);
 }
 @Test
 public void
     getGenesisTransactionByAssetAcceptedStatusThrowsCantCheckAssetDistributionProgressException()
         throws Exception {
   when(pluginDatabaseSystem.openDatabase(
           pluginId, AssetDistributionDatabaseConstants.ASSET_DISTRIBUTION_DATABASE))
       .thenThrow(new CantOpenDatabaseException("error"));
   try {
     mockAssetDistributionDao.getGenesisTransactionByAssetAcceptedStatus();
     fail("The method didn't throw when I expected it to");
   } catch (Exception ex) {
     Assert.assertTrue(ex instanceof CantCheckAssetDistributionProgressException);
   }
 }
  @Before
  public void setUp() throws Exception {
    pluginId = UUID.randomUUID();

    when(pluginDatabaseSystem.openDatabase(
            pluginId, AssetIssuingDatabaseConstants.ASSET_ISSUING_DATABASE))
        .thenReturn(database);
    assetIssuingDAO = new AssetIssuingDAO(pluginDatabaseSystem, pluginId);

    records = new LinkedList<DatabaseTableRecord>();
    records.add(databaseTableRecord);

    mockitoRules();
  }
  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);
  }
示例#17
0
  @Test
  public void getDatabaseListTest_GetListOk() throws Exception {
    UUID testOwnerId = UUID.randomUUID();

    when(mockPluginDatabaseSystem.openDatabase(any(UUID.class), anyString()))
        .thenReturn(mockDatabase);

    developerDatabaseFactory =
        new WalletContactsMiddlewareDeveloperDatabaseFactory(mockPluginDatabaseSystem, testOwnerId);

    developerDatabaseFactory.initializeDatabase();

    assertThat(developerDatabaseFactory.getDatabaseList(developerObjectFactory))
        .isInstanceOf(List.class);
  }
  private Database openDatabase() throws CantOpenDatabaseException, CantCreateDatabaseException {
    try {
      database =
          pluginDatabaseSystem.openDatabase(
              this.pluginId,
              BussinessTransactionBankMoneyRestockDatabaseConstants.BANK_MONEY_STOCK_DATABASE_NAME);

    } catch (DatabaseNotFoundException e) {
      BusinessTransactionBankMoneyRestockDatabaseFactory
          businessTransactionBankMoneyRestockDatabaseFactory =
              new BusinessTransactionBankMoneyRestockDatabaseFactory(this.pluginDatabaseSystem);
      database =
          businessTransactionBankMoneyRestockDatabaseFactory.createDatabase(
              this.pluginId,
              BussinessTransactionBankMoneyRestockDatabaseConstants.BANK_MONEY_STOCK_DATABASE_NAME);
    }
    return database;
  }
  @Before
  public void setUp() throws Exception {

    image = new byte[100];
    mockImages.put("image1", image);
    walletResourcePluginRoot = new WalletResourcesNetworkServicePluginRoot();
    walletResourcePluginRoot.setPluginFileSystem(pluginFileSystem);
    walletResourcePluginRoot.setEventManager(eventManager);
    walletResourcePluginRoot.setErrorManager(errorManager);

    when(mockImages.get(anyString())).thenReturn(image);

    walletResourcePluginRoot.setPluginDatabaseSystem(mockPluginDatabaseSystem);

    when(mockPluginDatabaseSystem.openDatabase(any(UUID.class), anyString()))
        .thenReturn(mockDatabase);

    walletResourcePluginRoot.start();
  }
示例#20
0
 @Test
 public void Initialize_DatabaseNotFound_MethodSuccesfullyInvoked() throws Exception {
   when(mockPluginDatabaseSystem.openDatabase(
           testId, IncomingExtraUserDataBaseConstants.INCOMING_EXTRA_USER_DATABASE))
       .thenThrow(
           new DatabaseNotFoundException(
               DatabaseNotFoundException.DEFAULT_MESSAGE, null, null, null));
   when(mockPluginDatabaseSystem.createDatabase(
           testId, IncomingExtraUserDataBaseConstants.INCOMING_EXTRA_USER_DATABASE))
       .thenReturn(mockDatabase);
   when(mockDatabase.getDatabaseFactory()).thenReturn(mockDatabaseFactory);
   when(mockDatabaseFactory.newTableFactory(any(UUID.class), anyString()))
       .thenReturn(mockTableFactory);
   testRegistry = new IncomingExtraUserRegistry();
   testRegistry.setErrorManager(mockErrorManager);
   testRegistry.setPluginDatabaseSystem(mockPluginDatabaseSystem);
   catchException(testRegistry).initialize(testId);
   assertThat(caughtException()).isNull();
 }
  private Database openDatabase() throws CantOpenDatabaseException, CantCreateDatabaseException {
    try {
      database =
          pluginDatabaseSystem.openDatabase(
              this.pluginId,
              StockTransactionsCrpytoMoneyRestockDatabaseConstants
                  .CRYPTO_MONEY_RESTOCK_DATABASE_NAME);

    } catch (DatabaseNotFoundException e) {
      StockTransactionsCryptoMoneyRestockDatabaseFactory
          stockTransactionsCryptoMoneyRestockDatabaseFactory =
              new StockTransactionsCryptoMoneyRestockDatabaseFactory(this.pluginDatabaseSystem);
      database =
          stockTransactionsCryptoMoneyRestockDatabaseFactory.createDatabase(
              this.pluginId,
              StockTransactionsCrpytoMoneyRestockDatabaseConstants
                  .CRYPTO_MONEY_RESTOCK_DATABASE_NAME);
    }
    return database;
  }
示例#22
0
  @Before
  public void setUp() throws Exception {
    subAppResourcesNetworkServicePluginRoot = new SubAppResourcesNetworkServicePluginRoot();
    subAppResourcesNetworkServicePluginRoot.setPluginFileSystem(pluginFileSystem);
    subAppResourcesNetworkServicePluginRoot.setEventManager(mockEventManager);
    subAppResourcesNetworkServicePluginRoot.setErrorManager(errorManager);
    subAppResourcesNetworkServicePluginRoot.setPluginDatabaseSystem(mockPluginDatabaseSystem);

    when(mockPluginDatabaseSystem.openDatabase(any(UUID.class), anyString()))
        .thenReturn(mockDatabase);
    when(gitHubConnection.getFile(anyString())).thenReturn(repoManifest);
    when(pluginFileSystem.createTextFile(
            any(UUID.class),
            anyString(),
            anyString(),
            any(FilePrivacy.class),
            any(FileLifeSpan.class)))
        .thenReturn(layoutFile);
    when(pluginFileSystem.createBinaryFile(
            any(UUID.class),
            anyString(),
            anyString(),
            any(FilePrivacy.class),
            any(FileLifeSpan.class)))
        .thenReturn(imageFile);

    when(mockEventManager.getNewListener(EventType.BEGUN_WALLET_INSTALLATION))
        .thenReturn(mockFermatEventListener);
    when(pluginFileSystem.getTextFile(
            any(UUID.class),
            anyString(),
            anyString(),
            any(FilePrivacy.class),
            any(FileLifeSpan.class)))
        .thenReturn(mockPluginTextFile);
    setUpDataBase();
  }