Skip to content

Commit

Permalink
conforms integration test setUpClass to Dataverse conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
bmckinney committed Oct 19, 2016
1 parent 640fe54 commit a509fca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 46 deletions.
51 changes: 13 additions & 38 deletions src/test/java/edu/harvard/iq/dataverse/api/FileMetadataIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.UUID;

import static com.jayway.restassured.RestAssured.given;
Expand All @@ -47,39 +44,19 @@ public class FileMetadataIT {
// test properties
private static String testName;
private static String token;
private static final String builtinUserKey = "burrito";
private static final String keyString = "X-Dataverse-key";

// dataset properties
private static int dsId;

private static Properties props = new Properties();


@BeforeClass
public static void setUpClass() throws Exception {

InputStream input = null;

try {
input = classLoader.getResourceAsStream("FileMetadataIT.properties");
props.load(input);
RestAssured.baseURI = props.getProperty("baseuri");
String port = props.getProperty("port");
RestAssured.port = Integer.valueOf(port);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void setUpClass() {
RestAssured.baseURI = UtilIT.getRestAssuredBaseUri();
}

@Before
public void setUpDataverse() {

try {
// create random test name
testName = UUID.randomUUID().toString().substring(0, 8);
Expand All @@ -93,7 +70,7 @@ public void setUpDataverse() {
"}")
.contentType(ContentType.JSON)
.request()
.post("/api/builtin-users/secret/" + props.getProperty("builtin.user.key"))
.post("/api/builtin-users/secret/" + builtinUserKey)
.then().assertThat().statusCode(200)
.extract().jsonPath().getString("data.apiToken");
System.out.println("TOKEN: " + token);
Expand All @@ -116,7 +93,7 @@ public void setUpDataverse() {
.contentType(ContentType.JSON).request()
.post("/api/dataverses/:root?key=" + token)
.then().assertThat().statusCode(201);
System.out.println("DATAVERSE: http://localhost:8080/dataverse/" + testName);
System.out.println("DATAVERSE: " + RestAssured.baseURI + "/dataverse/" + testName);
} catch (Exception e) {
System.out.println("Error setting up test dataverse: " + e.getMessage());
fail();
Expand All @@ -132,15 +109,15 @@ public static void tearDownClass() {
public void tearDownDataverse() {
try {
// delete dataset
given().header(props.getProperty("api.token.http.header"), token)
given().header(keyString, token)
.delete("/api/datasets/" + dsId)
.then().assertThat().statusCode(200);
// delete dataverse
given().header(props.getProperty("api.token.http.header"), token)
given().header(keyString, token)
.delete("/api/dataverses/" + testName)
.then().assertThat().statusCode(200);
// delete user
given().header(props.getProperty("api.token.http.header"), token)
given().header(keyString, token)
.delete("/api/admin/authenticatedUsers/"+testName+"/")
.then().assertThat().statusCode(200);
} catch (Exception e) {
Expand All @@ -155,26 +132,25 @@ public void tearDownDataverse() {
*/
@Test
public void testJsonParserWithDirectoryLabels() {

try {
// create dataset and set id
dsId = given()
.header(props.getProperty("api.token.http.header"), token)
.header(keyString, token)
.body(IOUtils.toString(classLoader.getResourceAsStream("json/complete-dataset-with-files.json")))
.contentType("application/json")
.post("/api/dataverses/" + testName + "/datasets")
.then().assertThat().statusCode(201)
.extract().jsonPath().getInt("data.id");
// check that both directory labels were persisted
String dirLabel1 = given()
.header(props.getProperty("api.token.http.header"), token)
.header(keyString, token)
.get("/api/datasets/" + dsId)
.then().assertThat().statusCode(200)
.extract().jsonPath().getString("data.latestVersion.files[0].directoryLabel");
System.out.println("directoryLabel 1: " + dirLabel1);
assertEquals("data/subdir1/", dirLabel1);
String dirLabel2 = given()
.header(props.getProperty("api.token.http.header"), token)
.header(keyString, token)
.get("/api/datasets/" + dsId)
.then().assertThat().statusCode(200)
.extract().jsonPath().getString("data.latestVersion.files[1].directoryLabel");
Expand All @@ -186,7 +162,6 @@ public void testJsonParserWithDirectoryLabels() {
e.printStackTrace();
fail();
}

}

}
8 changes: 0 additions & 8 deletions src/test/resources/FileMetadataIT.properties

This file was deleted.

0 comments on commit a509fca

Please sign in to comment.