|
43 | 43 | import com.example.storage.object.GenerateEncryptionKey; |
44 | 44 | import com.example.storage.object.GenerateV4GetObjectSignedUrl; |
45 | 45 | import com.example.storage.object.GenerateV4PutObjectSignedUrl; |
46 | | -import com.example.storage.object.GetObjectMetadata; |
47 | 46 | import com.example.storage.object.GetObjectContexts; |
| 47 | +import com.example.storage.object.GetObjectMetadata; |
48 | 48 | import com.example.storage.object.ListObjectContexts; |
49 | 49 | import com.example.storage.object.ListObjects; |
50 | 50 | import com.example.storage.object.ListObjectsWithOldVersions; |
|
68 | 68 | import com.google.cloud.storage.Blob; |
69 | 69 | import com.google.cloud.storage.BlobId; |
70 | 70 | import com.google.cloud.storage.BlobInfo; |
71 | | -import com.google.cloud.storage.BlobInfo.ObjectCustomContextPayload; |
72 | 71 | import com.google.cloud.storage.BlobInfo.ObjectContexts; |
| 72 | +import com.google.cloud.storage.BlobInfo.ObjectCustomContextPayload; |
73 | 73 | import com.google.cloud.storage.Bucket; |
74 | 74 | import com.google.cloud.storage.BucketInfo; |
75 | 75 | import com.google.cloud.storage.BucketInfo.IamConfiguration; |
@@ -638,69 +638,72 @@ public void testRestoreSoftDeletedObject() throws Exception { |
638 | 638 | } |
639 | 639 | } |
640 | 640 |
|
641 | | - @Test |
642 | | - public void testSetObjectContexts() throws Exception { |
643 | | - String blobName = generator.randomObjectName(); |
644 | | - String key = "test-key-get"; |
645 | | - String value = "test-value-get"; |
| 641 | + @Test |
| 642 | + public void testSetObjectContexts() throws Exception { |
| 643 | + String blobName = generator.randomObjectName(); |
| 644 | + String key = "test-key-get"; |
| 645 | + String value = "test-value-get"; |
646 | 646 |
|
647 | | - Blob initialBlob = storage.create(info(blobName), CONTENT, BlobTargetOption.doesNotExist()); |
| 647 | + Blob initialBlob = storage.create(info(blobName), CONTENT, BlobTargetOption.doesNotExist()); |
648 | 648 |
|
649 | | - SetObjectContexts.setObjectContexts( |
650 | | - GOOGLE_CLOUD_PROJECT, bucket.getName(), blobName, key, value); |
651 | | - String setOutput = stdOut.getCapturedOutputAsUtf8String(); |
652 | | - assertThat(setOutput).contains("Updated custom contexts for object " + blobName); |
| 649 | + SetObjectContexts.setObjectContexts( |
| 650 | + GOOGLE_CLOUD_PROJECT, bucket.getName(), blobName, key, value); |
| 651 | + String setOutput = stdOut.getCapturedOutputAsUtf8String(); |
| 652 | + assertThat(setOutput).contains("Updated custom contexts for object " + blobName); |
653 | 653 |
|
654 | | - Blob updatedBlob = storage.get(bucket.getName(), blobName); |
655 | | - assertThat(updatedBlob.getContexts().getCustom().get(key).getValue()).isEqualTo(value); |
656 | | - } |
| 654 | + Blob updatedBlob = storage.get(bucket.getName(), blobName); |
| 655 | + assertThat(updatedBlob.getContexts().getCustom().get(key).getValue()).isEqualTo(value); |
| 656 | + } |
657 | 657 |
|
658 | | - @Test |
659 | | - public void testGetObjectContexts() throws Exception { |
660 | | - String blobName = generator.randomObjectName(); |
661 | | - String key = "test-key-get"; |
662 | | - String value = "test-value-get"; |
| 658 | + @Test |
| 659 | + public void testGetObjectContexts() throws Exception { |
| 660 | + String blobName = generator.randomObjectName(); |
| 661 | + String key = "test-key-get"; |
| 662 | + String value = "test-value-get"; |
663 | 663 |
|
664 | | - storage.create(info(blobName), CONTENT, BlobTargetOption.doesNotExist()); |
| 664 | + storage.create(info(blobName), CONTENT, BlobTargetOption.doesNotExist()); |
665 | 665 |
|
666 | | - ObjectCustomContextPayload payload = |
667 | | - ObjectCustomContextPayload.newBuilder().setValue(value).build(); |
668 | | - Map<String, ObjectCustomContextPayload> custom = Maps.newHashMap(); |
669 | | - custom.put(key, payload); |
670 | | - ObjectContexts contexts = ObjectContexts.newBuilder().setCustom(custom).build(); |
671 | | - BlobInfo pendingUpdate = storage.get(bucket.getName(), blobName).toBuilder().setContexts(contexts).build(); |
672 | | - storage.update(pendingUpdate); |
| 666 | + ObjectCustomContextPayload payload = |
| 667 | + ObjectCustomContextPayload.newBuilder().setValue(value).build(); |
| 668 | + Map<String, ObjectCustomContextPayload> custom = Maps.newHashMap(); |
| 669 | + custom.put(key, payload); |
| 670 | + ObjectContexts contexts = ObjectContexts.newBuilder().setCustom(custom).build(); |
| 671 | + BlobInfo pendingUpdate = |
| 672 | + storage.get(bucket.getName(), blobName).toBuilder().setContexts(contexts).build(); |
| 673 | + storage.update(pendingUpdate); |
673 | 674 |
|
674 | | - GetObjectContexts.getObjectContexts(GOOGLE_CLOUD_PROJECT, bucket.getName(), blobName); |
| 675 | + GetObjectContexts.getObjectContexts(GOOGLE_CLOUD_PROJECT, bucket.getName(), blobName); |
675 | 676 |
|
676 | | - String getOutput = stdOut.getCapturedOutputAsUtf8String(); |
| 677 | + String getOutput = stdOut.getCapturedOutputAsUtf8String(); |
677 | 678 |
|
678 | | - assertThat(getOutput).contains("Custom Contexts:"); |
679 | | - assertThat(getOutput).contains(key + "=ObjectCustomContextPayload{"); |
680 | | - assertThat(getOutput).contains("value=" + value); |
681 | | - } |
| 679 | + assertThat(getOutput).contains("Custom Contexts:"); |
| 680 | + assertThat(getOutput).contains(key + "=ObjectCustomContextPayload{"); |
| 681 | + assertThat(getOutput).contains("value=" + value); |
| 682 | + } |
682 | 683 |
|
683 | | - @Test |
684 | | - public void testListObjectContexts() throws Exception { |
685 | | - String blobName = generator.randomObjectName(); |
686 | | - String key = "test-key-list"; |
687 | | - String value = "test-value-list"; |
| 684 | + @Test |
| 685 | + public void testListObjectContexts() throws Exception { |
| 686 | + String blobName = generator.randomObjectName(); |
| 687 | + String key = "test-key-list"; |
| 688 | + String value = "test-value-list"; |
688 | 689 |
|
689 | | - storage.create(info(blobName), CONTENT, BlobTargetOption.doesNotExist()); |
| 690 | + storage.create(info(blobName), CONTENT, BlobTargetOption.doesNotExist()); |
690 | 691 |
|
691 | | - ObjectCustomContextPayload payload = |
692 | | - ObjectCustomContextPayload.newBuilder().setValue(value).build(); |
693 | | - Map<String, ObjectCustomContextPayload> custom = Maps.newHashMap(); |
694 | | - custom.put(key, payload); |
695 | | - ObjectContexts contexts = ObjectContexts.newBuilder().setCustom(custom).build(); |
696 | | - BlobInfo pendingUpdate = storage.get(bucket.getName(), blobName).toBuilder().setContexts(contexts).build(); |
697 | | - storage.update(pendingUpdate); |
| 692 | + ObjectCustomContextPayload payload = |
| 693 | + ObjectCustomContextPayload.newBuilder().setValue(value).build(); |
| 694 | + Map<String, ObjectCustomContextPayload> custom = Maps.newHashMap(); |
| 695 | + custom.put(key, payload); |
| 696 | + ObjectContexts contexts = ObjectContexts.newBuilder().setCustom(custom).build(); |
| 697 | + BlobInfo pendingUpdate = |
| 698 | + storage.get(bucket.getName(), blobName).toBuilder().setContexts(contexts).build(); |
| 699 | + storage.update(pendingUpdate); |
698 | 700 |
|
699 | | - ListObjectContexts.listObjectContexts(GOOGLE_CLOUD_PROJECT, bucket.getName(), key); |
700 | | - String listOutput = stdOut.getCapturedOutputAsUtf8String(); |
| 701 | + ListObjectContexts.listObjectContexts(GOOGLE_CLOUD_PROJECT, bucket.getName(), key); |
| 702 | + String listOutput = stdOut.getCapturedOutputAsUtf8String(); |
701 | 703 |
|
702 | | - assertThat(listOutput).contains("gs://" + bucket.getName() + "/" + blobName); |
| 704 | + assertThat(listOutput).contains("gs://" + bucket.getName() + "/" + blobName); |
703 | 705 |
|
704 | | - assertThat(listOutput).contains("Listing objects for bucket: " + bucket.getName() + "with context key: " + key); |
705 | | - } |
| 706 | + assertThat(listOutput) |
| 707 | + .contains("Listing objects for bucket: " + bucket.getName() + "with context key: " + key); |
| 708 | + } |
706 | 709 | } |
0 commit comments