Search in sources :

Example 1 with JdbcConfig

use of com.quorum.tessera.config.JdbcConfig in project tessera by ConsenSys.

the class ConfigFileStoreTest method save.

@Test
public void save() throws IOException {
    Config config = new Config();
    config.setJdbcConfig(new JdbcConfig());
    config.getJdbcConfig().setUsername("JUNIT");
    configFileStore.save(config);
    Config result = JaxbUtil.unmarshal(Files.newInputStream(path), Config.class);
    assertThat(result.getJdbcConfig().getUsername()).isEqualTo("JUNIT");
}
Also used : JdbcConfig(com.quorum.tessera.config.JdbcConfig) Config(com.quorum.tessera.config.Config) JdbcConfig(com.quorum.tessera.config.JdbcConfig) Test(org.junit.Test)

Example 2 with JdbcConfig

use of com.quorum.tessera.config.JdbcConfig in project tessera by ConsenSys.

the class PrivacyGroupDAOProviderTest 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));
        PrivacyGroupDAO result = PrivacyGroupDAOProvider.provider();
        assertThat(result).isNotNull().isExactlyInstanceOf(PrivacyGroupDAOImpl.class);
        mockedPersistence.verify(() -> Persistence.createEntityManagerFactory(anyString(), anyMap()));
        mockedPersistence.verifyNoMoreInteractions();
        PrivacyGroupDAOProvider.provider();
    }
}
Also used : DataSourceFactory(com.quorum.tessera.data.DataSourceFactory) JdbcConfig(com.quorum.tessera.config.JdbcConfig) Config(com.quorum.tessera.config.Config) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) JdbcConfig(com.quorum.tessera.config.JdbcConfig) ConfigFactory(com.quorum.tessera.config.ConfigFactory) PrivacyGroupDAO(com.quorum.tessera.data.PrivacyGroupDAO) Test(org.junit.Test)

Example 3 with JdbcConfig

use of com.quorum.tessera.config.JdbcConfig in project tessera by ConsenSys.

the class StagingEntityDAOProviderTest method provider.

@Test
public void provider() {
    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));
        StagingEntityDAO result = StagingEntityDAOProvider.provider();
        assertThat(result).isNotNull().isExactlyInstanceOf(StagingEntityDAOImpl.class);
        mockedPersistence.verify(() -> Persistence.createEntityManagerFactory(anyString(), anyMap()));
        mockedPersistence.verifyNoMoreInteractions();
    }
}
Also used : DataSourceFactory(com.quorum.tessera.data.DataSourceFactory) JdbcConfig(com.quorum.tessera.config.JdbcConfig) Config(com.quorum.tessera.config.Config) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) StagingEntityDAO(com.quorum.tessera.data.staging.StagingEntityDAO) JdbcConfig(com.quorum.tessera.config.JdbcConfig) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 4 with JdbcConfig

use of com.quorum.tessera.config.JdbcConfig in project tessera by ConsenSys.

the class EncryptedTransactionDAOProviderTest 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));
        EncryptedTransactionDAO result = EncryptedTransactionDAOProvider.provider();
        assertThat(result).isNotNull().isExactlyInstanceOf(EncryptedTransactionDAOImpl.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) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) JdbcConfig(com.quorum.tessera.config.JdbcConfig) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 5 with JdbcConfig

use of com.quorum.tessera.config.JdbcConfig in project tessera by ConsenSys.

the class HikariDataSourceFactoryTest method create.

@Test
public void create() {
    String username = "junit";
    String password = "junitpw";
    String url = "jdbc:h2:mem:";
    JdbcConfig jdbcConfig = mock(JdbcConfig.class);
    when(jdbcConfig.getUsername()).thenReturn(username);
    when(jdbcConfig.getPassword()).thenReturn(password);
    when(jdbcConfig.getUrl()).thenReturn(url);
    DataSource dataSource = dataSourceFactory.create(jdbcConfig);
    assertThat(dataSource).isNotNull().isExactlyInstanceOf(HikariDataSource.class);
    HikariDataSource hikariDataSource = HikariDataSource.class.cast(dataSource);
    assertThat(hikariDataSource.getJdbcUrl()).isEqualTo(url);
    assertThat(hikariDataSource.getUsername()).isEqualTo(username);
    assertThat(hikariDataSource.getPassword()).isEqualTo(password);
    assertThat(dataSource).describedAs("Second call returns same instance").isSameAs(dataSourceFactory.create(jdbcConfig));
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) JdbcConfig(com.quorum.tessera.config.JdbcConfig) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Aggregations

JdbcConfig (com.quorum.tessera.config.JdbcConfig)8 Test (org.junit.Test)8 Config (com.quorum.tessera.config.Config)6 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)5 ConfigFactory (com.quorum.tessera.config.ConfigFactory)4 DataSourceFactory (com.quorum.tessera.data.DataSourceFactory)4 HikariDataSource (com.zaxxer.hikari.HikariDataSource)2 DataSource (javax.sql.DataSource)2 CliType (com.quorum.tessera.cli.CliType)1 ConfigConverter (com.quorum.tessera.cli.parsers.ConfigConverter)1 JaxbUtil (com.quorum.tessera.config.util.JaxbUtil)1 EncryptedRawTransaction (com.quorum.tessera.data.EncryptedRawTransaction)1 EncryptedRawTransactionDAO (com.quorum.tessera.data.EncryptedRawTransactionDAO)1 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)1 EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)1 MessageHash (com.quorum.tessera.data.MessageHash)1 PrivacyGroupDAO (com.quorum.tessera.data.PrivacyGroupDAO)1 StagingEntityDAO (com.quorum.tessera.data.staging.StagingEntityDAO)1 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)1 EncodedPayloadCodec (com.quorum.tessera.enclave.EncodedPayloadCodec)1