RestoreContentTaskRunner implements TaskRunner { @Override public String performTask(String taskParameters) { String spaceId = null; String contentId = null; if (null != taskParameters && taskParameters.length() > 0) { int separator = taskParameters.indexOf("/"); spaceId = taskParameters.substring(0, separator); contentId = taskParameters.substring(separator + 1); } if (null == spaceId || null == contentId || spaceId.equals("") || contentId.equals("")) { throw new RuntimeException("A path including a space ID and an " + "content ID (separated by a '/') is required."); } try { s3Client.restoreObject(unwrappedGlacierProvider.getBucketName(spaceId), contentId, RESTORE_EXPIRATION_DAYS); } catch (AmazonS3Exception e) { if (RESTORE_IN_PROGRESS.equals(e.getErrorCode())) { throw new StorageStateException( "Restore is already in progress for " + taskParameters, e); } } return "Request to restore content item " + contentId + " in space " + spaceId + " was successful."; } RestoreContentTaskRunner(StorageProvider glacierProvider,
                                    GlacierStorageProvider unwrappedGlacierProvider,
                                    AmazonS3 s3Client); @Override String getName(); @Override String performTask(String taskParameters);  }
@Test public void testPerformTask() { EasyMock.expect(unwrappedGlacierProvider.getBucketName("one")) .andReturn("123.one"); s3Client.restoreObject("123.one", "two/three.txt", 14); EasyMock.expectLastCall().once(); replayMocks(); taskRunner.performTask("one/two/three.txt"); }
@Test public void testPerformTaskRetrivalInProgress() { EasyMock.expect(unwrappedGlacierProvider.getBucketName("one")) .andReturn("123.one"); AmazonS3Exception glacierEx = new AmazonS3Exception("err msg"); glacierEx.setErrorCode(RestoreContentTaskRunner.RESTORE_IN_PROGRESS); s3Client.restoreObject("123.one", "two/three.txt", 14); EasyMock.expectLastCall().andThrow(glacierEx); replayMocks(); try { taskRunner.performTask("one/two/three.txt"); fail("Exception expected due to state of retrieval"); } catch (StorageStateException e) { assertNotNull(e.getMessage()); } }
@Test public void testPerformTaskInvalidParams() { try { taskRunner.performTask(null); fail("Exception expected passing a null parameter"); } catch (RuntimeException e) { } try { taskRunner.performTask(""); fail("Exception expected passing a empty parameter"); } catch (RuntimeException e) { } try { taskRunner.performTask("one"); fail("Exception expected passing an invalid parameter"); } catch (RuntimeException e) { } replayMocks(); }