Skip to content

Commit

Permalink
Closes #2560: Improves execution run-time of IT tests by performing d…
Browse files Browse the repository at this point in the history
…eployment only once per test module
  • Loading branch information
diasf committed Oct 7, 2024
1 parent 89a83ba commit cd664e4
Show file tree
Hide file tree
Showing 212 changed files with 1,582 additions and 1,823 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package edu.harvard.iq.dataverse.common;

import org.junit.*;
import org.junit.jupiter.api.*;

import java.util.AbstractMap.SimpleEntry;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class AuthenticatedUserUtilTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package edu.harvard.iq.dataverse.persistence;

import edu.harvard.iq.dataverse.persistence.GlobalId;
import edu.harvard.iq.dataverse.persistence.dataset.Dataset;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author rmp553
*/
public class GlobalIdTest {

@Rule
public ExpectedException exception = ExpectedException.none();

@Test
public void testValidDOI() {
System.out.println("testValidDOI");
Expand Down Expand Up @@ -76,27 +71,24 @@ public void testUnknownProtocol() {

String badProtocol = "doy:10.5072/FK2/BYM3IW";

exception.expect(IllegalArgumentException.class);
exception.expectMessage("Failed to parse identifier: " + badProtocol);
new GlobalId(badProtocol);
Exception thrown = assertThrows(IllegalArgumentException.class, () -> new GlobalId(badProtocol));
assertEquals("Failed to parse identifier: " + badProtocol, thrown.getMessage());
}

@Test
public void testBadIdentifierOnePart() {
System.out.println("testBadIdentifierOnePart");

exception.expect(IllegalArgumentException.class);
exception.expectMessage("Failed to parse identifier: 1part");
new GlobalId("1part");
Exception thrown = assertThrows(IllegalArgumentException.class, () -> new GlobalId("1part"));
assertEquals("Failed to parse identifier: 1part", thrown.getMessage());
}

@Test
public void testBadIdentifierTwoParts() {
System.out.println("testBadIdentifierTwoParts");

exception.expect(IllegalArgumentException.class);
exception.expectMessage("Failed to parse identifier: doi:2part/blah");
new GlobalId("doi:2part/blah");
Exception thrown = assertThrows(IllegalArgumentException.class, () -> new GlobalId("doi:2part/blah"));
assertEquals("Failed to parse identifier: doi:2part/blah", thrown.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package edu.harvard.iq.dataverse.persistence;

import edu.harvard.iq.dataverse.test.arquillian.ArquillianIntegrationTests;
import org.eu.ingwar.tools.arquillian.extension.suite.annotations.ArquillianSuiteDeployment;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Before;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -20,9 +20,10 @@
import javax.transaction.Status;
import javax.transaction.UserTransaction;

@RunWith(Arquillian.class)
@ExtendWith(ArquillianExtension.class)
@Transactional(TransactionMode.ROLLBACK)
@Category(ArquillianIntegrationTests.class)
@Tag("ArquillianIntegrationTests")
@ArquillianSuiteDeployment
public abstract class PersistenceArquillianDeployment {

protected static final Logger log = LoggerFactory.getLogger(PersistenceArquillianDeployment.class);
Expand All @@ -41,12 +42,12 @@ public static Archive<?> createDeployment() {
return javaArchive;
}

@Before
@BeforeEach
public void before() {
sqlScriptRunner.runScriptFromClasspath("/dbinit.sql");
}

@After
@AfterEach
public void after() throws Exception {
if (transaction.getStatus() == Status.STATUS_NO_TRANSACTION) {
databaseCleaner.cleanupDatabase();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package edu.harvard.iq.dataverse.persistence.config;

import edu.harvard.iq.dataverse.persistence.config.EMailValidator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Stream;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author philip durbin
Expand All @@ -18,57 +15,48 @@
* @author stephen kraffmiller
* @author alex scheitlin
*/
@RunWith(Parameterized.class)
public class EMailValidatorTest {

public boolean isValid;
public String email;

public EMailValidatorTest(boolean isValid, String email) {
this.isValid = isValid;
this.email = email;
}

@Parameters
public static Collection<Object[]> parameters() {
return Arrays.asList(new Object[][]{
{true, "[email protected]"},
public static Stream<Arguments> parameters() {
return Stream.of(
Arguments.of(true, "[email protected]"),

// @todo How can this be a valid email address?
{true, " [email protected]"},
Arguments.of(true, " [email protected]"),

// @todo How can this be a valid email address?
{true, "[email protected] "},
Arguments.of(true, "[email protected] "),

{false, "elisah.da [email protected]"},
{false, "[email protected];[email protected]"},
Arguments.of(false, "elisah.da [email protected]"),
Arguments.of(false, "[email protected];[email protected]"),

/**
* These examples are all from https://randomuser.me and seem to be
* valid according to
* http://sphinx.mythic-beasts.com/~pdw/cgi-bin/emailvalidate (except
* رونیکا.محمدخان@example.com).
*/
{true, "miché[email protected]"},
{true, "begü[email protected]"},
{true, "lótus.gonç[email protected]"},
{true, "lótus.gonçalves@éxample.com"},
{true, "begü[email protected]"},
{true, "رونیکا.محمدخان@example.com"},
{false, "lótus.gonç[email protected]óm"},
{false, "[email protected]"},
{false, ""},
{false, null},
Arguments.of(true, "miché[email protected]"),
Arguments.of(true, "begü[email protected]"),
Arguments.of(true, "lótus.gonç[email protected]"),
Arguments.of(true, "lótus.gonçalves@éxample.com"),
Arguments.of(true, "begü[email protected]"),
Arguments.of(true, "رونیکا.محمدخان@example.com"),
Arguments.of(false, "lótus.gonç[email protected]óm"),
Arguments.of(false, "[email protected]"),
Arguments.of(false, ""),
Arguments.of(false, null),

// add tests for 4601
{true, "[email protected]"},
{true, "[email protected]"},
{true, "[email protected]"},
});
Arguments.of(true, "[email protected]"),
Arguments.of(true, "[email protected]"),
Arguments.of(true, "[email protected]")
);
}

@Test
public void testIsEmailValid() {
@ParameterizedTest
@MethodSource("parameters")
public void testIsEmailValid(boolean isValid, String email) {
assertEquals(isValid, EMailValidator.isEmailValid(email, null));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package edu.harvard.iq.dataverse.persistence.config;

import edu.harvard.iq.dataverse.persistence.config.URLValidator;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author skraffmi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import edu.harvard.iq.dataverse.common.files.mime.TextMimeType;
import edu.harvard.iq.dataverse.persistence.datafile.ExternalTool;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import javax.json.JsonObject;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class ExternalToolTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import edu.harvard.iq.dataverse.persistence.PersistenceArquillianDeployment;
import org.assertj.core.util.Lists;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;


public class FileMetadataRepositoryIT extends PersistenceArquillianDeployment {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package edu.harvard.iq.dataverse.persistence.datafile.license;

import edu.harvard.iq.dataverse.persistence.PersistenceArquillianDeployment;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
package edu.harvard.iq.dataverse.persistence.dataset;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Stream;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

@RunWith(Parameterized.class)
public class DatasetAuthorTest {

public String idType;
public String idValue;
public String expectedIdentifierAsUrl;

public DatasetAuthorTest(String idType, String idValue, String expectedIdentifierAsUrl) {
this.idType = idType;
this.idValue = idValue;
this.expectedIdentifierAsUrl = expectedIdentifierAsUrl;
}

@Parameters
public static Collection<String[]> parameters() {
return Arrays.asList(new String[][]{
{"ORCID", "0000-0002-1825-0097", "https://orcid.org/0000-0002-1825-0097"},
{"ISNI", "0000000121032683", "http://www.isni.org/isni/0000000121032683"},
{"LCNA", "n82058243", "http://id.loc.gov/authorities/names/n82058243"},
{"VIAF", "172389567", "https://viaf.org/viaf/172389567"},
{"GND", "4079154-3", "https://d-nb.info/gnd/4079154-3"},
{null, null, null,},
});
public static Stream<Arguments> parameters() {
return Stream.of(
Arguments.of("ORCID", "0000-0002-1825-0097", "https://orcid.org/0000-0002-1825-0097"),
Arguments.of("ISNI", "0000000121032683", "http://www.isni.org/isni/0000000121032683"),
Arguments.of("LCNA", "n82058243", "http://id.loc.gov/authorities/names/n82058243"),
Arguments.of("VIAF", "172389567", "https://viaf.org/viaf/172389567"),
Arguments.of("GND", "4079154-3", "https://d-nb.info/gnd/4079154-3"),
Arguments.of(null, null, null)
);
}

@Test
public void getIdentifierAsUrl() {
@ParameterizedTest
@MethodSource("parameters")
public void getIdentifierAsUrl(String idType, String idValue, String expectedIdentifierAsUrl) {
DatasetAuthor datasetAuthor = new DatasetAuthor();
if (idType != null && idValue != null) {
datasetAuthor.setIdType(idType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package edu.harvard.iq.dataverse.persistence.dataset;

import edu.harvard.iq.dataverse.persistence.PersistenceArquillianDeployment;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

Expand Down
Loading

0 comments on commit cd664e4

Please sign in to comment.