Search in sources :

Example 6 with Config

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

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

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

the class ConfigHolderTest method setGetConfig.

@Test
public void setGetConfig() {
    ConfigHolder hdler = ConfigHolder.INSTANCE;
    Config config = mock(Config.class);
    hdler.setConfig(config);
    assertThat(hdler.getConfig()).isSameAs(config);
}
Also used : Config(com.quorum.tessera.config.Config) Test(org.junit.Test)

Example 9 with Config

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

the class ConfigFileStoreTest method save.

@Test
public void save() throws IOException {
    Config config = new Config();
    config.setJdbcConfig(new JdbcConfig());
    config.getJdbcConfig().setUsername("JUNIT");
    configFileStore.save(config);
    Config result = JaxbUtil.unmarshal(Files.newInputStream(path), Config.class);
    assertThat(result.getJdbcConfig().getUsername()).isEqualTo("JUNIT");
}
Also used : JdbcConfig(com.quorum.tessera.config.JdbcConfig) Config(com.quorum.tessera.config.Config) JdbcConfig(com.quorum.tessera.config.JdbcConfig) Test(org.junit.Test)

Example 10 with Config

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

the class PayloadDigest method create.

static PayloadDigest create() {
    Config config = ConfigFactory.create().getConfig();
    // FIXME:
    final Class implType;
    if (config.getClientMode() == ClientMode.ORION) {
        implType = SHA512256PayloadDigest.class;
    } else {
        implType = DefaultPayloadDigest.class;
    }
    return ServiceLoader.load(PayloadDigest.class).stream().filter(payloadDigestProvider -> payloadDigestProvider.type() == implType).map(ServiceLoader.Provider::get).findFirst().get();
}
Also used : ClientMode(com.quorum.tessera.config.ClientMode) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Config(com.quorum.tessera.config.Config) ServiceLoader(java.util.ServiceLoader) Config(com.quorum.tessera.config.Config)

Aggregations

Config (com.quorum.tessera.config.Config)78 Test (org.junit.Test)54 ServerConfig (com.quorum.tessera.config.ServerConfig)20 ConfigFactory (com.quorum.tessera.config.ConfigFactory)18 Path (java.nio.file.Path)11 Before (org.junit.Before)11 ResidentGroup (com.quorum.tessera.config.ResidentGroup)9 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)9 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)9 Client (jakarta.ws.rs.client.Client)9 JdbcConfig (com.quorum.tessera.config.JdbcConfig)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 After (org.junit.After)7 CommandLine (picocli.CommandLine)7 PrivacyViolationException (com.quorum.tessera.transaction.exception.PrivacyViolationException)6 CliResult (com.quorum.tessera.cli.CliResult)5 EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)5 PublicKey (com.quorum.tessera.encryption.PublicKey)5