Search in sources :

Example 1 with ConfigFactory

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

the class EnclaveProviderTest method provider.

@Test
public void provider() {
    try (var staticConfigFactory = mockStatic(ConfigFactory.class)) {
        ConfigFactory configFactory = mock(ConfigFactory.class);
        // FIXME: Having to use proper config object rather than mock
        Config config = JaxbUtil.unmarshal(getClass().getResourceAsStream("/sample.json"), Config.class);
        when(configFactory.getConfig()).thenReturn(config);
        staticConfigFactory.when(ConfigFactory::create).thenReturn(configFactory);
        Enclave enclave = EnclaveProvider.provider();
        assertThat(enclave).isNotNull();
        assertThat(enclave).describedAs("Second call should return cached/held instance").isSameAs(EnclaveProvider.provider());
    }
}
Also used : Config(com.quorum.tessera.config.Config) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 2 with ConfigFactory

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

the class EnclaveServerProviderTest method provider.

@Test
public void provider() {
    try (var configFactoryMockedStatic = mockStatic(ConfigFactory.class);
        var enclaveFactoryMockedStatic = mockStatic(EnclaveFactoryImpl.class)) {
        ConfigFactory configFactory = mock(ConfigFactory.class);
        Config config = mock(Config.class);
        when(configFactory.getConfig()).thenReturn(config);
        Enclave enclave = mock(Enclave.class);
        enclaveFactoryMockedStatic.when(() -> EnclaveFactoryImpl.createServer(config)).thenReturn(enclave);
        configFactoryMockedStatic.when(ConfigFactory::create).thenReturn(configFactory);
        EnclaveServer result = EnclaveServerProvider.provider();
        assertThat(result).isExactlyInstanceOf(EnclaveServerImpl.class);
        enclaveFactoryMockedStatic.verify(() -> EnclaveFactoryImpl.createServer(config));
        enclaveFactoryMockedStatic.verifyNoMoreInteractions();
        verify(configFactory).getConfig();
        verifyNoMoreInteractions(configFactory);
        configFactoryMockedStatic.verify(ConfigFactory::create);
        configFactoryMockedStatic.verifyNoMoreInteractions();
    }
}
Also used : Config(com.quorum.tessera.config.Config) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 3 with ConfigFactory

use of com.quorum.tessera.config.ConfigFactory 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 4 with ConfigFactory

use of com.quorum.tessera.config.ConfigFactory 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 5 with ConfigFactory

use of com.quorum.tessera.config.ConfigFactory 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)

Aggregations

ConfigFactory (com.quorum.tessera.config.ConfigFactory)20 Config (com.quorum.tessera.config.Config)17 Test (org.junit.Test)17 ServerConfig (com.quorum.tessera.config.ServerConfig)6 JdbcConfig (com.quorum.tessera.config.JdbcConfig)4 DataSourceFactory (com.quorum.tessera.data.DataSourceFactory)4 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)4 EncryptedRawTransactionDAO (com.quorum.tessera.data.EncryptedRawTransactionDAO)2 EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)2 Discovery (com.quorum.tessera.discovery.Discovery)2 ClientSSLContextFactory (com.quorum.tessera.ssl.context.ClientSSLContextFactory)2 PayloadPublisher (com.quorum.tessera.transaction.publish.PayloadPublisher)2 Before (org.junit.Before)2 PrivacyGroupDAO (com.quorum.tessera.data.PrivacyGroupDAO)1 StagingEntityDAO (com.quorum.tessera.data.staging.StagingEntityDAO)1 Enclave (com.quorum.tessera.enclave.Enclave)1 EnclaveClient (com.quorum.tessera.enclave.EnclaveClient)1 PayloadDigest (com.quorum.tessera.enclave.PayloadDigest)1 P2pClient (com.quorum.tessera.partyinfo.P2pClient)1 PrivacyGroupPublisher (com.quorum.tessera.privacygroup.publish.PrivacyGroupPublisher)1