mirror of
https://github.com/google/nomulus
synced 2026-05-30 11:36:39 +00:00
Restore global config after tests
Fix a couple more cases when caching related configs are changed. This does not fix all our problems with Gradle builds. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=228735790
This commit is contained in:
@@ -49,27 +49,37 @@ public class RequestFactoryModuleTest {
|
||||
@Test
|
||||
public void test_provideHttpRequestFactory_localhost() throws Exception {
|
||||
// Make sure that localhost creates a request factory with an initializer.
|
||||
boolean origIsLocal = RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal;
|
||||
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = true;
|
||||
HttpRequestFactory factory = RequestFactoryModule.provideHttpRequestFactory(googleCredential);
|
||||
HttpRequestInitializer initializer = factory.getInitializer();
|
||||
assertThat(initializer).isNotNull();
|
||||
HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost"));
|
||||
initializer.initialize(request);
|
||||
verifyZeroInteractions(googleCredential);
|
||||
try {
|
||||
HttpRequestFactory factory = RequestFactoryModule.provideHttpRequestFactory(googleCredential);
|
||||
HttpRequestInitializer initializer = factory.getInitializer();
|
||||
assertThat(initializer).isNotNull();
|
||||
HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost"));
|
||||
initializer.initialize(request);
|
||||
verifyZeroInteractions(googleCredential);
|
||||
} finally {
|
||||
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = origIsLocal;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_provideHttpRequestFactory_remote() throws Exception {
|
||||
// Make sure that example.com creates a request factory with the UNITTEST client id but no
|
||||
boolean origIsLocal = RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal;
|
||||
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = false;
|
||||
HttpRequestFactory factory = RequestFactoryModule.provideHttpRequestFactory(googleCredential);
|
||||
HttpRequestInitializer initializer = factory.getInitializer();
|
||||
assertThat(initializer).isNotNull();
|
||||
// HttpRequestFactory#buildGetRequest() calls initialize() once.
|
||||
HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost"));
|
||||
verify(googleCredential).initialize(request);
|
||||
assertThat(request.getConnectTimeout()).isEqualTo(REQUEST_TIMEOUT_MS);
|
||||
assertThat(request.getReadTimeout()).isEqualTo(REQUEST_TIMEOUT_MS);
|
||||
verifyNoMoreInteractions(googleCredential);
|
||||
try {
|
||||
HttpRequestFactory factory = RequestFactoryModule.provideHttpRequestFactory(googleCredential);
|
||||
HttpRequestInitializer initializer = factory.getInitializer();
|
||||
assertThat(initializer).isNotNull();
|
||||
// HttpRequestFactory#buildGetRequest() calls initialize() once.
|
||||
HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost"));
|
||||
verify(googleCredential).initialize(request);
|
||||
assertThat(request.getConnectTimeout()).isEqualTo(REQUEST_TIMEOUT_MS);
|
||||
assertThat(request.getReadTimeout()).isEqualTo(REQUEST_TIMEOUT_MS);
|
||||
verifyNoMoreInteractions(googleCredential);
|
||||
} finally {
|
||||
RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = origIsLocal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user