Skip to content

Commit

Permalink
refactor(api-test): migrate DatasetsIT to JUnit 5 IQSS#8251
Browse files Browse the repository at this point in the history
  • Loading branch information
poikilotherm committed Nov 22, 2021
1 parent 45ae750 commit ed4e08f
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Response;
import java.util.logging.Logger;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;

import edu.harvard.iq.dataverse.api.helpers.Tags;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.junit.Ignore;
import com.jayway.restassured.path.json.JsonPath;

import java.util.List;
Expand All @@ -23,7 +26,6 @@
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static javax.ws.rs.core.Response.Status.METHOD_NOT_ALLOWED;
import edu.harvard.iq.dataverse.DataFile;
import edu.harvard.iq.dataverse.DataverseServiceBean;

import static edu.harvard.iq.dataverse.api.UtilIT.API_TOKEN_HTTP_HEADER;
import edu.harvard.iq.dataverse.authorization.DataverseRole;
Expand Down Expand Up @@ -53,28 +55,25 @@
import javax.json.JsonArray;
import javax.json.JsonObjectBuilder;
import static javax.ws.rs.core.Response.Status.NO_CONTENT;
import static javax.ws.rs.core.Response.Status.OK;
import static org.junit.Assert.assertEquals;
import org.hamcrest.CoreMatchers;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.CoreMatchers.nullValue;
import org.junit.AfterClass;
import org.junit.Assert;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.matchers.JUnitMatchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class DatasetsIT {
@Tag(Tags.SLOW)
@Tag(Tags.STD_API_SET)
@Tag(Tags.EXT_API_SET)
public class DatasetsIT extends TestContainersBase {

private static final Logger logger = Logger.getLogger(DatasetsIT.class.getCanonicalName());



@BeforeClass
@BeforeAll
public static void setUpClass() {


RestAssured.baseURI = UtilIT.getRestAssuredBaseUri();

Response removeIdentifierGenerationStyle = UtilIT.deleteSetting(SettingsServiceBean.Key.IdentifierGenerationStyle);
Expand All @@ -96,7 +95,7 @@ public static void setUpClass() {
*/
}

@AfterClass
@AfterAll
public static void afterClass() {

Response removeIdentifierGenerationStyle = UtilIT.deleteSetting(SettingsServiceBean.Key.IdentifierGenerationStyle);
Expand Down Expand Up @@ -520,7 +519,7 @@ public void testCreatePublishDestroyDataset() {
* This test requires the root dataverse to be published to pass.
*/
@Test
@Ignore
@Disabled
public void testExport() {

Response createUser = UtilIT.createRandomUser();
Expand Down Expand Up @@ -1872,7 +1871,7 @@ public void testDatasetLocksApi() {
* This test requires the root dataverse to be published to pass.
*/
@Test
@Ignore
@Disabled
public void testUpdatePIDMetadataAPI() {

Response createUser = UtilIT.createRandomUser();
Expand Down Expand Up @@ -2132,7 +2131,11 @@ public void testRestrictFileExportDdi() throws IOException {

String fileId = JsonPath.from(uploadFile.body().asString()).getString("data.files[0].dataFile.id");

assertTrue("Failed test if Ingest Lock exceeds max duration " + pathToFile, UtilIT.sleepForLock(datasetId.longValue(), "Ingest", authorApiToken, UtilIT.MAXIMUM_INGEST_LOCK_DURATION));
assertTrue(UtilIT.sleepForLock(datasetId.longValue(),
"Ingest",
authorApiToken,
UtilIT.MAXIMUM_INGEST_LOCK_DURATION),
"Failed test if Ingest Lock exceeds max duration " + pathToFile);

Response restrictFile = UtilIT.restrictFile(fileId, true, authorApiToken);
restrictFile.prettyPrint();
Expand All @@ -2153,7 +2156,7 @@ public void testRestrictFileExportDdi() throws IOException {

// Here we are asserting that dataDscr is empty. TODO: Do this in REST Assured.
String dataDscrForGuest = XmlPath.from(exportByGuest.asString()).getString("codeBook.dataDscr");
Assert.assertEquals("", dataDscrForGuest);
assertEquals("", dataDscrForGuest);

// Author export (has access)
Response exportByAuthor = UtilIT.exportDataset(datasetPid, "ddi", authorApiToken);
Expand All @@ -2164,7 +2167,7 @@ public void testRestrictFileExportDdi() throws IOException {

// Here we are asserting that dataDscr is empty. TODO: Do this in REST Assured.
String dataDscrForAuthor = XmlPath.from(exportByAuthor.asString()).getString("codeBook.dataDscr");
Assert.assertEquals("", dataDscrForAuthor);
assertEquals("", dataDscrForAuthor);

// Now we are testing file-level retrieval.
// The author has access to a restricted file and gets all the metadata.
Expand All @@ -2175,7 +2178,7 @@ public void testRestrictFileExportDdi() throws IOException {
.body("codeBook.fileDscr.fileTxt.fileName", equalTo("data.tab"))
// .body("codeBook", containsString("dataDscr"))
// The names of all these variables (name, pounds, species) should be visible.
.body("codeBook.dataDscr", CoreMatchers.not(equalTo(null)))
.body("codeBook.dataDscr", not(equalTo(null)))
// .body("codeBook.dataDscr", equalTo(null))
.body("codeBook.dataDscr.var[0].@name", equalTo("name"))
.body("codeBook.dataDscr.var[1].@name", equalTo("pounds"))
Expand Down

0 comments on commit ed4e08f

Please sign in to comment.