Skip to content

Commit

Permalink
test groups as well
Browse files Browse the repository at this point in the history
  • Loading branch information
simonharrer committed Apr 10, 2016
1 parent cadba5f commit 034e550
Showing 1 changed file with 50 additions and 26 deletions.
76 changes: 50 additions & 26 deletions src/test/java/net/sf/jabref/sql/DatabaseImportExportTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ public void testExportToMySQLSingleEntry() throws Exception {
testDatabaseExport(databaseContext, databaseType, databaseName, strings);
}

@Test
public void testExportToMySQLSingleEntrySingleGroup() throws Exception {
Assume.assumeTrue(DevEnvironment.isCIServer());

BibDatabaseContext databaseContext = createContextWithSingleEntrySingleGroup();
DatabaseType databaseType = DatabaseType.MYSQL;

String databaseName = "jabref";
DBStrings strings = new DBStrings();
strings.setPassword("");
strings.setDbPreferences(new DBStringsPreferences("mysql", "localhost", "root", "jabref"));

testDatabaseExport(databaseContext, databaseType, databaseName, strings);
}

@Test
public void testExportToPostgresSingleEntry() throws Exception {
Assume.assumeTrue(DevEnvironment.isCIServer());
Expand All @@ -67,6 +82,21 @@ public void testExportToPostgresSingleEntry() throws Exception {
testDatabaseExport(databaseContext, databaseType, databaseName, strings);
}

@Test
public void testExportToPostgresSingleEntrySingleGroup() throws Exception {
Assume.assumeTrue(DevEnvironment.isCIServer());

BibDatabaseContext databaseContext = createContextWithSingleEntrySingleGroup();
DatabaseType databaseType = DatabaseType.POSTGRESQL;

String databaseName = "jabref";
DBStrings strings = new DBStrings();
strings.setPassword("");
strings.setDbPreferences(new DBStringsPreferences("postgresql", "localhost", "postgres", "jabref"));

testDatabaseExport(databaseContext, databaseType, databaseName, strings);
}

private void testDatabaseExport(BibDatabaseContext databaseContext, DatabaseType databaseType, String databaseName, DBStrings strings) throws Exception {
DatabaseExporter exporter = new DBExporterAndImporterFactory().getExporter(databaseType);
try (Connection connection = exporter.connectToDB(strings)) {
Expand All @@ -82,49 +112,43 @@ private void testDatabaseExport(BibDatabaseContext databaseContext, DatabaseType
assertEquals(1, results.size());
BibtexEntryAssert.assertEquals(databaseContext.getDatabase().getEntries(),
results.get(0).getDatabaseContext().getDatabase().getEntries());

assertEquals(databaseContext.getMetaData().getGroups(), results.get(0).getDatabaseContext().getMetaData().getGroups());
}
}

@Test
public void testExportToFileSingleEntry() throws Exception {
BibDatabaseContext databaseContext = createContextWithSingleEntry();
for (DatabaseType databaseType : DatabaseType.values()) {
DatabaseExporter exporter = new DBExporterAndImporterFactory().getExporter(databaseType);

Path tempFile = Files.createTempFile("jabref", "database-export" + databaseType.getFormattedName());
exporter.exportDatabaseAsFile(databaseContext,
databaseContext.getDatabase().getEntries(),
tempFile.toAbsolutePath().toString(),
StandardCharsets.UTF_8);

Path expectSqlFile = Paths.get("src/test/resources/net/sf/jabref/sql/database-export-single-entry.sql");
assertEquals(
String.join("\n", Files.readAllLines(expectSqlFile, StandardCharsets.UTF_8)),
String.join("\n", Files.readAllLines(tempFile, StandardCharsets.UTF_8))
);
testExportToFile(databaseContext, "src/test/resources/net/sf/jabref/sql/database-export-single-entry.sql", databaseType);
}
}

@Test
public void testExportToFileSingleEntrySingleGroup() throws Exception {
BibDatabaseContext databaseContext = createContextWithSingleEntrySingleGroup();
for (DatabaseType databaseType : DatabaseType.values()) {
DatabaseExporter exporter = new DBExporterAndImporterFactory().getExporter(databaseType);

Path tempFile = Files.createTempFile("jabref", "database-export" + databaseType.getFormattedName());
exporter.exportDatabaseAsFile(databaseContext,
databaseContext.getDatabase().getEntries(),
tempFile.toAbsolutePath().toString(),
StandardCharsets.UTF_8);

Path expectSqlFile = Paths.get("src/test/resources/net/sf/jabref/sql/database-export-single-entry-single-group.sql");
assertEquals(
String.join("\n", Files.readAllLines(expectSqlFile, StandardCharsets.UTF_8)),
String.join("\n", Files.readAllLines(tempFile, StandardCharsets.UTF_8))
);
testExportToFile(databaseContext, "src/test/resources/net/sf/jabref/sql/database-export-single-entry-single-group.sql", databaseType);
}
}

private void testExportToFile(BibDatabaseContext databaseContext, String path, DatabaseType databaseType) throws Exception {
DatabaseExporter exporter = new DBExporterAndImporterFactory().getExporter(databaseType);

Path tempFile = Files.createTempFile("jabref", "database-export" + databaseType.getFormattedName());
exporter.exportDatabaseAsFile(databaseContext,
databaseContext.getDatabase().getEntries(),
tempFile.toAbsolutePath().toString(),
StandardCharsets.UTF_8);

Path expectSqlFile = Paths.get(path);
assertEquals(
String.join("\n", Files.readAllLines(expectSqlFile, StandardCharsets.UTF_8)),
String.join("\n", Files.readAllLines(tempFile, StandardCharsets.UTF_8))
);
}

private BibDatabaseContext createContextWithSingleEntry() {
BibEntry entry = new BibEntry("id1");
entry.setCiteKey("einstein");
Expand Down

0 comments on commit 034e550

Please sign in to comment.