Search in sources :

Example 11 with ConfigFactory

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

the class ResendClientProviderTest method provider.

@Test
public void provider() {
    try (var configFactoryMockedStatic = mockStatic(ConfigFactory.class);
        var clientSSLContextFactoryMockedStatic = mockStatic(ClientSSLContextFactory.class)) {
        ConfigFactory configFactory = mock(ConfigFactory.class);
        Config config = mock(Config.class);
        ServerConfig serverConfig = mock(ServerConfig.class);
        when(config.getP2PServerConfig()).thenReturn(serverConfig);
        when(configFactory.getConfig()).thenReturn(config);
        configFactoryMockedStatic.when(ConfigFactory::create).thenReturn(configFactory);
        clientSSLContextFactoryMockedStatic.when(ClientSSLContextFactory::create).thenReturn(mock(ClientSSLContextFactory.class));
        ResendClient resendClient = ResendClientProvider.provider();
        assertThat(resendClient).isNotNull().isExactlyInstanceOf(RestResendClient.class);
        clientSSLContextFactoryMockedStatic.verify(ClientSSLContextFactory::create);
        clientSSLContextFactoryMockedStatic.verifyNoMoreInteractions();
        configFactoryMockedStatic.verify(ConfigFactory::create);
        configFactoryMockedStatic.verifyNoMoreInteractions();
    }
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) ClientSSLContextFactory(com.quorum.tessera.ssl.context.ClientSSLContextFactory) Config(com.quorum.tessera.config.Config) ServerConfig(com.quorum.tessera.config.ServerConfig) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 12 with ConfigFactory

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

the class EnclaveClientProviderTest method provider.

@Test
public void provider() {
    try (var configFactoryMockedStatic = mockStatic(ConfigFactory.class)) {
        configFactoryMockedStatic.when(ConfigFactory::create).thenReturn(configFactory);
        if (appType == AppType.ENCLAVE) {
            EnclaveClient enclaveClient = EnclaveClientProvider.provider();
            assertThat(enclaveClient).isNotNull();
        } else {
            Throwable ex = catchThrowable(() -> EnclaveClientProvider.provider());
            assertThat(ex).isExactlyInstanceOf(NoSuchElementException.class);
        }
        configFactoryMockedStatic.verify(ConfigFactory::create);
        configFactoryMockedStatic.verifyNoMoreInteractions();
    }
    verify(configFactory).getConfig();
}
Also used : EnclaveClient(com.quorum.tessera.enclave.EnclaveClient) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 13 with ConfigFactory

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

the class TransactionManagerProviderTest method provider.

