Skip to content

Commit e847668

Browse files
author
Frank Natividad
committed
Adding Integration tests and partial unit test coverage
1 parent 031b102 commit e847668

File tree

9 files changed

+155
-37
lines changed

9 files changed

+155
-37
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ public static BlobSourceOption decryptionKey(String key) {
184184
* Returns an option for blob's billing user project. This option is used only if the blob's
185185
* bucket has requester_pays flag enabled.
186186
*/
187-
@GcpLaunchStage.Alpha
188187
public static BlobSourceOption userProject(String userProject) {
189188
return new BlobSourceOption(StorageRpc.Option.USER_PROJECT, userProject);
190189
}
@@ -404,8 +403,8 @@ Builder setCustomerEncryption(CustomerEncryption customerEncryption) {
404403
}
405404

406405
@Override
407-
Builder setKmsKey(String kmsKey) {
408-
infoBuilder.setKmsKey(kmsKey);
406+
public Builder setKmsKeyName(String kmsKeyName) {
407+
infoBuilder.setKmsKeyName(kmsKeyName);
409408
return this;
410409
}
411410

google-cloud-storage/src/main/java/com/google/cloud/storage/BlobInfo.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public StorageObject apply(BlobInfo blobInfo) {
8383
private final Integer componentCount;
8484
private final boolean isDirectory;
8585
private final CustomerEncryption customerEncryption;
86-
private final String kmsKey;
86+
private final String kmsKeyName;
8787

8888
/**
8989
* This class is meant for internal use only. Users are discouraged from using this class.
@@ -267,7 +267,11 @@ public abstract static class Builder {
267267

268268
abstract Builder setCustomerEncryption(CustomerEncryption customerEncryption);
269269

270-
abstract Builder setKmsKey(String kmsKey);
270+
/**
271+
*
272+
* Sets the blob's kmsKeyName.
273+
*/
274+
public abstract Builder setKmsKeyName(String kmsKeyName);
271275

272276
/**
273277
* Creates a {@code BlobInfo} object.
@@ -301,7 +305,7 @@ static final class BuilderImpl extends Builder {
301305
private Boolean isDirectory;
302306
private CustomerEncryption customerEncryption;
303307
private StorageClass storageClass;
304-
private String kmsKey;
308+
private String kmsKeyName;
305309

306310
BuilderImpl(BlobId blobId) {
307311
this.blobId = blobId;
@@ -332,7 +336,7 @@ static final class BuilderImpl extends Builder {
332336
createTime = blobInfo.createTime;
333337
isDirectory = blobInfo.isDirectory;
334338
storageClass = blobInfo.storageClass;
335-
kmsKey = blobInfo.kmsKey;
339+
kmsKeyName = blobInfo.kmsKeyName;
336340
}
337341

338342
@Override
@@ -481,8 +485,8 @@ Builder setCustomerEncryption(CustomerEncryption customerEncryption) {
481485
}
482486

483487
@Override
484-
Builder setKmsKey(String kmsKey) {
485-
this.kmsKey = kmsKey;
488+
public Builder setKmsKeyName(String kmsKeyName) {
489+
this.kmsKeyName = kmsKeyName;
486490
return this;
487491
}
488492

@@ -518,7 +522,7 @@ public BlobInfo build() {
518522
createTime = builder.createTime;
519523
isDirectory = firstNonNull(builder.isDirectory, Boolean.FALSE);
520524
storageClass = builder.storageClass;
521-
kmsKey = builder.kmsKey;
525+
kmsKeyName = builder.kmsKeyName;
522526
}
523527

524528
/**
@@ -752,8 +756,8 @@ public StorageClass getStorageClass() {
752756
/**
753757
* Returns the Cloud KMS key used to encrypt the blob, if any.
754758
*/
755-
public String getKmsKey() {
756-
return kmsKey;
759+
public String getKmsKeyName() {
760+
return kmsKeyName;
757761
}
758762

759763
/**
@@ -828,8 +832,8 @@ public ObjectAccessControl apply(Acl acl) {
828832
if (customerEncryption != null) {
829833
storageObject.setCustomerEncryption(customerEncryption.toPb());
830834
}
831-
if (kmsKey != null) {
832-
storageObject.setKmsKeyName(kmsKey);
835+
if (kmsKeyName != null) {
836+
storageObject.setKmsKeyName(kmsKeyName);
833837
}
834838
storageObject.setMetadata(pbMetadata);
835839
storageObject.setCacheControl(cacheControl);
@@ -962,7 +966,7 @@ public Acl apply(ObjectAccessControl objectAccessControl) {
962966
builder.setStorageClass(StorageClass.valueOf(storageObject.getStorageClass()));
963967
}
964968
if (storageObject.getKmsKeyName() != null) {
965-
builder.setKmsKey(storageObject.getKmsKeyName());
969+
builder.setKmsKeyName(storageObject.getKmsKeyName());
966970
}
967971
return builder.build();
968972
}

google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public static BucketSourceOption metagenerationNotMatch() {
118118
* Returns an option for blob's billing user project. This option is only used by the buckets with
119119
* 'requester_pays' flag.
120120
*/
121-
@GcpLaunchStage.Alpha
122121
public static BucketSourceOption userProject(String userProject) {
123122
return new BucketSourceOption(StorageRpc.Option.USER_PROJECT, userProject);
124123
}
@@ -271,7 +270,6 @@ public static BlobTargetOption encryptionKey(String key) {
271270
* Returns an option for blob's billing user project. This option is only used by the buckets with
272271
* 'requester_pays' flag.
273272
*/
274-
@GcpLaunchStage.Alpha
275273
public static BlobTargetOption userProject(String userProject) {
276274
return new BlobTargetOption(StorageRpc.Option.USER_PROJECT, userProject);
277275
}
@@ -468,7 +466,6 @@ public static BlobWriteOption encryptionKey(String key) {
468466
* Returns an option for blob's billing user project. This option is only used by the buckets with
469467
* 'requester_pays' flag.
470468
*/
471-
@GcpLaunchStage.Alpha
472469
public static BlobWriteOption userProject(String userProject) {
473470
return new BlobWriteOption(Storage.BlobWriteOption.Option.USER_PROJECT, userProject);
474471
}

google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,9 +880,9 @@ public Rule apply(DeleteRule deleteRule) {
880880
if (labels != null) {
881881
bucketPb.setLabels(labels);
882882
}
883-
if (defaultKmsKeyName != null) {
884-
bucketPb.setEncryption(new Encryption().setDefaultKmsKeyName(defaultKmsKeyName));
885-
}
883+
// default kms key name can be null.
884+
bucketPb.setEncryption(new Encryption().setDefaultKmsKeyName(defaultKmsKeyName));
885+
886886
return bucketPb;
887887
}
888888

google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ enum BucketField implements FieldSelector {
9494
CORS("cors"),
9595
STORAGE_CLASS("storageClass"),
9696
ETAG("etag"),
97-
@GcpLaunchStage.Alpha
97+
DEFAULT_KMS_KEY_NAME("defaultKmsKeyName"),
9898
BILLING("billing");
9999

100100
static final List<? extends FieldSelector> REQUIRED_FIELDS = ImmutableList.of(NAME);
@@ -136,6 +136,7 @@ enum BlobField implements FieldSelector {
136136
SIZE("size"),
137137
STORAGE_CLASS("storageClass"),
138138
TIME_DELETED("timeDeleted"),
139+
KMS_KEY_NAME("kmsKeyName"),
139140
UPDATED("updated");
140141

141142
static final List<? extends FieldSelector> REQUIRED_FIELDS = ImmutableList.of(BUCKET, NAME);
@@ -203,7 +204,6 @@ public static BucketTargetOption metagenerationNotMatch() {
203204
* Returns an option to define the billing user project. This option is required by buckets with
204205
* `requester_pays` flag enabled to assign operation costs.
205206
*/
206-
@GcpLaunchStage.Alpha
207207
public static BucketTargetOption userProject(String userProject) {
208208
return new BucketTargetOption(StorageRpc.Option.USER_PROJECT, userProject);
209209
}
@@ -240,7 +240,6 @@ public static BucketSourceOption metagenerationNotMatch(long metageneration) {
240240
* Returns an option for bucket's billing user project. This option is only used by the buckets with
241241
* 'requester_pays' flag.
242242
*/
243-
@GcpLaunchStage.Alpha
244243
public static BucketSourceOption userProject(String userProject) {
245244
return new BucketSourceOption(StorageRpc.Option.USER_PROJECT, userProject);
246245
}
@@ -281,7 +280,6 @@ public static BucketGetOption metagenerationNotMatch(long metageneration) {
281280
* Returns an option for bucket's billing user project. This option is only used by the buckets with
282281
* 'requester_pays' flag.
283282
*/
284-
@GcpLaunchStage.Alpha
285283
public static BucketGetOption userProject(String userProject) {
286284
return new BucketGetOption(StorageRpc.Option.USER_PROJECT, userProject);
287285
}
@@ -372,7 +370,6 @@ public static BlobTargetOption encryptionKey(Key key) {
372370
* Returns an option for blob's billing user project. This option is only used by the buckets with
373371
* 'requester_pays' flag.
374372
*/
375-
@GcpLaunchStage.Alpha
376373
public static BlobTargetOption userProject(String userProject) {
377374
return new BlobTargetOption(StorageRpc.Option.USER_PROJECT, userProject);
378375
}
@@ -542,7 +539,6 @@ public static BlobWriteOption encryptionKey(String key) {
542539
* Returns an option for blob's billing user project. This option is only used by the buckets with
543540
* 'requester_pays' flag.
544541
*/
545-
@GcpLaunchStage.Alpha
546542
public static BlobWriteOption userProject(String userProject) {
547543
return new BlobWriteOption(Option.USER_PROJECT, userProject);
548544
}
@@ -636,7 +632,6 @@ public static BlobSourceOption decryptionKey(String key) {
636632
* Returns an option for blob's billing user project. This option is only used by the buckets with
637633
* 'requester_pays' flag.
638634
*/
639-
@GcpLaunchStage.Alpha
640635
public static BlobSourceOption userProject(String userProject) {
641636
return new BlobSourceOption(StorageRpc.Option.USER_PROJECT, userProject);
642637
}
@@ -726,7 +721,6 @@ public static BlobGetOption fields(BlobField... fields) {
726721
* Returns an option for blob's billing user project. This option is only used by the buckets with
727722
* 'requester_pays' flag.
728723
*/
729-
@GcpLaunchStage.Alpha
730724
public static BlobGetOption userProject(String userProject) {
731725
return new BlobGetOption(StorageRpc.Option.USER_PROJECT, userProject);
732726
}
@@ -769,7 +763,6 @@ public static BucketListOption prefix(String prefix) {
769763
* Returns an option for bucket's billing user project. This option is only used by the buckets with
770764
* 'requester_pays' flag.
771765
*/
772-
@GcpLaunchStage.Alpha
773766
public static BucketListOption userProject(String userProject) {
774767
return new BucketListOption(StorageRpc.Option.USER_PROJECT, userProject);
775768
}
@@ -840,7 +833,6 @@ public static BlobListOption currentDirectory() {
840833
*
841834
* @param userProject projectId of the billing user project.
842835
*/
843-
@GcpLaunchStage.Alpha
844836
public static BlobListOption userProject(String userProject) {
845837
return new BlobListOption(StorageRpc.Option.USER_PROJECT, userProject);
846838
}
@@ -2587,8 +2579,6 @@ public static Builder newBuilder() {
25872579
* @param options extra parameters to apply to this operation
25882580
* @throws StorageException upon failure
25892581
*/
2590-
@BetaApi
2591-
@GcpLaunchStage.Alpha
25922582
Policy getIamPolicy(String bucket, BucketSourceOption... options);
25932583

25942584
/**
@@ -2612,8 +2602,6 @@ public static Builder newBuilder() {
26122602
* @param options extra parameters to apply to this operation
26132603
* @throws StorageException upon failure
26142604
*/
2615-
@BetaApi
2616-
@GcpLaunchStage.Alpha
26172605
Policy setIamPolicy(String bucket, Policy policy, BucketSourceOption... options);
26182606

26192607
/**
@@ -2637,8 +2625,6 @@ public static Builder newBuilder() {
26372625
* @param options extra parameters to apply to this operation
26382626
* @throws StorageException upon failure
26392627
*/
2640-
@BetaApi
2641-
@GcpLaunchStage.Alpha
26422628
List<Boolean> testIamPermissions(String bucket, List<String> permissions, BucketSourceOption... options);
26432629

26442630
/**

google-cloud-storage/src/test/java/com/google/cloud/storage/BlobInfoTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ public class BlobInfoTest {
6666
private static final String KEY_SHA256 = "keySha";
6767
private static final CustomerEncryption CUSTOMER_ENCRYPTION =
6868
new CustomerEncryption(ENCRYPTION_ALGORITHM, KEY_SHA256);
69+
private static final String KMS_KEY_NAME = "projects/p/keyRings/kr/location/kr-loc/cryptoKey/key";
6970
private static final StorageClass STORAGE_CLASS = StorageClass.COLDLINE;
7071

72+
// Unit tests include Customer Supplied encryption which may be confusing with the KMS KEY NAME
73+
// as both can't be set at the same time. At least not right now.
7174
private static final BlobInfo BLOB_INFO = BlobInfo.newBuilder("b", "n", GENERATION)
7275
.setAcl(ACL)
7376
.setComponentCount(COMPONENT_COUNT)
@@ -91,6 +94,7 @@ public class BlobInfoTest {
9194
.setUpdateTime(UPDATE_TIME)
9295
.setCreateTime(CREATE_TIME)
9396
.setStorageClass(STORAGE_CLASS)
97+
.setKmsKeyName(KMS_KEY_NAME)
9498
.build();
9599
private static final BlobInfo DIRECTORY_INFO = BlobInfo.newBuilder("b", "n/")
96100
.setSize(0L)
@@ -153,6 +157,7 @@ public void testBuilder() {
153157
assertEquals(UPDATE_TIME, BLOB_INFO.getUpdateTime());
154158
assertEquals(CREATE_TIME, BLOB_INFO.getCreateTime());
155159
assertEquals(STORAGE_CLASS, BLOB_INFO.getStorageClass());
160+
assertEquals(KMS_KEY_NAME, BLOB_INFO.getKmsKeyName());
156161
assertFalse(BLOB_INFO.isDirectory());
157162
assertEquals("b", DIRECTORY_INFO.getBucket());
158163
assertEquals("n/", DIRECTORY_INFO.getName());
@@ -208,6 +213,7 @@ private void compareBlobs(BlobInfo expected, BlobInfo value) {
208213
assertEquals(expected.getSize(), value.getSize());
209214
assertEquals(expected.getUpdateTime(), value.getUpdateTime());
210215
assertEquals(expected.getStorageClass(), value.getStorageClass());
216+
assertEquals(expected.getKmsKeyName(), value.getKmsKeyName());
211217
}
212218

213219
private void compareCustomerEncryptions(CustomerEncryption expected, CustomerEncryption value) {
@@ -255,6 +261,7 @@ public void testToPbAndFromPb() {
255261
assertEquals(0L, (long) blobInfo.getSize());
256262
assertNull(blobInfo.getUpdateTime());
257263
assertNull(blobInfo.getStorageClass());
264+
assertNull(blobInfo.getKmsKeyName());
258265
assertTrue(blobInfo.isDirectory());
259266
}
260267

google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class BucketInfoTest {
6060
private static final String NOT_FOUND_PAGE = "error.html";
6161
private static final String LOCATION = "ASIA";
6262
private static final StorageClass STORAGE_CLASS = StorageClass.STANDARD;
63+
private static final String DEFAULT_KMS_KEY_NAME = "projects/p/keyRings/kr/location/kr-loc/cryptoKey/key";
6364
private static final Boolean VERSIONING_ENABLED = true;
6465
private static final Map<String, String> BUCKET_LABELS = ImmutableMap.of("label1", "value1");
6566
private static final Boolean REQUESTER_PAYS = true;
@@ -81,6 +82,7 @@ public class BucketInfoTest {
8182
.setVersioningEnabled(VERSIONING_ENABLED)
8283
.setLabels(BUCKET_LABELS)
8384
.setRequesterPays(REQUESTER_PAYS)
85+
.setDefaultKmsKeyName(DEFAULT_KMS_KEY_NAME)
8486
.build();
8587

8688
@Test
@@ -122,6 +124,7 @@ public void testBuilder() {
122124
assertEquals(NOT_FOUND_PAGE, BUCKET_INFO.getNotFoundPage());
123125
assertEquals(LOCATION, BUCKET_INFO.getLocation());
124126
assertEquals(STORAGE_CLASS, BUCKET_INFO.getStorageClass());
127+
assertEquals(DEFAULT_KMS_KEY_NAME, BUCKET_INFO.getDefaultKmsKeyName());
125128
assertEquals(VERSIONING_ENABLED, BUCKET_INFO.versioningEnabled());
126129
assertEquals(BUCKET_LABELS, BUCKET_INFO.getLabels());
127130
assertEquals(REQUESTER_PAYS, BUCKET_INFO.requesterPays());
@@ -151,6 +154,7 @@ private void compareBuckets(BucketInfo expected, BucketInfo value) {
151154
assertEquals(expected.getNotFoundPage(), value.getNotFoundPage());
152155
assertEquals(expected.getLocation(), value.getLocation());
153156
assertEquals(expected.getStorageClass(), value.getStorageClass());
157+
assertEquals(expected.getDefaultKmsKeyName(), value.getDefaultKmsKeyName());
154158
assertEquals(expected.versioningEnabled(), value.versioningEnabled());
155159
assertEquals(expected.getLabels(), value.getLabels());
156160
assertEquals(expected.requesterPays(), value.requesterPays());

google-cloud-storage/src/test/java/com/google/cloud/storage/BucketTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class BucketTest {
7777
private static final String NOT_FOUND_PAGE = "error.html";
7878
private static final String LOCATION = "ASIA";
7979
private static final StorageClass STORAGE_CLASS = StorageClass.STANDARD;
80+
private static final String DEFAULT_KMS_KEY_NAME = "projects/p/keyRings/kr/location/kr-loc/cryptoKey/key";
8081
private static final Boolean VERSIONING_ENABLED = true;
8182
private static final Map<String, String> BUCKET_LABELS = ImmutableMap.of("label1", "value1");
8283
private static final Boolean REQUESTER_PAYS = true;
@@ -96,6 +97,7 @@ public class BucketTest {
9697
.setNotFoundPage(NOT_FOUND_PAGE)
9798
.setLocation(LOCATION)
9899
.setStorageClass(STORAGE_CLASS)
100+
.setDefaultKmsKeyName(DEFAULT_KMS_KEY_NAME)
99101
.setVersioningEnabled(VERSIONING_ENABLED)
100102
.setLabels(BUCKET_LABELS)
101103
.setRequesterPays(REQUESTER_PAYS)

0 commit comments

Comments
 (0)