SwiftStorageProvider extends S3StorageProvider { public ObjectMetadata expireObject(String bucketName, String contentId, Integer seconds) { log.debug("Expiring object {} in {} after {} seconds.", contentId, bucketName, seconds); ObjectMetadata objMetadata = getObjectDetails(bucketName, contentId, true); objMetadata.setHeader(Constants.SWIFT_EXPIRE_OBJECT_HEADER, seconds); updateObjectProperties(bucketName, contentId, objMetadata); return objMetadata; } SwiftStorageProvider(String accessKey, String secretKey, Map<String, String> options);  SwiftStorageProvider(AmazonS3 s3Client, String accessKey); @Override StorageProviderType getStorageProviderType(); @Override void removeSpace(String spaceId); @Override String createHiddenSpace(String spaceId, int expirationInDays); ObjectMetadata expireObject(String bucketName, String contentId, Integer seconds);  }
@Test public void testExpireObject() { setupS3Client(); String bucketName = truncateKey() + "." + spaceId; Integer seconds = 600; Bucket bucket = createMock(Bucket.class); expect(bucket.getName()).andReturn(bucketName).anyTimes(); Map<String,Object> rawMetadata = new HashMap<>(); rawMetadata.put(Constants.SWIFT_EXPIRE_OBJECT_HEADER, seconds); ObjectMetadata objectMetadata = createMock("ObjectMetadata", ObjectMetadata.class); expect(s3Client.getObjectMetadata( EasyMock.isA(String.class), EasyMock.isA(String.class))).andReturn(objectMetadata); expect(objectMetadata.getRawMetadata()).andReturn(rawMetadata).anyTimes(); objectMetadata.setHeader(Constants.SWIFT_EXPIRE_OBJECT_HEADER, seconds); EasyMock.expectLastCall(); AccessControlList originalACL = createMock("AccessControlList", AccessControlList.class); expect(s3Client.getObjectAcl(bucketName, contentId)).andReturn(originalACL); CopyObjectResult copyObjectResult = createMock("CopyObjectResult", CopyObjectResult.class); Capture<CopyObjectRequest> capturedRequest = new Capture<CopyObjectRequest>(); expect(s3Client.copyObject(capture(capturedRequest))).andReturn(copyObjectResult); SwiftStorageProvider provider = getProvider(); replay(s3Client, bucket, objectMetadata, originalACL, copyObjectResult); ObjectMetadata resultMetadata = provider.expireObject(bucketName, contentId, seconds); CopyObjectRequest copyRequest = capturedRequest.getValue(); assertEquals(bucketName, copyRequest.getDestinationBucketName()); assertEquals(contentId, copyRequest.getDestinationKey()); assertEquals(bucketName, copyRequest.getSourceBucketName()); assertEquals(contentId, copyRequest.getSourceKey()); assertEquals(originalACL, copyRequest.getAccessControlList()); assertTrue(copyRequest.getNewObjectMetadata().getRawMetadata(). containsKey(Constants.SWIFT_EXPIRE_OBJECT_HEADER)); assertTrue(resultMetadata.getRawMetadata().containsKey(Constants.SWIFT_EXPIRE_OBJECT_HEADER)); assertEquals(resultMetadata, copyRequest.getNewObjectMetadata()); verify(s3Client, bucket, objectMetadata, originalACL, copyObjectResult); }