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);
}
}
Aggregations