Search in sources :

Example 1 with EnclaveClient

use of com.quorum.tessera.enclave.EnclaveClient 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 2 with EnclaveClient

use of com.quorum.tessera.enclave.EnclaveClient in project tessera by ConsenSys.

the class EnclaveClientProvider method provider.

public static EnclaveClient provider() {
    Config config = ConfigFactory.create().getConfig();
    LOGGER.debug("Creating RestfulEnclaveClient with {}", config);
    Optional<ServerConfig> enclaveServerConfig = config.getServerConfigs().stream().filter(sc -> sc.getApp() == AppType.ENCLAVE).findAny();
    final ClientFactory clientFactory = new ClientFactory();
    LOGGER.debug("Creating server context from config");
    ServerConfig serverConfig = enclaveServerConfig.get();
    LOGGER.debug("Created server context from config");
    Client client = clientFactory.buildFrom(serverConfig);
    LOGGER.info("Creating remoted enclave for {}", serverConfig.getServerUri());
    return new RestfulEnclaveClient(client, serverConfig.getServerUri());
}
Also used : EnclaveClient(com.quorum.tessera.enclave.EnclaveClient) Client(jakarta.ws.rs.client.Client) Logger(org.slf4j.Logger) com.quorum.tessera.config(com.quorum.tessera.config) LoggerFactory(org.slf4j.LoggerFactory) Optional(java.util.Optional) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) EnclaveClient(com.quorum.tessera.enclave.EnclaveClient) Client(jakarta.ws.rs.client.Client)

Aggregations

EnclaveClient (com.quorum.tessera.enclave.EnclaveClient)2 com.quorum.tessera.config (com.quorum.tessera.config)1 ConfigFactory (com.quorum.tessera.config.ConfigFactory)1 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)1 Client (jakarta.ws.rs.client.Client)1 Optional (java.util.Optional)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1