@Test
public void provider() {
    try (var mockedStaticConfigFactory = mockStatic(ConfigFactory.class);
        var mockedStaticEncryptedTransactionDAO = mockStatic(EncryptedTransactionDAO.class);
        var mockedStaticEnclave = mockStatic(Enclave.class);
        var mockedStaticEncryptedRawTransactionDAO = mockStatic(EncryptedRawTransactionDAO.class);
        var mockedStaticPayloadPublisher = mockStatic(PayloadPublisher.class);
        var mockedStaticBatchPayloadPublisher = mockStatic(BatchPayloadPublisher.class);
        var mockedStaticPrivacyHelper = mockStatic(PrivacyHelper.class);
        var mockedStaticResendManager = mockStatic(ResendManager.class);
        var mockedStaticPayloadDigest = mockStatic(PayloadDigest.class)) {
        ConfigFactory configFactory = mock(ConfigFactory.class);
        Config config = mock(Config.class);
        when(configFactory.getConfig()).thenReturn(config);
        mockedStaticConfigFactory.when(ConfigFactory::create).thenReturn(configFactory);
        PayloadPublisher payloadPublisher = mock(PayloadPublisher.class);
        mockedStaticPayloadPublisher.when(PayloadPublisher::create).thenReturn(payloadPublisher);
        BatchPayloadPublisher batchPayloadPublisher = mock(BatchPayloadPublisher.class);
        mockedStaticBatchPayloadPublisher.when(BatchPayloadPublisher::create).thenReturn(batchPayloadPublisher);
        mockedStaticEncryptedRawTransactionDAO.when(EncryptedRawTransactionDAO::create).thenReturn(mock(EncryptedRawTransactionDAO.class));
        mockedStaticEnclave.when(Enclave::create).thenReturn(mock(Enclave.class));
        mockedStaticEncryptedTransactionDAO.when(EncryptedTransactionDAO::create).thenReturn(mock(EncryptedTransactionDAO.class));
        mockedStaticPrivacyHelper.when(PrivacyHelper::create).thenReturn(mock(PrivacyHelper.class));
        mockedStaticResendManager.when(ResendManager::create).thenReturn(mock(ResendManager.class));
        mockedStaticPayloadDigest.when(PayloadDigest::create).thenReturn(mock(PayloadDigest.class));
        TransactionManager transactionManager = TransactionManagerProvider.provider();
        assertThat(transactionManager).isNotNull();
        assertThat(TransactionManagerProvider.provider()).describedAs("Second invocation should return same instance").isSameAs(transactionManager);
        mockedStaticEncryptedTransactionDAO.verify(EncryptedTransactionDAO::create);
        mockedStaticEncryptedTransactionDAO.verifyNoMoreInteractions();
        mockedStaticEnclave.verify(Enclave::create);
        mockedStaticEnclave.verifyNoMoreInteractions();
        mockedStaticEncryptedRawTransactionDAO.verify(EncryptedRawTransactionDAO::create);
        mockedStaticEncryptedRawTransactionDAO.verifyNoMoreInteractions();
        mockedStaticPayloadPublisher.verify(PayloadPublisher::create);
        mockedStaticPayloadPublisher.verifyNoMoreInteractions();
        mockedStaticBatchPayloadPublisher.verify(BatchPayloadPublisher::create);
        mockedStaticBatchPayloadPublisher.verifyNoMoreInteractions();
        mockedStaticPrivacyHelper.verify(PrivacyHelper::create);
        mockedStaticPrivacyHelper.verifyNoMoreInteractions();
        mockedStaticResendManager.verify(ResendManager::create);
        mockedStaticResendManager.verifyNoMoreInteractions();
        mockedStaticPayloadDigest.verify(PayloadDigest::create);
        mockedStaticPayloadDigest.verifyNoMoreInteractions();
    }
}
Also used : ResendManager(com.quorum.tessera.transaction.resend.ResendManager) BatchPayloadPublisher(com.quorum.tessera.transaction.publish.BatchPayloadPublisher) PayloadPublisher(com.quorum.tessera.transaction.publish.PayloadPublisher) BatchPayloadPublisher(com.quorum.tessera.transaction.publish.BatchPayloadPublisher) Config(com.quorum.tessera.config.Config) EncryptedRawTransactionDAO(com.quorum.tessera.data.EncryptedRawTransactionDAO) Enclave(com.quorum.tessera.enclave.Enclave) PayloadDigest(com.quorum.tessera.enclave.PayloadDigest) TransactionManager(com.quorum.tessera.transaction.TransactionManager) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 14 with ConfigFactory

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

the class StagingTransactionUtilsTest method beforeTest.

@Before
public void beforeTest() {
    Config config = mock(Config.class);
    when(config.getClientMode()).thenReturn(clientMode);
    configFactory = mock(ConfigFactory.class);
    when(configFactory.getConfig()).thenReturn(config);
    configFactoryMockedStatic = mockStatic(ConfigFactory.class);
    configFactoryMockedStatic.when(ConfigFactory::create).thenReturn(configFactory);
    payloadDigest = PayloadDigest.create();
    assertThat(payloadDigest).isExactlyInstanceOf(DIGEST_LOOKUP.get(clientMode));
}
Also used : Config(com.quorum.tessera.config.Config) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Before(org.junit.Before)

Example 15 with ConfigFactory

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

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