Search in sources :

Example 16 with ConfigFactory

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);
    }
}
Also used : Config(com.quorum.tessera.config.Config) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 17 with ConfigFactory

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();
    }
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) PayloadPublisher(com.quorum.tessera.transaction.publish.PayloadPublisher) Config(com.quorum.tessera.config.Config) ServerConfig(com.quorum.tessera.config.ServerConfig) Discovery(com.quorum.tessera.discovery.Discovery) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 18 with ConfigFactory

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();
    }
}
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 19 with ConfigFactory

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);
}
Also used : ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 20 with ConfigFactory

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();
}
Also used : Config(com.quorum.tessera.config.Config) ConfigFactory(com.quorum.tessera.config.ConfigFactory) ServiceLoader(java.util.ServiceLoader) 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