Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist deleteat and deleteafter from upload instructions in mock #169

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/org/javaswift/joss/swift/SwiftStoredObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public SwiftResult<Object> 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() + (1000 * uploadInstructions.getDeleteAfter().getExpireAfterSeconds())) : null;
return new SwiftResult<Object>(HttpStatus.SC_CREATED);
} catch (IOException err) {
return new SwiftResult<Object>(HttpStatus.SC_UNPROCESSABLE_ENTITY);
Expand Down Expand Up @@ -178,6 +181,7 @@ protected StoredObject copyToStoredObject(StoredObject targetObject) {
targetObject.setEtag(getEtag().getHeaderValue());
targetObject.setLastModified(getLastModified());
targetObject.metadataSetFromHeaders();
targetObject.setDeleteAt(deleteAt.getDate());
return targetObject;
}

Expand Down
22 changes: 22 additions & 0 deletions src/test/java/org/javaswift/joss/swift/SwiftStoredObjectTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.javaswift.joss.swift;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -10,9 +11,12 @@

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;


public class SwiftStoredObjectTest {

@Test
Expand All @@ -23,6 +27,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() {
Expand Down