diff --git a/src/main/java/org/javaswift/joss/swift/SwiftStoredObject.java b/src/main/java/org/javaswift/joss/swift/SwiftStoredObject.java index f50d1fc7..2e2ff131 100644 --- a/src/main/java/org/javaswift/joss/swift/SwiftStoredObject.java +++ b/src/main/java/org/javaswift/joss/swift/SwiftStoredObject.java @@ -85,6 +85,9 @@ public SwiftResult uploadObject(UploadInstructions uploadInstructions) { uploadInstructions.getContentType() != null ? uploadInstructions.getContentType() : new ObjectContentType(new MimetypesFileTypeMap().getContentType(getName())); + this.deleteAt = uploadInstructions.getDeleteAt() != null ? uploadInstructions.getDeleteAt() : + uploadInstructions.getDeleteAfter() != null ? + new DeleteAt(System.currentTimeMillis() + uploadInstructions.getDeleteAfter().getExpireAfterSeconds()) : null; return new SwiftResult(HttpStatus.SC_CREATED); } catch (IOException err) { return new SwiftResult(HttpStatus.SC_UNPROCESSABLE_ENTITY); diff --git a/src/test/java/org/javaswift/joss/swift/SwiftStoredObjectTest.java b/src/test/java/org/javaswift/joss/swift/SwiftStoredObjectTest.java index 9b7f6703..3bbba071 100644 --- a/src/test/java/org/javaswift/joss/swift/SwiftStoredObjectTest.java +++ b/src/test/java/org/javaswift/joss/swift/SwiftStoredObjectTest.java @@ -4,6 +4,8 @@ import mockit.Mocked; import org.apache.commons.io.IOUtils; import org.apache.http.HttpStatus; +import org.javaswift.joss.headers.object.DeleteAfter; +import org.javaswift.joss.headers.object.DeleteAt; import org.javaswift.joss.instructions.UploadInstructions; import org.junit.Test; @@ -11,6 +13,7 @@ import java.io.InputStream; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; public class SwiftStoredObjectTest { @@ -22,6 +25,24 @@ public void uploadObject() { assertEquals(3, object.getContent().length); } + @Test + public void uploadObject_withDeleteAt_populatesDeleteAt() { + UploadInstructions instructions = new UploadInstructions(new byte[] { 0x01, 0x02, 0x03}) + .setDeleteAfter(new DeleteAfter(20)); + SwiftStoredObject object = new SwiftStoredObject("alpha"); + object.uploadObject(instructions); + assertNotNull(object.getInfo().getDeleteAt()); + } + + @Test + public void uploadObject_withDeleteAfter_populatesDeleteAt() { + UploadInstructions instructions = new UploadInstructions(new byte[] { 0x01, 0x02, 0x03}) + .setDeleteAt(new DeleteAt(System.currentTimeMillis() + 10000)); + SwiftStoredObject object = new SwiftStoredObject("alpha"); + object.uploadObject(instructions); + assertNotNull(object.getInfo().getDeleteAt()); + } + @Test public void uploadObjectThrowsException() throws IOException { new Expectations() {