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
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -440,7 +440,7 @@ 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 {
@@ -454,7 +454,8 @@ task databaseTest(type: Test) {
useJUnitPlatform {
includeTags 'DatabaseTest'
}
testLogging {

testLogging {
// set options for log level LIFECYCLE
events = ["FAILED", "STANDARD_OUT", "STANDARD_ERROR"]
exceptionFormat "full"
@@ -465,6 +466,7 @@ task fetcherTest(type: Test) {
useJUnitPlatform {
includeTags 'FetcherTest'
}

testLogging {
// set options for log level LIFECYCLE
events = ["FAILED", "STANDARD_OUT", "STANDARD_ERROR"]
@@ -476,6 +478,7 @@ task guiTest(type: Test) {
useJUnitPlatform {
includeTags 'GUITest'
}

testLogging {
// set options for log level LIFECYCLE
events = ["FAILED", "STANDARD_OUT", "STANDARD_ERROR"]
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
@@ -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();
}
@@ -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.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
@@ -372,7 +372,7 @@ public Optional<FieldChange> setType(EntryType newType, EntriesEventSource event
* @return a set of existing field names
*/
public Set<Field> getFields() {
return fields.keySet();
return Collections.unmodifiableSet(fields.keySet());
}

/**
47 changes: 15 additions & 32 deletions src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java
Original file line number Diff line number Diff line change
@@ -2,17 +2,13 @@

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.Collectors;
import java.util.stream.Stream;

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;
@@ -34,19 +30,8 @@
@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());
@@ -57,7 +42,7 @@ void testCheckBaseIntegrity(DBMSType dbmsType, DBMSConnection dbmsConnection, DB
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testSetUpSharedDatabase(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws SQLException {
dbmsProcessor.setupSharedDatabase();
clear(dbmsConnection);
@@ -68,7 +53,7 @@ void testSetUpSharedDatabase(DBMSType dbmsType, DBMSConnection dbmsConnection, D
}

@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();
@@ -102,28 +87,26 @@ void testInsertEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProce
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@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")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
void testGetEntriesByIdList(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {
dbmsProcessor.setupSharedDatabase();
BibEntry firstEntry = getBibEntryExample();
@@ -144,7 +127,7 @@ void testGetEntriesByIdList(DBMSType dbmsType, DBMSConnection dbmsConnection, DB
}

@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();
@@ -161,7 +144,7 @@ void testUpdateNewerEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMS
}

@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();
@@ -180,7 +163,7 @@ void testUpdateEqualEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMS
}

@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();
@@ -194,7 +177,7 @@ void testRemoveEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProce
}

@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();
@@ -209,7 +192,7 @@ void testGetSharedEntries(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMS
}

@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();
@@ -223,7 +206,7 @@ void testGetSharedEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSPr
}

@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);
@@ -233,7 +216,7 @@ void testGetNotExistingSharedEntry(DBMSType dbmsType, DBMSConnection dbmsConnect
}

@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();
@@ -255,7 +238,7 @@ void testGetSharedIDVersionMapping(DBMSType dbmsType, DBMSConnection dbmsConnect
}

@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);
50 changes: 16 additions & 34 deletions src/test/java/org/jabref/logic/shared/DBMSSynchronizerTest.java
Original file line number Diff line number Diff line change
@@ -3,15 +3,12 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import org.jabref.logic.exporter.MetaDataSerializer;
import org.jabref.logic.formatter.casechanger.LowerCaseFormatter;
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern;
import org.jabref.model.cleanup.FieldFormatterCleanup;
import org.jabref.model.cleanup.FieldFormatterCleanups;
@@ -41,20 +38,9 @@ public class DBMSSynchronizerTest {
private BibDatabase bibDatabase;
private final GlobalBibtexKeyPattern pattern = GlobalBibtexKeyPattern.fromPattern("[auth][year]");

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();
}

public void setUp(DBMSConnection dbmsConnection) throws Exception {
clear(dbmsConnection);

bibDatabase = new BibDatabase();
BibDatabaseContext context = new BibDatabaseContext(bibDatabase);
dbmsSynchronizer = new DBMSSynchronizer(context, ',', pattern, new DummyFileUpdateMonitor());
@@ -65,12 +51,10 @@ public void setUp(DBMSConnection dbmsConnection) throws Exception {
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
public void testEntryAddedEventListener(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {

System.out.println("dbmstype" + dbmsType);

setUp(dbmsConnection);

BibEntry expectedEntry = getBibEntryExample(1);
BibEntry furtherEntry = getBibEntryExample(1);

@@ -87,31 +71,28 @@ public void testEntryAddedEventListener(DBMSType dbmsType, DBMSConnection dbmsCo
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
public void testFieldChangedEventListener(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {

setUp(dbmsConnection);

BibEntry expectedEntry = getBibEntryExample(1);
expectedEntry.registerListener(dbmsSynchronizer);

bibDatabase.insertEntry(expectedEntry);
bibDatabase.insertEntry(expectedEntry);
expectedEntry.setField(StandardField.AUTHOR, "Brad L and Gilson");
expectedEntry.setField(StandardField.TITLE, "The micro multiplexer", EntriesEventSource.SHARED);

List<BibEntry> actualEntries = dbmsProcessor.getSharedEntries();
assertEquals(1, actualEntries.size());
assertEquals(expectedEntry.getField(StandardField.AUTHOR), actualEntries.get(0).getField(StandardField.AUTHOR));
assertEquals("The nano processor1", actualEntries.get(0).getField(StandardField.TITLE).get());
Copy link
Member Author

Choose a reason for hiding this comment

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

See here that the title is different @tobiasdiez

//somehow the field stable is not filled
assertEquals(Collections.singletonList(expectedEntry), actualEntries);
Copy link
Member Author

@Siedlerchr Siedlerchr Nov 12, 2019

Choose a reason for hiding this comment

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

This is wrong. The test explicitly checks for a changed title! Please revert!


clear(dbmsConnection);
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
public void testEntryRemovedEventListener(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {
setUp(dbmsConnection);

BibEntry bibEntry = getBibEntryExample(1);
bibDatabase.insertEntry(bibEntry);

@@ -135,10 +116,10 @@ public void testEntryRemovedEventListener(DBMSType dbmsType, DBMSConnection dbms
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
public void testMetaDataChangedEventListener(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {

setUp(dbmsConnection);

MetaData testMetaData = new MetaData();
testMetaData.registerListener(dbmsSynchronizer);
dbmsSynchronizer.setMetaData(testMetaData);
@@ -148,11 +129,12 @@ public void testMetaDataChangedEventListener(DBMSType dbmsType, DBMSConnection d
Map<String, String> actualMap = dbmsProcessor.getSharedMetaData();

assertEquals(expectedMap, actualMap);

clear(dbmsConnection);
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
public void testInitializeDatabases(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {
setUp(dbmsConnection);

@@ -165,7 +147,7 @@ public void testInitializeDatabases(DBMSType dbmsType, DBMSConnection dbmsConnec
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
public void testSynchronizeLocalDatabaseWithEntryRemoval(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {
setUp(dbmsConnection);

@@ -193,7 +175,7 @@ public void testSynchronizeLocalDatabaseWithEntryRemoval(DBMSType dbmsType, DBMS
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
public void testSynchronizeLocalDatabaseWithEntryUpdate(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {
setUp(dbmsConnection);

@@ -215,7 +197,7 @@ public void testSynchronizeLocalDatabaseWithEntryUpdate(DBMSType dbmsType, DBMSC
}

@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
@MethodSource("org.jabref.logic.shared.TestManager#getTestingDatabaseSystems")
public void testApplyMetaData(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {
setUp(dbmsConnection);

Loading