-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to EntityMetadataDTO hook resolution
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
...re/src/test/java/com/antelopesystem/crudframework/crud/model/EntityMetadataDTOHookTest.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,73 @@ | ||
package com.antelopesystem.crudframework.crud.model | ||
|
||
import com.antelopesystem.crudframework.crud.annotation.WithHooks | ||
import com.antelopesystem.crudframework.crud.hooks.interfaces.CRUDHooks | ||
import com.antelopesystem.crudframework.crud.test.AbstractTestEntity | ||
import com.antelopesystem.crudframework.model.BaseCrudEntity | ||
import org.junit.Assert.assertArrayEquals | ||
import org.junit.Test | ||
import java.io.Serializable | ||
|
||
class EntityMetadataDTOHookTest { | ||
private class GenericPersistentHooks<ID : Serializable> : CRUDHooks<ID, BaseCrudEntity<ID>> | ||
private class GenericPersistentHooks2<ID : Serializable> : CRUDHooks<ID, BaseCrudEntity<ID>> | ||
|
||
@WithHooks(hooks = [GenericPersistentHooks::class]) | ||
private annotation class WithGenericPersistentHooks | ||
|
||
@WithHooks(hooks = [GenericPersistentHooks2::class]) | ||
private annotation class WithGenericPersistentHooks2 | ||
|
||
@Test | ||
fun `single nested withHooks annotation should register`() { | ||
@WithGenericPersistentHooks | ||
class TestEntity : AbstractTestEntity() | ||
|
||
val metadata = EntityMetadataDTO(TestEntity::class.java) | ||
|
||
assertArrayEquals(arrayOf(GenericPersistentHooks::class.java), metadata.hookTypesFromAnnotations.toTypedArray()) | ||
} | ||
|
||
@Test | ||
fun `two nested withHooks annotation should register`() { | ||
@WithGenericPersistentHooks | ||
@WithGenericPersistentHooks2 | ||
class TestEntity : AbstractTestEntity() | ||
|
||
val metadata = EntityMetadataDTO(TestEntity::class.java) | ||
|
||
assertArrayEquals(arrayOf(GenericPersistentHooks::class.java, GenericPersistentHooks2::class.java), metadata.hookTypesFromAnnotations.toTypedArray()) | ||
} | ||
|
||
@Test | ||
fun `two nested withHooks annotation should register with one on parent`() { | ||
@WithGenericPersistentHooks2 abstract class AbstractAnnotatedTestEntity : AbstractTestEntity() | ||
@WithGenericPersistentHooks class TestEntity : AbstractAnnotatedTestEntity() | ||
|
||
val metadata = EntityMetadataDTO(TestEntity::class.java) | ||
|
||
assertArrayEquals(arrayOf(GenericPersistentHooks::class.java, GenericPersistentHooks2::class.java), metadata.hookTypesFromAnnotations.toTypedArray()) | ||
} | ||
|
||
@Test | ||
fun `one withHooks annotation with multiple hooks should register`() { | ||
@WithHooks(hooks = [GenericPersistentHooks::class, GenericPersistentHooks2::class]) | ||
class TestEntity : AbstractTestEntity() | ||
|
||
val metadata = EntityMetadataDTO(TestEntity::class.java) | ||
|
||
assertArrayEquals(arrayOf(GenericPersistentHooks::class.java, GenericPersistentHooks2::class.java), metadata.hookTypesFromAnnotations.toTypedArray()) | ||
} | ||
|
||
@Test | ||
fun `nested witHooks annotation with multiple hooks should register`() { | ||
@WithHooks(hooks = [GenericPersistentHooks::class, GenericPersistentHooks2::class]) | ||
abstract class AbstractAnnotatedTestEntity : AbstractTestEntity() | ||
|
||
class TestEntity : AbstractAnnotatedTestEntity() | ||
|
||
val metadata = EntityMetadataDTO(TestEntity::class.java) | ||
|
||
assertArrayEquals(arrayOf(GenericPersistentHooks::class.java, GenericPersistentHooks2::class.java), metadata.hookTypesFromAnnotations.toTypedArray()) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ework-core/src/test/java/com/antelopesystem/crudframework/crud/test/AbstractTestEntity.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,20 @@ | ||
package com.antelopesystem.crudframework.crud.test | ||
|
||
import com.antelopesystem.crudframework.crud.annotation.CrudEntity | ||
import com.antelopesystem.crudframework.crud.test.TestCrudDao | ||
import com.antelopesystem.crudframework.model.BaseCrudEntity | ||
import java.util.* | ||
|
||
@CrudEntity(TestCrudDao::class) | ||
abstract class AbstractTestEntity : BaseCrudEntity<Long>() { | ||
override var id: Long | ||
get() = 0L | ||
set(value) {} | ||
override var creationTime: Date | ||
get() = Date() | ||
set(value) {} | ||
|
||
override fun exists(): Boolean { | ||
return false | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
crud-framework-core/src/test/java/com/antelopesystem/crudframework/crud/test/TestCrudDao.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,28 @@ | ||
package com.antelopesystem.crudframework.crud.test | ||
|
||
import com.antelopesystem.crudframework.crud.handler.CrudDao | ||
import com.antelopesystem.crudframework.model.BaseCrudEntity | ||
import com.antelopesystem.crudframework.modelfilter.DynamicModelFilter | ||
import java.io.Serializable | ||
|
||
class TestCrudDao : CrudDao { | ||
override fun <ID : Serializable?, Entity : BaseCrudEntity<ID>?, E : DynamicModelFilter?> index(filter: E, clazz: Class<Entity>?): MutableList<Entity> { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun <ID : Serializable?, Entity : BaseCrudEntity<ID>?, E : DynamicModelFilter?> indexCount(filter: E, clazz: Class<Entity>?): Long { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun <ID : Serializable?, Entity : BaseCrudEntity<ID>?> softDeleteById(id: ID, deleteColumn: String?, clazz: Class<Entity>?) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun <ID : Serializable?, Entity : BaseCrudEntity<ID>?> hardDeleteById(id: ID, clazz: Class<Entity>?) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun <ID : Serializable?, Entity : BaseCrudEntity<ID>?> saveOrUpdate(entity: Entity): Entity { | ||
TODO("Not yet implemented") | ||
} | ||
} |