|
| 1 | +package edu.harvard.iq.dataverse.api; |
| 2 | + |
| 3 | +import com.jayway.restassured.RestAssured; |
| 4 | +import static com.jayway.restassured.path.json.JsonPath.with; |
| 5 | +import com.jayway.restassured.response.Response; |
| 6 | +import java.io.IOException; |
| 7 | +import java.util.List; |
| 8 | +import java.util.Map; |
| 9 | +import javax.json.Json; |
| 10 | +import javax.json.JsonObject; |
| 11 | +import static javax.ws.rs.core.Response.Status.CREATED; |
| 12 | +import static javax.ws.rs.core.Response.Status.OK; |
| 13 | +import static org.hamcrest.CoreMatchers.equalTo; |
| 14 | +import static org.junit.Assert.assertTrue; |
| 15 | +import org.junit.BeforeClass; |
| 16 | +import org.junit.Test; |
| 17 | + |
| 18 | +public class FitsIT { |
| 19 | + |
| 20 | + @BeforeClass |
| 21 | + public static void setUp() { |
| 22 | + RestAssured.baseURI = UtilIT.getRestAssuredBaseUri(); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testAstroFieldsFromFits() throws IOException { |
| 27 | + Response createUser = UtilIT.createRandomUser(); |
| 28 | + createUser.then().assertThat().statusCode(OK.getStatusCode()); |
| 29 | + String apiToken = UtilIT.getApiTokenFromResponse(createUser); |
| 30 | + String username = UtilIT.getUsernameFromResponse(createUser); |
| 31 | + |
| 32 | + Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); |
| 33 | + createDataverseResponse.prettyPrint(); |
| 34 | + createDataverseResponse.then().assertThat() |
| 35 | + .statusCode(CREATED.getStatusCode()); |
| 36 | + |
| 37 | + String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); |
| 38 | + |
| 39 | + Response setMetadataBlocks = UtilIT.setMetadataBlocks(dataverseAlias, Json.createArrayBuilder().add("citation").add("astrophysics"), apiToken); |
| 40 | + setMetadataBlocks.prettyPrint(); |
| 41 | + setMetadataBlocks.then().assertThat().statusCode(OK.getStatusCode()); |
| 42 | + |
| 43 | + Response createDataset = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken); |
| 44 | + createDataset.prettyPrint(); |
| 45 | + createDataset.then().assertThat() |
| 46 | + .statusCode(CREATED.getStatusCode()); |
| 47 | + |
| 48 | + Integer datasetId = UtilIT.getDatasetIdFromResponse(createDataset); |
| 49 | + String datasetPid = UtilIT.getDatasetPersistentIdFromResponse(createDataset); |
| 50 | + |
| 51 | + // "FOS 2 x 2064 primary array spectrum containing the flux and wavelength arrays, plus a small table extension" |
| 52 | + // from https://fits.gsfc.nasa.gov/fits_samples.html |
| 53 | + String pathToFile = "src/test/resources/fits/FOSy19g0309t_c2f.fits"; |
| 54 | + |
| 55 | + Response uploadFile = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile, apiToken); |
| 56 | + uploadFile.prettyPrint(); |
| 57 | + uploadFile.then().assertThat().statusCode(OK.getStatusCode()); |
| 58 | + |
| 59 | + Response getJson = UtilIT.nativeGet(datasetId, apiToken); |
| 60 | + getJson.prettyPrint(); |
| 61 | + getJson.then().assertThat() |
| 62 | + .statusCode(OK.getStatusCode()) |
| 63 | + .body("data.latestVersion.metadataBlocks.astrophysics.fields[0].value[0]", equalTo("Image")); |
| 64 | + |
| 65 | + // a bit more precise than the check for "Image" above (but annoyingly fiddly) |
| 66 | + List<JsonObject> astroTypeFromNativeGet = with(getJson.body().asString()).param("astroType", "astroType") |
| 67 | + .getJsonObject("data.latestVersion.metadataBlocks.astrophysics.fields.findAll { fields -> fields.typeName == astroType }"); |
| 68 | + Map firstAstroTypeFromNativeGet = astroTypeFromNativeGet.get(0); |
| 69 | + assertTrue(firstAstroTypeFromNativeGet.toString().contains("Image")); |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments