-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 18 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 |
---|---|---|
|
@@ -9,19 +9,19 @@ | |
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; | ||
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; | ||
|
||
|
@@ -37,10 +37,10 @@ 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))}); | ||
result.add(new Object[] { | ||
dbmsType, | ||
TestConnector.getTestDBMSConnection(dbmsType), | ||
DBMSProcessor.getProcessorInstance(TestConnector.getTestDBMSConnection(dbmsType))}); | ||
} | ||
return result.stream(); | ||
} | ||
|
@@ -52,6 +52,8 @@ void testCheckBaseIntegrity(DBMSType dbmsType, DBMSConnection dbmsConnection, DB | |
assertTrue(dbmsProcessor.checkBaseIntegrity()); | ||
clear(dbmsConnection); | ||
assertFalse(dbmsProcessor.checkBaseIntegrity()); | ||
|
||
clear(dbmsConnection); | ||
} | ||
|
||
@ParameterizedTest | ||
|
@@ -61,6 +63,8 @@ void testSetUpSharedDatabase(DBMSType dbmsType, DBMSConnection dbmsConnection, D | |
clear(dbmsConnection); | ||
dbmsProcessor.setupSharedDatabase(); | ||
assertTrue(dbmsProcessor.checkBaseIntegrity()); | ||
|
||
clear(dbmsConnection); | ||
} | ||
|
||
@ParameterizedTest | ||
|
@@ -91,14 +95,15 @@ 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 { | ||
void testUpdateEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws Exception { | ||
dbmsProcessor.setupSharedDatabase(); | ||
BibEntry expectedEntry = getBibEntryExample(); | ||
|
||
|
@@ -111,28 +116,31 @@ void testUpdateEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProce | |
|
||
dbmsProcessor.updateEntry(expectedEntry); | ||
|
||
Optional<BibEntry> actualEntryOptional = dbmsProcessor | ||
.getSharedEntry(expectedEntry.getSharedBibEntryData().getSharedID()); | ||
Optional<BibEntry> actualEntryOptional = dbmsProcessor.getSharedEntry(expectedEntry.getSharedBibEntryData().getSharedID()); | ||
tobiasdiez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
assertEquals(expectedEntry, actualEntryOptional.get()); | ||
clear(dbmsConnection); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getTestingDatabaseSystems") | ||
void testGetEntriesByIdList(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws OfflineLockException, SQLException { | ||
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 | ||
|
@@ -148,6 +156,8 @@ void testUpdateNewerEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMS | |
bibEntry.setField(StandardField.YEAR, "1993"); | ||
|
||
assertThrows(OfflineLockException.class, () -> dbmsProcessor.updateEntry(bibEntry)); | ||
|
||
clear(dbmsConnection); | ||
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. Is it important that 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. That's why I addtionally call clear now as first method in setup :-D |
||
} | ||
|
||
@ParameterizedTest | ||
|
@@ -162,9 +172,11 @@ 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 | ||
|
@@ -178,6 +190,7 @@ void testRemoveEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProce | |
try (ResultSet resultSet = selectFrom("ENTRY", dbmsConnection, dbmsProcessor)) { | ||
assertFalse(resultSet.next()); | ||
} | ||
clear(dbmsConnection); | ||
} | ||
|
||
@ParameterizedTest | ||
|
@@ -192,6 +205,7 @@ void testGetSharedEntries(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMS | |
List<BibEntry> actualEntries = dbmsProcessor.getSharedEntries(); | ||
|
||
assertEquals(expectedEntries, actualEntries); | ||
clear(dbmsConnection); | ||
} | ||
|
||
@ParameterizedTest | ||
|
@@ -202,10 +216,10 @@ void testGetSharedEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSPr | |
|
||
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 | ||
|
@@ -214,6 +228,8 @@ void testGetNotExistingSharedEntry(DBMSType dbmsType, DBMSConnection dbmsConnect | |
dbmsProcessor.setupSharedDatabase(); | ||
Optional<BibEntry> actualBibEntryOptional = dbmsProcessor.getSharedEntry(1); | ||
assertFalse(actualBibEntryOptional.isPresent()); | ||
|
||
clear(dbmsConnection); | ||
} | ||
|
||
@ParameterizedTest | ||
|
@@ -234,6 +250,8 @@ void testGetSharedIDVersionMapping(DBMSType dbmsType, DBMSConnection dbmsConnect | |
Map<Integer, Integer> actualIDVersionMap = dbmsProcessor.getSharedIDVersionMapping(); | ||
|
||
assertEquals(expectedIDVersionMap, actualIDVersionMap); | ||
|
||
clear(dbmsConnection); | ||
} | ||
|
||
@ParameterizedTest | ||
|
@@ -249,6 +267,7 @@ void testGetSharedMetaData(DBMSType dbmsType, DBMSConnection dbmsConnection, DBM | |
Map<String, String> actualMetaData = dbmsProcessor.getSharedMetaData(); | ||
|
||
assertEquals(expectedMetaData, actualMetaData); | ||
clear(dbmsConnection); | ||
} | ||
|
||
@ParameterizedTest | ||
|
@@ -261,6 +280,7 @@ void testSetSharedMetaData(DBMSType dbmsType, DBMSConnection dbmsConnection, DBM | |
Map<String, String> actualMetaData = dbmsProcessor.getSharedMetaData(); | ||
|
||
assertEquals(expectedMetaData, actualMetaData); | ||
clear(dbmsConnection); | ||
} | ||
|
||
private Map<String, String> getMetaDataExample() { | ||
|
@@ -307,8 +327,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()); | ||
} | ||
|
@@ -322,7 +342,6 @@ private String escapeValue(String value) { | |
return "'" + value + "'"; | ||
} | ||
|
||
@AfterEach | ||
void clear(DBMSConnection dbmsConnection) throws SQLException { | ||
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.
@koppor just change this lines.
Im only on mobile for the next days without access to a PC 💻