SetStoragePolicyTaskRunner implements TaskRunner { @Override public String performTask(String taskParameters) { SetStoragePolicyTaskParameters taskParams = SetStoragePolicyTaskParameters.deserialize(taskParameters); String spaceId = taskParams.getSpaceId(); int daysToTransition = taskParams.getDaysToTransition(); StorageClass storageClass; try { storageClass = StorageClass.fromValue(taskParams.getStorageClass()); } catch (IllegalArgumentException e) { throw new RuntimeException("Cannot set storage policy due to invalid " + "storage class. The valid storage class " + "options are: " + Arrays.asList(StorageClass.values())); } String bucketName = unwrappedS3Provider.getBucketName(spaceId); StoragePolicy storagePolicy = new StoragePolicy(storageClass, daysToTransition); unwrappedS3Provider.setSpaceLifecycle(bucketName, storagePolicy.getBucketLifecycleConfig()); return "Successfully set storage policy on space " + spaceId + " to move content to " + storageClass.name() + " after " + daysToTransition + " days"; } SetStoragePolicyTaskRunner(S3StorageProvider unwrappedS3Provider); String getName(); @Override String performTask(String taskParameters);  }
@Test public void testPerformTask() { String spaceId = "space-id"; String storageClass = "STANDARD_IA"; int days = 42; SetStoragePolicyTaskParameters params = new SetStoragePolicyTaskParameters(); params.setSpaceId(spaceId); params.setStorageClass(storageClass); params.setDaysToTransition(days); SetStoragePolicyTaskRunner taskRunner = new SetStoragePolicyTaskRunner(unwrappedS3Provider); EasyMock.expect(unwrappedS3Provider.getBucketName(spaceId)).andReturn(spaceId); unwrappedS3Provider.setSpaceLifecycle(EasyMock.eq(spaceId), EasyMock.isA(BucketLifecycleConfiguration.class)); EasyMock.expectLastCall().once(); replayAll(); taskRunner.performTask(params.serialize()); }