Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert remaining tests to junit 5 #5394

Merged
merged 28 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ac526de
[WIP] Convert remaining tests to junit 5
Siedlerchr Oct 5, 2019
9f8ad5a
remove junit 4
Siedlerchr Oct 5, 2019
b13e470
Merge remote-tracking branch 'upstream/master' into convertRemainingTest
Siedlerchr Oct 9, 2019
1374d20
temporaily add system.out.prinltn to test if all are run
Siedlerchr Oct 9, 2019
9a4a52a
fix gradle not executing tests correclty
Siedlerchr Oct 9, 2019
48c545c
fix gradle syntax error
Siedlerchr Oct 9, 2019
09b131b
add more logging
Siedlerchr Oct 9, 2019
c284667
fix psql driver name and url
Siedlerchr Oct 9, 2019
2041c5b
Merge remote-tracking branch 'upstream/master' into convertRemainingTest
Siedlerchr Oct 24, 2019
0717211
Manually call setup and clear in each test
Siedlerchr Oct 24, 2019
ac192c0
fix typo and call clear
Siedlerchr Oct 24, 2019
a324878
fix unmodifable error
Siedlerchr Oct 24, 2019
05398b0
fix field map error
Siedlerchr Oct 24, 2019
98f0a7c
fix id
Siedlerchr Oct 24, 2019
6a2760c
Merge remote-tracking branch 'upstream/master' into convertRemainingTest
Siedlerchr Oct 25, 2019
96d65e9
SetID does not store value as internal id field
Siedlerchr Oct 25, 2019
b1ff631
add some comments for further debugging hints
Siedlerchr Oct 25, 2019
0d380fd
fix copy paste error
Siedlerchr Oct 25, 2019
3778214
Merge remote-tracking branch 'upstream/master' into convertRemainingTest
Siedlerchr Nov 5, 2019
e475748
Merge branch 'master' into convertRemainingTest
tobiasdiez Nov 11, 2019
06d9ec1
Cleanup code
tobiasdiez Nov 11, 2019
ae96327
Don't allow codecov to fail
tobiasdiez Nov 11, 2019
dfb7a18
Temporarily allow failure of database tests
tobiasdiez Nov 11, 2019
7152a3b
Readd database test to codecov
tobiasdiez Nov 11, 2019
7bbd564
Try to ignore failures the other way
tobiasdiez Nov 11, 2019
b627365
Or maybe this way?
tobiasdiez Nov 11, 2019
8a82ef9
Yet another try
tobiasdiez Nov 11, 2019
68e51e1
Well...maybe now
tobiasdiez Nov 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ dependencies {


testCompile 'io.github.classgraph:classgraph:4.8.53'
testCompile 'junit:junit:4.12'
testImplementation 'org.junit.jupiter:junit-jupiter:5.5.2'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.5.2'
testCompile 'org.junit.platform:junit-platform-launcher:1.5.2'
Expand Down Expand Up @@ -441,31 +440,49 @@ localization.script = 'scripts/syncLang.py'
// Test tasks
test {
useJUnitPlatform {
excludeTags 'DatabaseTest', 'FetcherTest', 'GUITest', 'org.jabref.testutils.category.FetcherTest', 'org.jabref.testutils.category.GUITest'
excludeTags 'DatabaseTest', 'FetcherTest', 'GUITest'
}

testLogging {
// set options for log level LIFECYCLE
events "failed"
events = ["FAILED", "STANDARD_OUT", "STANDARD_ERROR"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koppor just change this lines.
Im only on mobile for the next days without access to a PC 💻

exceptionFormat "full"
}
}

task databaseTest(type: Test) {
useJUnit {
includeCategories 'org.jabref.testutils.category.DatabaseTest'
useJUnitPlatform {
includeTags 'DatabaseTest'
}

testLogging {
// set options for log level LIFECYCLE
events = ["FAILED", "STANDARD_OUT", "STANDARD_ERROR"]
exceptionFormat "full"
}
}

task fetcherTest(type: Test) {
useJUnit {
includeCategories 'org.jabref.testutils.category.FetcherTest'
useJUnitPlatform {
includeTags 'FetcherTest'
}

testLogging {
// set options for log level LIFECYCLE
events = ["FAILED", "STANDARD_OUT", "STANDARD_ERROR"]
exceptionFormat "full"
}
}

task guiTest(type: Test) {
useJUnit {
includeCategories 'org.jabref.testutils.category.GUITest'
useJUnitPlatform {
includeTags 'GUITest'
}

testLogging {
// set options for log level LIFECYCLE
events = ["FAILED", "STANDARD_OUT", "STANDARD_ERROR"]
exceptionFormat "full"
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/jabref/logic/shared/DBMSConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class DBMSConnection implements DatabaseConnection {
private final DBMSConnectionProperties properties;

public DBMSConnection(DBMSConnectionProperties connectionProperties) throws SQLException, InvalidDBMSConnectionPropertiesException {

if (!connectionProperties.isValid()) {
throw new InvalidDBMSConnectionPropertiesException();
}
Expand All @@ -34,7 +33,6 @@ public DBMSConnection(DBMSConnectionProperties connectionProperties) throws SQLE
// we use the side effect of getAvailableDBMSTypes() - it loads all available drivers
DBMSConnection.getAvailableDBMSTypes();
this.connection = DriverManager.getConnection(connectionProperties.getUrl(), connectionProperties.asProperties());

} catch (SQLException e) {
// Some systems like PostgreSQL retrieves 0 to every exception.
// Therefore a stable error determination is not possible.
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/module-info.test
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
--add-modules
// Make junit4 module visible (only required for last remaining parameterized tests)
junit

--add-modules
// Add junit5 module dependency
org.junit.jupiter.api
Expand Down
98 changes: 50 additions & 48 deletions src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
import java.util.stream.Collectors;

import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.logic.shared.exception.OfflineLockException;
import org.jabref.model.database.shared.DBMSType;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.InternalField;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UnknownField;
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.testutils.category.DatabaseTest;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand All @@ -34,37 +30,30 @@
@DatabaseTest
class DBMSProcessorTest {

private static Stream<Object[]> getTestingDatabaseSystems() throws InvalidDBMSConnectionPropertiesException, SQLException {
Collection<Object[]> result = new ArrayList<>();
for (DBMSType dbmsType : TestManager.getDBMSTypeTestParameter()) {
result.add(new Object[]{
dbmsType,
TestConnector.getTestDBMSConnection(dbmsType),
DBMSProcessor.getProcessorInstance(TestConnector.getTestDBMSConnection(dbmsType))});
}
return result.stream();
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testCheckBaseIntegrity(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws SQLException {
dbmsProcessor.setupSharedDatabase();
assertTrue(dbmsProcessor.checkBaseIntegrity());
clear(dbmsConnection);
assertFalse(dbmsProcessor.checkBaseIntegrity());

clear(dbmsConnection);
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testSetUpSharedDatabase(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws SQLException {
dbmsProcessor.setupSharedDatabase();
clear(dbmsConnection);
dbmsProcessor.setupSharedDatabase();
assertTrue(dbmsProcessor.checkBaseIntegrity());

clear(dbmsConnection);
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testInsertEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws SQLException {
dbmsProcessor.setupSharedDatabase();
BibEntry expectedEntry = getBibEntryExample();
Expand All @@ -91,52 +80,54 @@ void testInsertEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProce
}
}

Map<Field, String> expectedFieldMap = expectedEntry.getFieldMap();
Map<String, String> expectedFieldMap = expectedEntry.getFieldMap().entrySet().stream().collect(Collectors.toMap((entry) -> entry.getKey().getName(), Map.Entry::getValue));

assertEquals(expectedFieldMap, actualFieldMap);
clear(dbmsConnection);
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
void testUpdateEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws OfflineLockException, SQLException {
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testUpdateEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {
dbmsProcessor.setupSharedDatabase();
BibEntry expectedEntry = getBibEntryExample();

dbmsProcessor.insertEntry(expectedEntry);

expectedEntry.setType(StandardEntryType.Book);
expectedEntry.setField(StandardField.AUTHOR, "Michael J and Hutchings");
expectedEntry.setField(new UnknownField("customField"), "custom value");
expectedEntry.clearField(StandardField.BOOKTITLE);

dbmsProcessor.updateEntry(expectedEntry);

Optional<BibEntry> actualEntryOptional = dbmsProcessor
.getSharedEntry(expectedEntry.getSharedBibEntryData().getSharedID());
Optional<BibEntry> actualEntry = dbmsProcessor.getSharedEntry(expectedEntry.getSharedBibEntryData().getSharedID());
assertEquals(expectedEntry, actualEntry.get());

assertEquals(expectedEntry, actualEntryOptional.get());
clear(dbmsConnection);
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
void testGetEntriesByIdList(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws OfflineLockException, SQLException {
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testGetEntriesByIdList(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {
dbmsProcessor.setupSharedDatabase();
BibEntry firstEntry = getBibEntryExample();
firstEntry.setId("1");
firstEntry.setField(InternalField.INTERNAL_ID_FIELD, "00001");
BibEntry secondEntry = getBibEntryExample();
secondEntry.setId("2");
secondEntry.setField(InternalField.INTERNAL_ID_FIELD, "00002");

dbmsProcessor.insertEntry(firstEntry);
dbmsProcessor.insertEntry(secondEntry);

List<BibEntry> sharedEntriesByIdList = dbmsProcessor.getSharedEntries(Arrays.asList(1, 2));

assertEquals(firstEntry.getId(), sharedEntriesByIdList.get(0).getId());
assertEquals(secondEntry.getId(), sharedEntriesByIdList.get(1).getId());
clear(dbmsConnection);

assertEquals(firstEntry, sharedEntriesByIdList.get(0));
assertEquals(secondEntry, sharedEntriesByIdList.get(1));

}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testUpdateNewerEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws OfflineLockException, SQLException {
dbmsProcessor.setupSharedDatabase();
BibEntry bibEntry = getBibEntryExample();
Expand All @@ -148,10 +139,12 @@ void testUpdateNewerEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMS
bibEntry.setField(StandardField.YEAR, "1993");

assertThrows(OfflineLockException.class, () -> dbmsProcessor.updateEntry(bibEntry));

clear(dbmsConnection);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it important that clear is always invoked? I think, if a assert method fails, then an exception is thrown and thus clear is never called. Either move it before assert or use try finally.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I addtionally call clear now as first method in setup :-D

}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testUpdateEqualEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws OfflineLockException, SQLException {
dbmsProcessor.setupSharedDatabase();
BibEntry expectedBibEntry = getBibEntryExample();
Expand All @@ -162,13 +155,15 @@ void testUpdateEqualEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMS
dbmsProcessor.updateEntry(expectedBibEntry);

Optional<BibEntry> actualBibEntryOptional = dbmsProcessor
.getSharedEntry(expectedBibEntry.getSharedBibEntryData().getSharedID());
.getSharedEntry(expectedBibEntry.getSharedBibEntryData().getSharedID());

assertEquals(expectedBibEntry, actualBibEntryOptional.get());

clear(dbmsConnection);
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testRemoveEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws SQLException {
dbmsProcessor.setupSharedDatabase();
BibEntry bibEntry = getBibEntryExample();
Expand All @@ -178,10 +173,11 @@ void testRemoveEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProce
try (ResultSet resultSet = selectFrom("ENTRY", dbmsConnection, dbmsProcessor)) {
assertFalse(resultSet.next());
}
clear(dbmsConnection);
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testGetSharedEntries(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws SQLException {
dbmsProcessor.setupSharedDatabase();
BibEntry bibEntry = getBibEntryExampleWithEmptyFields();
Expand All @@ -192,32 +188,35 @@ void testGetSharedEntries(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMS
List<BibEntry> actualEntries = dbmsProcessor.getSharedEntries();

assertEquals(expectedEntries, actualEntries);
clear(dbmsConnection);
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testGetSharedEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws SQLException {
dbmsProcessor.setupSharedDatabase();
BibEntry expectedBibEntry = getBibEntryExampleWithEmptyFields();

dbmsProcessor.insertEntry(expectedBibEntry);

Optional<BibEntry> actualBibEntryOptional = dbmsProcessor
.getSharedEntry(expectedBibEntry.getSharedBibEntryData().getSharedID());
Optional<BibEntry> actualBibEntryOptional = dbmsProcessor.getSharedEntry(expectedBibEntry.getSharedBibEntryData().getSharedID());

assertEquals(expectedBibEntry, actualBibEntryOptional.get());
clear(dbmsConnection);
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testGetNotExistingSharedEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws SQLException {
dbmsProcessor.setupSharedDatabase();
Optional<BibEntry> actualBibEntryOptional = dbmsProcessor.getSharedEntry(1);
assertFalse(actualBibEntryOptional.isPresent());

clear(dbmsConnection);
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testGetSharedIDVersionMapping(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws OfflineLockException, SQLException {
dbmsProcessor.setupSharedDatabase();
BibEntry firstEntry = getBibEntryExample();
Expand All @@ -234,10 +233,12 @@ void testGetSharedIDVersionMapping(DBMSType dbmsType, DBMSConnection dbmsConnect
Map<Integer, Integer> actualIDVersionMap = dbmsProcessor.getSharedIDVersionMapping();

assertEquals(expectedIDVersionMap, actualIDVersionMap);

clear(dbmsConnection);
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testGetSharedMetaData(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws SQLException {
dbmsProcessor.setupSharedDatabase();
insertMetaData("databaseType", "bibtex;", dbmsConnection, dbmsProcessor);
Expand All @@ -249,6 +250,7 @@ void testGetSharedMetaData(DBMSType dbmsType, DBMSConnection dbmsConnection, DBM
Map<String, String> actualMetaData = dbmsProcessor.getSharedMetaData();

assertEquals(expectedMetaData, actualMetaData);
clear(dbmsConnection);
}

@ParameterizedTest
Expand All @@ -261,6 +263,7 @@ void testSetSharedMetaData(DBMSType dbmsType, DBMSConnection dbmsConnection, DBM
Map<String, String> actualMetaData = dbmsProcessor.getSharedMetaData();

assertEquals(expectedMetaData, actualMetaData);
clear(dbmsConnection);
}

private Map<String, String> getMetaDataExample() {
Expand Down Expand Up @@ -307,8 +310,8 @@ private ResultSet selectFrom(String table, DBMSConnection dbmsConnection, DBMSPr
private void insertMetaData(String key, String value, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) {
try {
dbmsConnection.getConnection().createStatement().executeUpdate("INSERT INTO " + escape("METADATA", dbmsProcessor) + "("
+ escape("KEY", dbmsProcessor) + ", " + escape("VALUE", dbmsProcessor) + ") VALUES("
+ escapeValue(key) + ", " + escapeValue(value) + ")");
+ escape("KEY", dbmsProcessor) + ", " + escape("VALUE", dbmsProcessor) + ") VALUES("
+ escapeValue(key) + ", " + escapeValue(value) + ")");
} catch (SQLException e) {
fail(e.getMessage());
}
Expand All @@ -322,7 +325,6 @@ private String escapeValue(String value) {
return "'" + value + "'";
}

@AfterEach
void clear(DBMSConnection dbmsConnection) throws SQLException {
TestManager.clearTables(dbmsConnection);
}
Expand Down
Loading