-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Changes from 2 commits
ac526de
9f8ad5a
b13e470
1374d20
9a4a52a
48c545c
09b131b
c284667
2041c5b
0717211
ac192c0
a324878
05398b0
98f0a7c
6a2760c
96d65e9
b1ff631
0d380fd
3778214
e475748
06d9ec1
ae96327
dfb7a18
7152a3b
7bbd564
b627365
8a82ef9
68e51e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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); | ||
|
||
|
@@ -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); | ||
|
||
|
@@ -102,8 +97,15 @@ public void testFieldChangedEventListener() { | |
assertEquals("The nano processor1", actualEntries.get(0).getField(StandardField.TITLE).get()); | ||
} | ||
|
||
@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); | ||
|
||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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); | ||
|
@@ -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)); | ||
|
@@ -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()); | ||
|
@@ -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(); | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
But this is in a slightly different context. If this method works, then it should also be used in There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -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)); | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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); | ||
} | ||
} |
There was a problem hiding this comment.
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