use of com.quorum.tessera.config.ConfigFactory in project tessera by ConsenSys.
the class Q2TRestAppTest method getSingletonsOrionClientMode.
@Test
public void getSingletonsOrionClientMode() {
Config config = mock(Config.class);
when(config.getClientMode()).thenReturn(ClientMode.ORION);
ConfigFactory configFactory = mock(ConfigFactory.class);
when(configFactory.getConfig()).thenReturn(config);
try (var configFactoryMockedStatic = mockStatic(ConfigFactory.class)) {
configFactoryMockedStatic.when(ConfigFactory::create).thenReturn(configFactory);
Set<Object> results = q2TRestApp.getSingletons();
assertThat(results).hasSize(4);
List<Class> types = results.stream().map(Object::getClass).collect(Collectors.toList());
assertThat(types).containsExactlyInAnyOrder(BesuTransactionResource.class, UpCheckResource.class, PrivacyGroupResource.class, RawTransactionResource.class);
}
}
use of com.quorum.tessera.config.ConfigFactory in project tessera by ConsenSys.
the class PayloadPublisherProviderTest method provider.
@Test
public void provider() {
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);
try (var configFactoryMockedStatic = mockStatic(ConfigFactory.class);
var discoveryMockedStatic = mockStatic(Discovery.class)) {
configFactoryMockedStatic.when(ConfigFactory::create).thenReturn(configFactory);
discoveryMockedStatic.when(Discovery::create).thenReturn(mock(Discovery.class));
PayloadPublisher payloadPublisher = PayloadPublisherProvider.provider();
assertThat(payloadPublisher).isNotNull();
configFactoryMockedStatic.verify(ConfigFactory::create);
configFactoryMockedStatic.verifyNoMoreInteractions();
discoveryMockedStatic.verify(Discovery::create);
discoveryMockedStatic.verifyNoMoreInteractions();
}
}
use of com.quorum.tessera.config.ConfigFactory in project tessera by ConsenSys.
the class RecoveryClientProviderTest 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));
RecoveryClient recoveryClient = RecoveryClientProvider.provider();
assertThat(recoveryClient).isNotNull().isExactlyInstanceOf(RestRecoveryClient.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 ConfigFactoryProviderTest method createConfigFactoryFromServiceLoader.
@Test
public void createConfigFactoryFromServiceLoader() {
ConfigFactory configFactory = ServiceLoader.load(ConfigFactory.class).findFirst().get();
assertThat(configFactory).isNotNull().isExactlyInstanceOf(JaxbConfigFactory.class);
}
use of com.quorum.tessera.config.ConfigFactory in project tessera by ConsenSys.
the class PayloadDigestTest method create.
@Test
public void create() {
ServiceLoader<PayloadDigest> serviceLoader = mock(ServiceLoader.class);
Stream<ServiceLoader.Provider<PayloadDigest>> providerStream = Stream.of(DefaultPayloadDigest.class, SHA512256PayloadDigest.class).map(type -> new ServiceLoader.Provider<PayloadDigest>() {
@Override
public Class<? extends PayloadDigest> type() {
return type;
}
@Override
public PayloadDigest get() {
return mock(type);
}
});
when(serviceLoader.stream()).thenReturn(providerStream);
Config config = mock(Config.class);
when(config.getClientMode()).thenReturn(clientMode);
ConfigFactory configFactory = mock(ConfigFactory.class);
when(configFactory.getConfig()).thenReturn(config);
PayloadDigest result;
try (var serviceLoaderMockedStatic = mockStatic(ServiceLoader.class);
var configFactoryMockedStatic = mockStatic(ConfigFactory.class)) {
serviceLoaderMockedStatic.when(() -> ServiceLoader.load(PayloadDigest.class)).thenReturn(serviceLoader);
configFactoryMockedStatic.when(ConfigFactory::create).thenReturn(configFactory);
result = PayloadDigest.create();
serviceLoaderMockedStatic.verify(() -> ServiceLoader.load(PayloadDigest.class));
serviceLoaderMockedStatic.verifyNoMoreInteractions();
configFactoryMockedStatic.verify(ConfigFactory::create);
configFactoryMockedStatic.verifyNoMoreInteractions();
}
assertThat(result).isExactlyInstanceOf(digestType).isNotNull();
}
Aggregations