Search in sources :

Example 6 with DataSourceFactory

use of com.quorum.tessera.data.DataSourceFactory in project tessera by ConsenSys.

the class EncryptedRawTransactionDAOProviderTest method provides.

@Test
public void provides() {
    try (var mockedConfigFactory = mockStatic(ConfigFactory.class);
        var mockedDataSourceFactory = mockStatic(DataSourceFactory.class);
        var mockedPersistence = mockStatic(Persistence.class)) {
        mockedPersistence.when(() -> Persistence.createEntityManagerFactory(anyString(), anyMap())).thenReturn(mock(EntityManagerFactory.class));
        Config config = mock(Config.class);
        JdbcConfig jdbcConfig = mock(JdbcConfig.class);
        when(jdbcConfig.isAutoCreateTables()).thenReturn(autocreateTables);
        when(config.getJdbcConfig()).thenReturn(jdbcConfig);
        ConfigFactory configFactory = mock(ConfigFactory.class);
        when(configFactory.getConfig()).thenReturn(config);
        mockedConfigFactory.when(ConfigFactory::create).thenReturn(configFactory);
        mockedDataSourceFactory.when(DataSourceFactory::create).thenReturn(mock(DataSourceFactory.class));
        EncryptedRawTransactionDAO result = EncryptedRawTransactionDAOProvider.provider();
        assertThat(result).isNotNull().isExactlyInstanceOf(EncryptedRawTransactionDAOImpl.class);
        mockedPersistence.verify(() -> Persistence.createEntityManagerFactory(anyString(), anyMap()));
        mockedPersistence.verifyNoMoreInteractions();
        EncryptedTransactionDAOProvider.provider();
    }
}
Also used : DataSourceFactory(com.quorum.tessera.data.DataSourceFactory) JdbcConfig(com.quorum.tessera.config.JdbcConfig) Config(com.quorum.tessera.config.Config) EncryptedRawTransactionDAO(com.quorum.tessera.data.EncryptedRawTransactionDAO) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) JdbcConfig(com.quorum.tessera.config.JdbcConfig) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Aggregations

DataSourceFactory (com.quorum.tessera.data.DataSourceFactory)6 Test (org.junit.Test)6 Config (com.quorum.tessera.config.Config)4 ConfigFactory (com.quorum.tessera.config.ConfigFactory)4 JdbcConfig (com.quorum.tessera.config.JdbcConfig)4 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)4 EncryptedRawTransactionDAO (com.quorum.tessera.data.EncryptedRawTransactionDAO)1 EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)1 PrivacyGroupDAO (com.quorum.tessera.data.PrivacyGroupDAO)1 StagingEntityDAO (com.quorum.tessera.data.staging.StagingEntityDAO)1