Skip to content

Commit

Permalink
test: Fix failing Oracle exposed-core tests (JetBrains#1831)
Browse files Browse the repository at this point in the history
The following tests fail when run on Oracle:

CreateMissingTablesAndColumnsTests/testCamelCaseForeignKeyCreation()

Fails with:
ORA-02275: such a referential constraint already exists in the table.

Because Oracle metadata (via getImportedKeys()) only returns foreign keys that
reference primary keys of the referenced table.

The test now excludes Oracle.

EntityTests/preloadOptionalReferencesOnASizedIterable()

Fails on the first assertNotNull() because testCache() is unable to find
school1.id = 0, which does not exist. The entity school1 is cached with its correct
id.value = 1, but an incorrect value is passed as an argument unless the entity
is first flushed after creation.
  • Loading branch information
bog-walk authored and saral committed Oct 3, 2023
1 parent 4aa017e commit 3b62a9d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ class CreateMissingTablesAndColumnsTests : DatabaseTestsBase() {
val traceNumber = reference("traceNumber", ordersTable.traceNumber)
}

withDb {
// Oracle metadata only returns foreign keys that reference primary keys
withDb(excludeSettings = listOf(TestDB.ORACLE)) {
SchemaUtils.createMissingTablesAndColumns(ordersTable, receiptsTable)
assertTrue(ordersTable.exists())
assertTrue(receiptsTable.exists())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.statements.api.ExposedBlob
import org.jetbrains.exposed.sql.tests.DatabaseTestsBase
import org.jetbrains.exposed.sql.tests.TestDB
import org.jetbrains.exposed.sql.tests.currentDialectTest
import org.jetbrains.exposed.sql.tests.shared.*
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.transactions.inTopLevelTransaction
import org.jetbrains.exposed.sql.vendors.OracleDialect
import org.junit.Test
import java.sql.Connection
import java.util.*
Expand Down Expand Up @@ -754,10 +756,9 @@ class EntityTests : DatabaseTestsBase() {
var holidays by Holiday via SchoolHolidays
}

@Test fun preloadReferencesOnASizedIterable() {

@Test
fun preloadReferencesOnASizedIterable() {
withTables(Regions, Schools) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -796,10 +797,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadReferencesOnAnEntity() {

@Test
fun preloadReferencesOnAnEntity() {
withTables(Regions, Schools) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -829,9 +829,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadOptionalReferencesOnASizedIterable() {
@Test
fun preloadOptionalReferencesOnASizedIterable() {
withTables(Regions, Schools) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand All @@ -844,6 +844,9 @@ class EntityTests : DatabaseTestsBase() {
name = "Eton"
region = region1
secondaryRegion = region2
}.apply {
// otherwise Oracle provides school1.id = 0 to testCache(), which returns null
if (currentDialectTest is OracleDialect) flush()
}

val school2 = School.new {
Expand All @@ -866,10 +869,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadOptionalReferencesOnAnEntity() {

@Test
fun preloadOptionalReferencesOnAnEntity() {
withTables(Regions, Schools) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -897,10 +899,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadReferrersOnASizedIterable() {

@Test
fun preloadReferrersOnASizedIterable() {
withTables(Regions, Schools, Students) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -959,9 +960,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadReferrersOnAnEntity() {
@Test
fun preloadReferrersOnAnEntity() {
withTables(Regions, Schools, Students) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -999,10 +1000,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadOptionalReferrersOnASizedIterable() {

@Test
fun preloadOptionalReferrersOnASizedIterable() {
withTables(Regions, Schools, Students, Detentions) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -1048,10 +1048,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadInnerTableLinkOnASizedIterable() {

@Test
fun preloadInnerTableLinkOnASizedIterable() {
withTables(Regions, Schools, Holidays, SchoolHolidays) {

val now = System.currentTimeMillis()
val now10 = now + 10

Expand Down Expand Up @@ -1110,9 +1109,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadInnerTableLinkOnAnEntity() {
@Test
fun preloadInnerTableLinkOnAnEntity() {
withTables(Regions, Schools, Holidays, SchoolHolidays) {

val now = System.currentTimeMillis()
val now10 = now + 10

Expand Down Expand Up @@ -1169,10 +1168,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadRelationAtDepth() {

@Test
fun preloadRelationAtDepth() {
withTables(Regions, Schools, Holidays, SchoolHolidays, Students, Notes) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -1213,8 +1211,8 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadBackReferrenceOnASizedIterable() {

@Test
fun preloadBackReferrenceOnASizedIterable() {
withTables(Regions, Schools, Students, StudentBios) {
val region1 = Region.new {
name = "United States"
Expand Down Expand Up @@ -1258,8 +1256,8 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadBackReferrenceOnAnEntity() {

@Test
fun preloadBackReferrenceOnAnEntity() {
withTables(Regions, Schools, Students, StudentBios) {
val region1 = Region.new {
name = "United States"
Expand Down

0 comments on commit 3b62a9d

Please sign in to comment.