Skip to content

Commit

Permalink
Persist deleteat and deleteafter from upload instructions in mock
Browse files Browse the repository at this point in the history
  • Loading branch information
toscott committed Jun 26, 2019
1 parent 0b00611 commit ac15738
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/javaswift/joss/swift/SwiftStoredObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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() + uploadInstructions.getDeleteAfter().getExpireAfterSeconds()) : null;
return new SwiftResult<Object>(HttpStatus.SC_CREATED);
} catch (IOException err) {
return new SwiftResult<Object>(HttpStatus.SC_UNPROCESSABLE_ENTITY);
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/javaswift/joss/swift/SwiftStoredObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
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;

import java.io.IOException;
import java.io.InputStream;

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

public class SwiftStoredObjectTest {

Expand All @@ -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() {
Expand Down

0 comments on commit ac15738

Please sign in to comment.