when(s3Operations.getObjectTagging(any(GetObjectTaggingRequest.class), any(AmazonS3Client.class))).thenReturn(getObjectTaggingResult); when(s3Operations.setObjectTagging(any(SetObjectTaggingRequest.class), any(AmazonS3Client.class))).thenReturn(setObjectTaggingResult); verify(s3Operations).getObjectTagging(any(GetObjectTaggingRequest.class), any(AmazonS3Client.class)); verify(s3Operations).setObjectTagging(any(SetObjectTaggingRequest.class), any(AmazonS3Client.class)); verifyNoMoreInteractionsHelper();
when(s3Operations.getObjectTagging(any(GetObjectTaggingRequest.class), any(AmazonS3Client.class))).thenReturn(getObjectTaggingResult); when(s3Operations.setObjectTagging(any(SetObjectTaggingRequest.class), any(AmazonS3Client.class))).thenReturn(setObjectTaggingResult); verify(s3Operations).getObjectTagging(any(GetObjectTaggingRequest.class), any(AmazonS3Client.class)); verify(s3Operations).setObjectTagging(any(SetObjectTaggingRequest.class), any(AmazonS3Client.class)); verifyNoMoreInteractionsHelper();
GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging(getObjectTaggingRequest, s3Client);
GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging(getObjectTaggingRequest, s3Client);
@Test public void testTagObjectsTargetTagKeyAlreadyExists() { // Create two S3 object tags having the same tag key. List<Tag> tags = Arrays.asList(new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE), new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE_2)); // Put a file in S3 that is already tagged with the first S3 object tag. PutObjectRequest putObjectRequest = new PutObjectRequest(S3_BUCKET_NAME, TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), new ObjectMetadata()); putObjectRequest.setTagging(new ObjectTagging(Collections.singletonList(tags.get(0)))); s3Operations.putObject(putObjectRequest, null); // Validate that the S3 object is tagged with the first tag. GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null); assertEquals(Collections.singletonList(tags.get(0)), getObjectTaggingResult.getTagSet()); // Create an S3 file transfer request parameters DTO to access S3 objects. S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto(); params.setS3BucketName(S3_BUCKET_NAME); // Create an S3 object summary. S3ObjectSummary s3ObjectSummary = new S3ObjectSummary(); s3ObjectSummary.setKey(TARGET_S3_KEY); // Tag the S3 file with the second S3 object tag. s3Dao.tagObjects(params, new S3FileTransferRequestParamsDto(), Collections.singletonList(s3ObjectSummary), tags.get(1)); // Validate that the S3 object is tagged with the second tag now. getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null); assertEquals(Collections.singletonList(tags.get(1)), getObjectTaggingResult.getTagSet()); }
@Test public void testTagObjectsOtherTagKeyAlreadyExists() { // Create two S3 object tags having different tag keys. List<Tag> tags = Arrays.asList(new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE), new Tag(S3_OBJECT_TAG_KEY_2, S3_OBJECT_TAG_VALUE_2)); // Put a file in S3 that is already tagged with the first S3 object tag. PutObjectRequest putObjectRequest = new PutObjectRequest(S3_BUCKET_NAME, TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), new ObjectMetadata()); putObjectRequest.setTagging(new ObjectTagging(Collections.singletonList(tags.get(0)))); s3Operations.putObject(putObjectRequest, null); // Validate that the S3 object is tagged with the first tag only. GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null); assertEquals(Collections.singletonList(tags.get(0)), getObjectTaggingResult.getTagSet()); // Create an S3 file transfer request parameters DTO to access S3 objects. S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto(); params.setS3BucketName(S3_BUCKET_NAME); // Create an S3 object summary. S3ObjectSummary s3ObjectSummary = new S3ObjectSummary(); s3ObjectSummary.setKey(TARGET_S3_KEY); // Tag the S3 file with the second S3 object tag. s3Dao.tagObjects(params, new S3FileTransferRequestParamsDto(), Collections.singletonList(s3ObjectSummary), tags.get(1)); // Validate that the S3 object is now tagged with both tags. getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null); assertEquals(tags.size(), getObjectTaggingResult.getTagSet().size()); assertTrue(getObjectTaggingResult.getTagSet().containsAll(tags)); }
@Test public void testTagObjects() { // Create an S3 file transfer request parameters DTO to access S3 objects. S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto(); params.setS3BucketName(S3_BUCKET_NAME); // Create an S3 object summary. S3ObjectSummary s3ObjectSummary = new S3ObjectSummary(); s3ObjectSummary.setKey(TARGET_S3_KEY); // Create an S3 object tag. Tag tag = new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE); // Put a file in S3. s3Operations.putObject(new PutObjectRequest(S3_BUCKET_NAME, TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), new ObjectMetadata()), null); // Tag the file with an S3 object tag. s3Dao.tagObjects(params, new S3FileTransferRequestParamsDto(), Collections.singletonList(s3ObjectSummary), tag); // Validate that the object got tagged. GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null); assertEquals(Collections.singletonList(tag), getObjectTaggingResult.getTagSet()); }
GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging( new GetObjectTaggingRequest(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_VERSIONING_ENABLED, TARGET_S3_KEY, versionListing.getVersionSummaries().get(0).getVersionId()), null); getObjectTaggingResult = s3Operations.getObjectTagging( new GetObjectTaggingRequest(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_VERSIONING_ENABLED, TARGET_S3_KEY, versionListing.getVersionSummaries().get(0).getVersionId()), null);
GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging( new GetObjectTaggingRequest(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_VERSIONING_ENABLED, TARGET_S3_KEY, versionListing.getVersionSummaries().get(0).getVersionId()), null); getObjectTaggingResult = s3Operations.getObjectTagging( new GetObjectTaggingRequest(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_VERSIONING_ENABLED, TARGET_S3_KEY, versionListing.getVersionSummaries().get(0).getVersionId()), null);
s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, storageFile.getFilePath()), null); assertEquals(Arrays.asList(new Tag(S3_ARCHIVE_TO_GLACIER_TAG_KEY, S3_ARCHIVE_TO_GLACIER_TAG_VALUE)), getObjectTaggingResult.getTagSet());
s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, storageFile.getFilePath()), null); assertEquals(Collections.singletonList(expectedTag), getObjectTaggingResult.getTagSet()); s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, unregisteredS3FilePath), null); assertEquals(Collections.singletonList(expectedTag), getObjectTaggingResult.getTagSet());
s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY + i, null), null); assertEquals(Collections.singletonList(tag), getObjectTaggingResult.getTagSet());
GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging( new GetObjectTaggingRequest(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_VERSIONING_ENABLED, TARGET_S3_KEY, versionListing.getVersionSummaries().get(i).getVersionId()), null);
s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, storageFile.getFilePath()), null); assertEquals(Collections.singletonList(new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE)), getObjectTaggingResult.getTagSet()); s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, unregisteredS3FilePath), null); assertEquals(Collections.singletonList(new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE)), getObjectTaggingResult.getTagSet());