Skip to content

Commit

Permalink
applying spotless Java check
Browse files Browse the repository at this point in the history
Signed-off-by: fahadshamiinsta <[email protected]>
  • Loading branch information
fahadshamiinsta committed Jan 11, 2024
1 parent 5f991c8 commit 6fb32ef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public GoogleCredentials get() {
try {
credentials = SocketAccess.doPrivilegedIOException(GoogleCredentials::getApplicationDefault);
} catch (IOException e) {
logger.error("Failed to retrieve \"Application Default Credentials\"",e);
logger.error("Failed to retrieve \"Application Default Credentials\"", e);
}
return credentials;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public GoogleCloudStorageService() {
public GoogleCloudStorageService(GoogleApplicationDefaultCredentials googleApplicationDefaultCredentials) {
this.googleApplicationDefaultCredentials = googleApplicationDefaultCredentials;
}

/**
* Refreshes the client settings and clears the client cache. Subsequent calls to
* {@code GoogleCloudStorageService#client} will return new clients constructed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@
import com.google.cloud.http.HttpTransportOptions;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import org.hamcrest.MatcherAssert;
import org.mockito.Mockito;
import org.opensearch.common.settings.MockSecureSettings;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.test.OpenSearchTestCase;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;

import java.io.IOException;
Expand All @@ -58,6 +57,8 @@
import java.util.Locale;
import java.util.UUID;

import org.mockito.Mockito;

import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -221,9 +222,9 @@ public void testApplicationDefaultCredential() throws Exception {
Mockito.when(mockDefaultCredentials.get()).thenReturn(mockGoogleCredentials);

GoogleCloudStorageService service = new GoogleCloudStorageService(mockDefaultCredentials);
StorageOptions storageOptions = service.createStorageOptions(settings,mockHttpTransportOptions);
StorageOptions storageOptions = service.createStorageOptions(settings, mockHttpTransportOptions);
assertNotNull(storageOptions);
assertEquals(storageOptions.getCredentials().toString(),mockGoogleCredentials.toString());
assertEquals(storageOptions.getCredentials().toString(), mockGoogleCredentials.toString());
}

/**
Expand All @@ -235,12 +236,12 @@ public void applicationDefaultCredentialThrowsErrorWhenNotAvailable() throws Exc
GoogleCloudStorageClientSettings settings = getGCSClientSettingsWithoutCredentials();
HttpTransportOptions mockHttpTransportOptions = Mockito.mock(HttpTransportOptions.class);
GoogleCloudStorageService service = new GoogleCloudStorageService();
StorageOptions storageOptions = service.createStorageOptions(settings,mockHttpTransportOptions);
StorageOptions storageOptions = service.createStorageOptions(settings, mockHttpTransportOptions);

Exception exception = assertThrows(IOException.class, GoogleCredentials::getApplicationDefault);
assertNotNull(storageOptions);
assertNull(storageOptions.getCredentials());
MatcherAssert.assertThat(exception.getMessage(),containsString("The Application Default Credentials are not available"));
MatcherAssert.assertThat(exception.getMessage(), containsString("The Application Default Credentials are not available"));
}

private GoogleCloudStorageClientSettings getGCSClientSettingsWithoutCredentials() throws URISyntaxException {
Expand All @@ -252,7 +253,8 @@ private GoogleCloudStorageClientSettings getGCSClientSettingsWithoutCredentials(
readTimeValue,
applicationName,
new URI(""),
new ProxySettings(Proxy.Type.DIRECT, null, 0, null, null));
new ProxySettings(Proxy.Type.DIRECT, null, 0, null, null)
);
}

}

0 comments on commit 6fb32ef

Please sign in to comment.