Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions storm-kotlin/src/main/kotlin/st/orm/template/ORMTemplate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import st.orm.repository.RepositoryLookup
import st.orm.template.impl.ORMTemplateImpl
import java.sql.Connection
import javax.sql.DataSource
import kotlin.reflect.KClass

/**
* The primary entry point for Storm's ORM functionality in Kotlin, combining SQL template query construction with
Expand Down Expand Up @@ -113,7 +114,7 @@ interface ORMTemplate :
* @throws st.orm.PersistenceException if the template does not support schema validation.
* @since 1.9
*/
fun validateSchema(types: Iterable<Class<out Data>>): List<String>
fun validateSchema(vararg types: KClass<out Data>): List<String>

/**
* Validates all discovered types and throws if any errors are found.
Expand All @@ -136,7 +137,7 @@ interface ORMTemplate :
* @throws st.orm.PersistenceException if validation fails or the template does not support schema validation.
* @since 1.9
*/
fun validateSchemaOrThrow(types: Iterable<Class<out Data>>)
fun validateSchemaOrThrow(vararg types: KClass<out Data>)

companion object {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ class ORMTemplateImpl(private val core: st.orm.core.template.ORMTemplate) :

override fun validateSchema(): List<String> = core.validateSchema()

override fun validateSchema(types: Iterable<Class<out Data>>): List<String> = core.validateSchema(types)
override fun validateSchema(vararg types: KClass<out Data>): List<String> = core.validateSchema(types.map { it.java })

override fun validateSchemaOrThrow() = core.validateSchemaOrThrow()

override fun validateSchemaOrThrow(types: Iterable<Class<out Data>>) = core.validateSchemaOrThrow(types)
override fun validateSchemaOrThrow(vararg types: KClass<out Data>) = core.validateSchemaOrThrow(types.map { it.java })

/**
* Returns the repository for the given entity type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ open class ORMTemplateFactoryTest(

@Test
fun `validateSchema should return list of errors or empty`() {
val errors = orm.validateSchema(listOf(City::class.java))
val errors = orm.validateSchema(City::class)
// City should validate fine against H2
errors shouldHaveSize 0
}
Expand Down
16 changes: 8 additions & 8 deletions storm-kotlin/src/test/kotlin/st/orm/template/ORMTemplateTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,29 @@ open class ORMTemplateTest(

@Test
fun `validateSchema should return empty for valid types`() {
val errors = orm.validateSchema(listOf(City::class.java))
val errors = orm.validateSchema(City::class)
errors shouldHaveSize 0
}

@Test
fun `validateSchema should return errors for invalid types`() {
@st.orm.DbTable("nonexistent_table")
data class NonExistentEntity(@st.orm.PK val id: Int = 0) : Entity<Int>
val errors = orm.validateSchema(listOf(NonExistentEntity::class.java))
@DbTable("nonexistent_table")
data class NonExistentEntity(@PK val id: Int = 0) : Entity<Int>
val errors = orm.validateSchema(NonExistentEntity::class)
errors.size shouldBe 1
}

@Test
fun `validateSchemaOrThrow should not throw for valid types`() {
orm.validateSchemaOrThrow(listOf(City::class.java))
orm.validateSchemaOrThrow(City::class)
}

@Test
fun `validateSchemaOrThrow should throw for invalid types`() {
@st.orm.DbTable("nonexistent_table")
data class NonExistentEntity(@st.orm.PK val id: Int = 0) : Entity<Int>
@DbTable("nonexistent_table")
data class NonExistentEntity(@PK val id: Int = 0) : Entity<Int>
assertThrows<PersistenceException> {
orm.validateSchemaOrThrow(listOf(NonExistentEntity::class.java))
orm.validateSchemaOrThrow(NonExistentEntity::class)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,51 +28,49 @@ open class SchemaValidationTest(

@Test
fun `validateSchema with City should return no errors`() {
val errors = orm.validateSchema(listOf(City::class.java))
val errors = orm.validateSchema(City::class)
errors.shouldBeEmpty()
}

@Test
fun `validateSchema with Owner should return no errors`() {
val errors = orm.validateSchema(listOf(Owner::class.java))
val errors = orm.validateSchema(Owner::class)
errors.shouldBeEmpty()
}

@Test
fun `validateSchema with Pet should return no errors`() {
val errors = orm.validateSchema(listOf(Pet::class.java))
val errors = orm.validateSchema(Pet::class)
errors.shouldBeEmpty()
}

@Test
fun `validateSchema with Vet should return no errors`() {
val errors = orm.validateSchema(listOf(Vet::class.java))
val errors = orm.validateSchema(Vet::class)
errors.shouldBeEmpty()
}

@Test
fun `validateSchema with PetType should return no errors`() {
val errors = orm.validateSchema(listOf(PetType::class.java))
val errors = orm.validateSchema(PetType::class)
errors.shouldBeEmpty()
}

@Test
fun `validateSchema with Visit should return no errors`() {
val errors = orm.validateSchema(listOf(Visit::class.java))
val errors = orm.validateSchema(Visit::class)
errors.shouldBeEmpty()
}

@Test
fun `validateSchema with multiple valid types should return no errors`() {
val errors = orm.validateSchema(
listOf(
City::class.java,
Owner::class.java,
Pet::class.java,
PetType::class.java,
Vet::class.java,
Visit::class.java,
),
City::class,
Owner::class,
Pet::class,
PetType::class,
Vet::class,
Visit::class,
)
errors.shouldBeEmpty()
}
Expand All @@ -88,7 +86,7 @@ open class SchemaValidationTest(

@Test
fun `validateSchema with nonexistent table entity should return errors`() {
val errors = orm.validateSchema(listOf(NonExistentEntity::class.java))
val errors = orm.validateSchema(NonExistentEntity::class)
errors.shouldNotBeEmpty()
}

Expand All @@ -102,7 +100,7 @@ open class SchemaValidationTest(

@Test
fun `validateSchema with mismatched columns should return errors`() {
val errors = orm.validateSchema(listOf(CityMismatch::class.java))
val errors = orm.validateSchema(CityMismatch::class)
errors.shouldNotBeEmpty()
}

Expand All @@ -111,37 +109,24 @@ open class SchemaValidationTest(
@Test
fun `validateSchemaOrThrow with valid types should not throw`() {
// Should complete without exception for valid entity types.
orm.validateSchemaOrThrow(listOf(City::class.java, Vet::class.java))
orm.validateSchemaOrThrow(City::class, Vet::class)
}

@Test
fun `validateSchemaOrThrow with invalid type should throw PersistenceException`() {
assertThrows<PersistenceException> {
orm.validateSchemaOrThrow(listOf(NonExistentEntity::class.java))
orm.validateSchemaOrThrow(NonExistentEntity::class)
}
}

@Test
fun `validateSchemaOrThrow with mixed valid and invalid types should throw`() {
assertThrows<PersistenceException> {
orm.validateSchemaOrThrow(listOf(City::class.java, NonExistentEntity::class.java))
orm.validateSchemaOrThrow(City::class, NonExistentEntity::class)
}
}

// validateSchema with empty list

@Test
fun `validateSchema with empty list should return no errors`() {
val errors = orm.validateSchema(emptyList())
errors.shouldBeEmpty()
}

@Test
fun `validateSchemaOrThrow with empty list should not throw`() {
orm.validateSchemaOrThrow(emptyList())
}

// validateSchema on connection-backed template
// validateSchema with no args (zero varargs)

@Test
fun `validateSchema on connection-backed template should throw PersistenceException`() {
Expand All @@ -168,12 +153,12 @@ open class SchemaValidationTest(

@Test
fun `validateSchema with OwnerView projection should return no errors`() {
val errors = orm.validateSchema(listOf(OwnerView::class.java))
val errors = orm.validateSchema(OwnerView::class)
errors.shouldBeEmpty()
}

@Test
fun `validateSchemaOrThrow with OwnerView projection should not throw`() {
orm.validateSchemaOrThrow(listOf(OwnerView::class.java))
orm.validateSchemaOrThrow(OwnerView::class)
}
}
Loading