Skip to content

Commit

Permalink
send bytes with body rather than a file with multiPart
Browse files Browse the repository at this point in the history
See rest-assured/rest-assured#507 but
unclear why preemptive is necessary.
  • Loading branch information
pdurbin committed Dec 8, 2015
1 parent 42d1a67 commit 3d2ac41
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/test/java/edu/harvard/iq/dataverse/api/SearchIT.java
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import static java.lang.Thread.sleep;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -73,7 +74,7 @@ public class SearchIT {
private static final boolean homerPublishesVersion2AfterDeletingFile = false;
private static final boolean disableTestCategory = false;
private Stopwatch timer;
private boolean haveToUseCurlForUpload = true;
private boolean haveToUseCurlForUpload = false;

public SearchIT() {
}
Expand Down Expand Up @@ -847,19 +848,27 @@ private Response search(TestSearchQuery query, TestUser user) {
);
}

/**
* @todo Get this version that doesn't require curl working. Use body
* instead of multiPart?
*/
private Response uploadZipFile(String persistentId, String zipFileName, String apiToken) throws FileNotFoundException {
String pathToFileName = "scripts/search/data/binary/" + zipFileName;
Path path = Paths.get(pathToFileName);
byte[] data = null;
try {
data = Files.readAllBytes(path);
} catch (IOException ex) {
logger.info("Could not read bytes from " + path + ": " + ex);
}
Response swordStatementResponse = given()
.multiPart(new File(pathToFileName))
.body(data)
.header("Packaging", "http://purl.org/net/sword/package/SimpleZip")
.header("Content-Disposition", "filename=" + zipFileName)
.auth().basic(apiToken, EMPTY_STRING)
/**
* It's unclear why we need to add "preemptive" to auth but
* without it we can't seem to switch from .multiPart(file) to
* .body(bytes).
*
* See https://github.com/jayway/rest-assured/issues/507
*/
.auth().preemptive().basic(apiToken, EMPTY_STRING)
.post("/dvn/api/data-deposit/v1.1/swordv2/edit-media/study/" + persistentId);
return swordStatementResponse;
}
Expand Down

0 comments on commit 3d2ac41

Please sign in to comment.