-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add more data types * Adjust tests * Add minecraft color test * Add missing tests * Organize imports
- Loading branch information
1 parent
0b47ecf
commit 256939e
Showing
13 changed files
with
227 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package tests.minecraft | ||
|
||
import de.mineking.database.* | ||
import de.mineking.database.vendors.postgres.PostgresConnection | ||
import de.mineking.database.vendors.postgres.PostgresMappers | ||
import net.kyori.adventure.text.format.NamedTextColor | ||
import net.kyori.adventure.text.format.TextColor | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import setup.ConsoleSqlLogger | ||
import setup.createServer | ||
import setup.recreate | ||
|
||
data class ColorDao( | ||
@AutoIncrement @Key @Column val id: Int = 0, | ||
@Column val color: TextColor = TextColor.color(0), | ||
@Column val namedColor: NamedTextColor = NamedTextColor.BLACK | ||
) | ||
|
||
class ColorTest { | ||
val connection = PostgresConnection("localhost:5432/test", user = "test", password = "test") | ||
val table: Table<ColorDao> | ||
|
||
init { | ||
connection.registerMinecraftMappers(createServer(), PostgresMappers.STRING, PostgresMappers.UUID_MAPPER, PostgresMappers.ARRAY, PostgresMappers.DOUBLE) | ||
table = connection.getTable(name = "color_test") { ColorDao() } | ||
|
||
table.recreate() | ||
|
||
table.insert(ColorDao(color = TextColor.color(0x00ff00), namedColor = NamedTextColor.GREEN)) | ||
|
||
connection.driver.setSqlLogger(ConsoleSqlLogger) | ||
} | ||
|
||
@Test | ||
fun selectAll() { | ||
val result = table.select().list() | ||
|
||
assertEquals(TextColor.color(0x00ff00), result[0].color) | ||
assertEquals(NamedTextColor.GREEN, result[0].namedColor) | ||
} | ||
|
||
@Test | ||
fun selectColumn() { | ||
assertEquals(TextColor.color(0x00ff00), table.select<TextColor>(property("color"), limit = 1).first()) | ||
assertEquals(NamedTextColor.GREEN, table.select<NamedTextColor>(property("namedColor"), limit = 1).first()) | ||
|
||
assertEquals(1, table.selectRowCount(where = property("color") isEqualTo value(TextColor.color(0x00ff00)))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
postgres/src/main/kotlin/de/mineking/database/vendors/postgres/Conditions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package tests.postgres.specific | ||
|
||
import de.mineking.database.* | ||
import de.mineking.database.vendors.postgres.PostgresConnection | ||
import org.junit.jupiter.api.Test | ||
import setup.ConsoleSqlLogger | ||
import setup.recreate | ||
import java.awt.Color | ||
import kotlin.test.assertEquals | ||
|
||
data class ColorDao( | ||
@AutoIncrement @Key @Column val id: Int = 0, | ||
@Column val color: Color = Color.WHITE | ||
) | ||
|
||
class ColorTest { | ||
val connection = PostgresConnection("localhost:5432/test", user = "test", password = "test") | ||
val table = connection.getTable(name = "color_test") { ColorDao() } | ||
|
||
init { | ||
table.recreate() | ||
|
||
table.insert(ColorDao(color = Color.GREEN)) | ||
|
||
connection.driver.setSqlLogger(ConsoleSqlLogger) | ||
} | ||
|
||
@Test | ||
fun selectAll() { | ||
assertEquals(Color.GREEN, table.select<Color>(property("color")).first()) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
postgres/src/test/kotlin/tests/postgres/specific/Locale.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package tests.postgres.specific | ||
|
||
import de.mineking.database.* | ||
import de.mineking.database.vendors.postgres.PostgresConnection | ||
import org.junit.jupiter.api.Test | ||
import setup.ConsoleSqlLogger | ||
import setup.recreate | ||
import java.util.* | ||
import kotlin.test.assertEquals | ||
|
||
data class LocaleDao( | ||
@AutoIncrement @Key @Column val id: Int = 0, | ||
@Column val locale: Locale = Locale.ENGLISH, | ||
) | ||
|
||
class LocaleTest { | ||
val connection = PostgresConnection("localhost:5432/test", user = "test", password = "test") | ||
val table = connection.getTable(name = "locale_test") { LocaleDao() } | ||
|
||
init { | ||
table.recreate() | ||
|
||
table.insert(LocaleDao(locale = Locale.GERMAN)) | ||
|
||
connection.driver.setSqlLogger(ConsoleSqlLogger) | ||
} | ||
|
||
@Test | ||
fun selectAll() { | ||
assertEquals(Locale.GERMAN, table.select<Locale>(property("locale")).first()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package tests.sqlite.specific | ||
|
||
import de.mineking.database.* | ||
import de.mineking.database.vendors.sqlite.SQLiteConnection | ||
import org.junit.jupiter.api.Test | ||
import setup.ConsoleSqlLogger | ||
import setup.recreate | ||
import java.awt.Color | ||
import kotlin.test.assertEquals | ||
|
||
data class ColorDao( | ||
@AutoIncrement @Key @Column val id: Int = 0, | ||
@Column val color: Color = Color.WHITE | ||
) | ||
|
||
class ColorTest { | ||
val connection = SQLiteConnection("test.db") | ||
val table = connection.getTable(name = "color_test") { ColorDao() } | ||
|
||
init { | ||
table.recreate() | ||
|
||
table.insert(ColorDao(color = Color.GREEN)) | ||
|
||
connection.driver.setSqlLogger(ConsoleSqlLogger) | ||
} | ||
|
||
@Test | ||
fun selectAll() { | ||
assertEquals(Color.GREEN, table.select<Color>(property("color")).first()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package tests.sqlite.specific | ||
|
||
import de.mineking.database.* | ||
import de.mineking.database.vendors.sqlite.SQLiteConnection | ||
import org.junit.jupiter.api.Test | ||
import setup.ConsoleSqlLogger | ||
import setup.recreate | ||
import java.util.* | ||
import kotlin.test.assertEquals | ||
|
||
data class LocaleDao( | ||
@AutoIncrement @Key @Column val id: Int = 0, | ||
@Column val locale: Locale = Locale.ENGLISH, | ||
) | ||
|
||
class LocaleTest { | ||
val connection = SQLiteConnection("test.db") | ||
val table = connection.getTable(name = "locale_test") { LocaleDao() } | ||
|
||
init { | ||
table.recreate() | ||
|
||
table.insert(LocaleDao(locale = Locale.GERMAN)) | ||
|
||
connection.driver.setSqlLogger(ConsoleSqlLogger) | ||
} | ||
|
||
@Test | ||
fun selectAll() { | ||
assertEquals(Locale.GERMAN, table.select<Locale>(property("locale")).first()) | ||
} | ||
} |