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 2 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
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ dependencies {
exclude module: "log4j-core"
}

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
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
127 changes: 79 additions & 48 deletions src/test/java/org/jabref/logic/shared/DBMSSynchronizerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
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.logic.shared.exception.OfflineLockException;
import org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern;
import org.jabref.model.cleanup.FieldFormatterCleanup;
import org.jabref.model.cleanup.FieldFormatterCleanups;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.database.shared.DBMSType;
import org.jabref.model.database.shared.DatabaseNotSupportedException;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.event.EntryEventSource;
import org.jabref.model.entry.field.StandardField;
Expand All @@ -29,51 +28,40 @@
import org.jabref.model.util.DummyFileUpdateMonitor;
import org.jabref.testutils.category.DatabaseTest;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

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

@DatabaseTest
public class DBMSSynchronizerTest {

@Parameter
public DBMSType dbmsType;
private DBMSSynchronizer dbmsSynchronizer;
private DBMSConnection dbmsConnection;
private DBMSProcessor dbmsProcessor;
private BibDatabase bibDatabase;
private GlobalBibtexKeyPattern pattern;

@Parameters(name = "Test with {0} database system")
public static Collection<DBMSType> getTestingDatabaseSystems() {
return TestManager.getDBMSTypeTestParameter();
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();
}

@BeforeEach
public void setUp() throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException {

dbmsConnection = TestConnector.getTestDBMSConnection(dbmsType);
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void testEntryAddedEventListener(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {

bibDatabase = new BibDatabase();
BibDatabaseContext context = new BibDatabaseContext(bibDatabase);

pattern = GlobalBibtexKeyPattern.fromPattern("[auth][year]");

dbmsSynchronizer = new DBMSSynchronizer(context, ',', pattern, new DummyFileUpdateMonitor());
dbmsProcessor = DBMSProcessor.getProcessorInstance(dbmsConnection);

bibDatabase.registerListener(dbmsSynchronizer);

dbmsSynchronizer.openSharedDatabase(dbmsConnection);
}

@Test
public void testEntryAddedEventListener() {
BibEntry expectedEntry = getBibEntryExample(1);
BibEntry furtherEntry = getBibEntryExample(1);

Expand All @@ -87,8 +75,15 @@ public void testEntryAddedEventListener() {
assertEquals(expectedEntry, actualEntries.get(0));
}

@Test
public void testFieldChangedEventListener() {
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void testFieldChangedEventListener(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {

bibDatabase = new BibDatabase();
BibDatabaseContext context = new BibDatabaseContext(bibDatabase);
dbmsSynchronizer = new DBMSSynchronizer(context, ',', pattern, new DummyFileUpdateMonitor());
dbmsSynchronizer.openSharedDatabase(dbmsConnection);

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

Expand All @@ -102,8 +97,15 @@ public void testFieldChangedEventListener() {
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

}

@Test
public void testEntryRemovedEventListener() {
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void testEntryRemovedEventListener(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {

bibDatabase = new BibDatabase();
BibDatabaseContext context = new BibDatabaseContext(bibDatabase);
dbmsSynchronizer = new DBMSSynchronizer(context, ',', pattern, new DummyFileUpdateMonitor());
dbmsSynchronizer.openSharedDatabase(dbmsConnection);

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

Expand All @@ -124,8 +126,15 @@ public void testEntryRemovedEventListener() {
assertEquals(bibEntry, actualEntries.get(0));
}

@Test
public void testMetaDataChangedEventListener() {
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void testMetaDataChangedEventListener(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {

bibDatabase = new BibDatabase();
Copy link
Member

Choose a reason for hiding this comment

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

The first three lines are shared between all tests, thus please extract them to the setup method.

BibDatabaseContext context = new BibDatabaseContext(bibDatabase);
dbmsSynchronizer = new DBMSSynchronizer(context, ',', pattern, new DummyFileUpdateMonitor());
dbmsSynchronizer.openSharedDatabase(dbmsConnection);

MetaData testMetaData = new MetaData();
testMetaData.registerListener(dbmsSynchronizer);
dbmsSynchronizer.setMetaData(testMetaData);
Expand All @@ -137,17 +146,29 @@ public void testMetaDataChangedEventListener() {
assertEquals(expectedMap, actualMap);
}

@Test
public void testInitializeDatabases() throws SQLException, DatabaseNotSupportedException {
clear();
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void testInitializeDatabases(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {
bibDatabase = new BibDatabase();
BibDatabaseContext context = new BibDatabaseContext(bibDatabase);
dbmsSynchronizer = new DBMSSynchronizer(context, ',', pattern, new DummyFileUpdateMonitor());
dbmsSynchronizer.openSharedDatabase(dbmsConnection);

clear(dbmsConnection);
dbmsSynchronizer.initializeDatabases();
assertTrue(dbmsProcessor.checkBaseIntegrity());
dbmsSynchronizer.initializeDatabases();
assertTrue(dbmsProcessor.checkBaseIntegrity());
}

@Test
public void testSynchronizeLocalDatabaseWithEntryRemoval() {
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void testSynchronizeLocalDatabaseWithEntryRemoval(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {
bibDatabase = new BibDatabase();
BibDatabaseContext context = new BibDatabaseContext(bibDatabase);
dbmsSynchronizer = new DBMSSynchronizer(context, ',', pattern, new DummyFileUpdateMonitor());
dbmsSynchronizer.openSharedDatabase(dbmsConnection);

List<BibEntry> expectedBibEntries = Arrays.asList(getBibEntryExample(1), getBibEntryExample(2));

dbmsProcessor.insertEntry(expectedBibEntries.get(0));
Expand All @@ -169,8 +190,14 @@ public void testSynchronizeLocalDatabaseWithEntryRemoval() {
assertEquals(expectedBibEntries, bibDatabase.getEntries());
}

@Test
public void testSynchronizeLocalDatabaseWithEntryUpdate() throws OfflineLockException, SQLException {
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void testSynchronizeLocalDatabaseWithEntryUpdate(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {
bibDatabase = new BibDatabase();
BibDatabaseContext context = new BibDatabaseContext(bibDatabase);
dbmsSynchronizer = new DBMSSynchronizer(context, ',', pattern, new DummyFileUpdateMonitor());
dbmsSynchronizer.openSharedDatabase(dbmsConnection);

BibEntry bibEntry = getBibEntryExample(1);
bibDatabase.insertEntry(bibEntry);
assertEquals(1, bibDatabase.getEntries().size());
Expand All @@ -187,14 +214,19 @@ public void testSynchronizeLocalDatabaseWithEntryUpdate() throws OfflineLockExce
assertEquals(bibDatabase.getEntries(), dbmsProcessor.getSharedEntries());
}

@Test
public void testApplyMetaData() {
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void testApplyMetaData(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception {
bibDatabase = new BibDatabase();
BibDatabaseContext context = new BibDatabaseContext(bibDatabase);
dbmsSynchronizer = new DBMSSynchronizer(context, ',', pattern, new DummyFileUpdateMonitor());
dbmsSynchronizer.openSharedDatabase(dbmsConnection);

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

MetaData testMetaData = new MetaData();
testMetaData.setSaveActions(new FieldFormatterCleanups(true,
Collections.singletonList(new FieldFormatterCleanup(StandardField.AUTHOR, new LowerCaseFormatter()))));
testMetaData.setSaveActions(new FieldFormatterCleanups(true, Collections.singletonList(new FieldFormatterCleanup(StandardField.AUTHOR, new LowerCaseFormatter()))));
dbmsSynchronizer.setMetaData(testMetaData);

dbmsSynchronizer.applyMetaData();
Expand All @@ -211,8 +243,7 @@ private BibEntry getBibEntryExample(int index) {
return bibEntry;
}

@AfterEach
public void clear() throws SQLException {
public void clear(DBMSConnection dbmsConnection) throws SQLException {
tobiasdiez marked this conversation as resolved.
Show resolved Hide resolved
TestManager.clearTables(dbmsConnection);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.jabref.logic.shared;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.stream.Stream;

import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.model.Defaults;
Expand All @@ -17,11 +19,9 @@
import org.jabref.model.util.DummyFileUpdateMonitor;
import org.jabref.testutils.category.DatabaseTest;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -32,23 +32,27 @@
@DatabaseTest
public class SynchronizationTestSimulator {

@Parameter
public DBMSType dbmsType;
private BibDatabaseContext clientContextA;
private BibDatabaseContext clientContextB;
private SynchronizationTestEventListener eventListenerB; // used to monitor occurring events
private DBMSConnection dbmsConnection;

@Parameters(name = "Test with {0} database system")
public static Collection<DBMSType> getTestingDatabaseSystems() {
return TestManager.getDBMSTypeTestParameter();
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();
}

@BeforeEach
public void setUp() throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException {
this.dbmsConnection = TestConnector.getTestDBMSConnection(dbmsType);
@MethodSource("getTestingDatabaseSystems")
public void setUp(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException {
Copy link
Member

Choose a reason for hiding this comment

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

Does this really works, i.e. did you tested that all test methods are invoked correctly? According to the documentation the before/aftereach handlers don't get their parameterized resolved.

Since a test class may contain regular tests as well as parameterized tests with different parameter lists, values from argument sources are not resolved for lifecycle methods (e.g. @beforeeach) and test class constructors.

But this is in a slightly different context. If this method works, then it should also be used in DBMSSynchronizerTest.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well I will see if I can test it locally, but otherwise Travis is green and so I thought it's working

Copy link
Member

Choose a reason for hiding this comment

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

Without double chcking (but trying to understand the implications of Tobias' explanation), I would bet that the test use only one database system and not all avaiable.


GlobalBibtexKeyPattern pattern = GlobalBibtexKeyPattern.fromPattern("[auth][year]");
clientContextA = new BibDatabaseContext(new Defaults(BibDatabaseMode.BIBTEX));
DBMSSynchronizer synchronizerA = new DBMSSynchronizer(clientContextA, ',', pattern, new DummyFileUpdateMonitor());
clientContextA.convertToSharedDatabase(synchronizerA);
Expand All @@ -62,7 +66,8 @@ public void setUp() throws SQLException, DatabaseNotSupportedException, InvalidD
clientContextB.getDBMSSynchronizer().registerListener(eventListenerB);
}

@Test
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void simulateEntryInsertionAndManualPull() {
//client A inserts an entry
clientContextA.getDatabase().insertEntry(getBibEntryExample(1));
Expand All @@ -74,7 +79,8 @@ public void simulateEntryInsertionAndManualPull() {
assertEquals(clientContextA.getDatabase().getEntries(), clientContextB.getDatabase().getEntries());
}

@Test
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void simulateEntryUpdateAndManualPull() {
BibEntry bibEntry = getBibEntryExample(1);
//client A inserts an entry
Expand All @@ -89,7 +95,8 @@ public void simulateEntryUpdateAndManualPull() {
assertEquals(clientContextA.getDatabase().getEntries(), clientContextB.getDatabase().getEntries());
}

@Test
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void simulateEntryDelitionAndManualPull() {
BibEntry bibEntry = getBibEntryExample(1);
//client A inserts an entry
Expand All @@ -110,7 +117,8 @@ public void simulateEntryDelitionAndManualPull() {
assertTrue(clientContextB.getDatabase().getEntries().isEmpty());
}

@Test
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void simulateUpdateOnNoLongerExistingEntry() {
BibEntry bibEntryOfClientA = getBibEntryExample(1);
//client A inserts an entry
Expand All @@ -136,7 +144,8 @@ public void simulateUpdateOnNoLongerExistingEntry() {
assertEquals(bibEntryOfClientB, eventListenerB.getSharedEntryNotPresentEvent().getBibEntry());
}

@Test
@ParameterizedTest
@MethodSource("getTestingDatabaseSystems")
public void simulateEntryChangeConflicts() {
BibEntry bibEntryOfClientA = getBibEntryExample(1);
//client A inserts an entry
Expand Down Expand Up @@ -172,8 +181,4 @@ private BibEntry getBibEntryExample(int index) {
return bibEntry;
}

@AfterEach
public void clear() throws SQLException {
tobiasdiez marked this conversation as resolved.
Show resolved Hide resolved
TestManager.clearTables(dbmsConnection);
}
}