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();
}
}
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();
}
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();
}
}
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));
}
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();
}
}
Aggregations