mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-23 10:35:18 +01:00
refactor(test): Refactor DatabaseTest
This commit is contained in:
parent
2e891f736e
commit
2add5b642f
@ -17,27 +17,12 @@ import java.util.Map;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
public class DatabaseTest {
|
public class DatabaseTest {
|
||||||
|
|
||||||
//Create database tests for DataManager
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Disable tips and logo for Jooq
|
|
||||||
System.setProperty("org.jooq.no-tips", "true");
|
System.setProperty("org.jooq.no-tips", "true");
|
||||||
System.setProperty("org.jooq.no-logo", "true");
|
System.setProperty("org.jooq.no-logo", "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean deleteDirectory(File directoryToBeDeleted) {
|
|
||||||
File[] allContents = directoryToBeDeleted.listFiles();
|
|
||||||
if (allContents != null) {
|
|
||||||
for (File file : allContents) {
|
|
||||||
deleteDirectory(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return directoryToBeDeleted.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testId() {
|
public void testId() {
|
||||||
File dbDir = new File("./db_test");
|
File dbDir = new File("./db_test");
|
||||||
@ -116,7 +101,6 @@ public class DatabaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dataManager.shutdownNow();
|
dataManager.shutdownNow();
|
||||||
|
|
||||||
if (dbDir.exists()) {
|
if (dbDir.exists()) {
|
||||||
@ -128,7 +112,7 @@ public class DatabaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public static void testConvert() {
|
public void testConvert() {
|
||||||
File dbDir = new File("./db_test");
|
File dbDir = new File("./db_test");
|
||||||
File logsDir = new File("./logs");
|
File logsDir = new File("./logs");
|
||||||
|
|
||||||
@ -263,30 +247,17 @@ public class DatabaseTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getTableColumns(Connection sqliteConnection, String tableName) {
|
private static boolean deleteDirectory(File directoryToBeDeleted) {
|
||||||
StringBuilder columns = new StringBuilder();
|
File[] allContents = directoryToBeDeleted.listFiles();
|
||||||
try {
|
if (allContents != null) {
|
||||||
DatabaseMetaData meta = sqliteConnection.getMetaData();
|
for (File file : allContents) {
|
||||||
ResultSet rs = meta.getColumns(null, null, tableName, null);
|
deleteDirectory(file);
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
String columnName = rs.getString("COLUMN_NAME");
|
|
||||||
String columnType = rs.getString("TYPE_NAME");
|
|
||||||
|
|
||||||
columns.append(columnName).append(" ").append(columnType).append(", ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
return directoryToBeDeleted.delete();
|
||||||
columns.setLength(columns.length() - 2);
|
|
||||||
return columns.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DataTestId implements Data {
|
private static class DataTestId implements Data {
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private String name;
|
private String name;
|
||||||
private int points;
|
private int points;
|
||||||
@ -337,12 +308,14 @@ public class DatabaseTest {
|
|||||||
if (!(obj instanceof DataTestId)) return false;
|
if (!(obj instanceof DataTestId)) return false;
|
||||||
|
|
||||||
DataTestId other = (DataTestId) obj;
|
DataTestId other = (DataTestId) obj;
|
||||||
return id == other.id && name.equals(other.name) && points == other.points && otherPoints == other.otherPoints;
|
return this.id == other.id &&
|
||||||
|
this.name.equals(other.name) &&
|
||||||
|
this.points == other.points &&
|
||||||
|
this.otherPoints == other.otherPoints;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DataTestUUID implements Data {
|
private static class DataTestUUID implements Data {
|
||||||
|
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
private String name;
|
private String name;
|
||||||
private int points;
|
private int points;
|
||||||
@ -393,16 +366,19 @@ public class DatabaseTest {
|
|||||||
if (!(obj instanceof DataTestUUID)) return false;
|
if (!(obj instanceof DataTestUUID)) return false;
|
||||||
|
|
||||||
DataTestUUID other = (DataTestUUID) obj;
|
DataTestUUID other = (DataTestUUID) obj;
|
||||||
return uuid.equals(other.uuid) && name.equals(other.name) && points == other.points && otherPoints == other.otherPoints;
|
return this.uuid.equals(other.uuid) &&
|
||||||
|
this.name.equals(other.name) &&
|
||||||
|
this.points == other.points &&
|
||||||
|
this.otherPoints == other.otherPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "DataTestUUID{" +
|
return "DataTestUUID{" +
|
||||||
"uuid=" + uuid +
|
"uuid=" + this.uuid +
|
||||||
", name='" + name + '\'' +
|
", name='" + this.name + '\'' +
|
||||||
", points=" + points +
|
", points=" + this.points +
|
||||||
", otherPoints=" + otherPoints +
|
", otherPoints=" + this.otherPoints +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user