Search in sources :

Example 1 with RestClientFactory

use of com.quorum.tessera.context.RestClientFactory in project tessera by ConsenSys.

the class RuntimeContextProviderTest method provides.

@Test
public void provides() {
    Config confg = createMockConfig();
    try (var mockedStaticConfigFactory = mockStatic(ConfigFactory.class);
        var mockStaticRestClientFactory = mockStatic(RestClientFactory.class);
        var mockStaticKeyDataUtil = mockStatic(KeyDataUtil.class);
        var mockStaticEnclave = mockStatic(Enclave.class)) {
        Enclave enclave = mock(Enclave.class);
        mockStaticEnclave.when(Enclave::create).thenReturn(enclave);
        ConfigKeyPair configKeyPair = mock(ConfigKeyPair.class);
        when(configKeyPair.getPublicKey()).thenReturn(Base64.getEncoder().encodeToString("PublicKey".getBytes()));
        when(configKeyPair.getPrivateKey()).thenReturn(Base64.getEncoder().encodeToString("PrivateKey".getBytes()));
        mockStaticKeyDataUtil.when(() -> KeyDataUtil.unmarshal(any(KeyData.class), any(KeyEncryptor.class))).thenReturn(configKeyPair);
        RestClientFactory restClientFactory = mock(RestClientFactory.class);
        when(restClientFactory.buildFrom(any(ServerConfig.class))).thenReturn(mock(Client.class));
        mockStaticRestClientFactory.when(RestClientFactory::create).thenReturn(restClientFactory);
        ConfigFactory configFactory = mock(ConfigFactory.class);
        when(configFactory.getConfig()).thenReturn(confg);
        mockedStaticConfigFactory.when(ConfigFactory::create).thenReturn(configFactory);
        RuntimeContext runtimeContext = RuntimeContextProvider.provider();
        assertThat(runtimeContext).isNotNull().isSameAs(RuntimeContextProvider.provider());
        mockedStaticConfigFactory.verify(ConfigFactory::create);
        mockedStaticConfigFactory.verifyNoMoreInteractions();
        mockStaticRestClientFactory.verify(RestClientFactory::create);
        mockedStaticConfigFactory.verifyNoMoreInteractions();
        mockStaticKeyDataUtil.verify(() -> KeyDataUtil.unmarshal(any(KeyData.class), any(KeyEncryptor.class)));
        mockStaticKeyDataUtil.verifyNoMoreInteractions();
        mockStaticEnclave.verify(Enclave::create);
        mockStaticEnclave.verifyNoMoreInteractions();
        verify(enclave).getPublicKeys();
        verifyNoMoreInteractions(enclave);
    }
}
Also used : Enclave(com.quorum.tessera.enclave.Enclave) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) RestClientFactory(com.quorum.tessera.context.RestClientFactory) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Client(jakarta.ws.rs.client.Client) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Test(org.junit.Test)

Aggregations

ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)1 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)1 RestClientFactory (com.quorum.tessera.context.RestClientFactory)1 RuntimeContext (com.quorum.tessera.context.RuntimeContext)1 Enclave (com.quorum.tessera.enclave.Enclave)1 Client (jakarta.ws.rs.client.Client)1 Test (org.junit.Test)1