CORDA-825 Test jdbc session and entity manager in corda service constructors (#5088)

This commit is contained in:
Dan Newton 2019-05-02 16:34:44 +01:00 committed by Shams Asari
parent 2365276597
commit 268f6db430

View File

@ -90,6 +90,16 @@ class CordaServiceTest {
nodeA.services.cordaService(VaultQueryService::class.java)
}
@Test
fun `Can query using jdbc session in constructor`() {
nodeA.services.cordaService(JdbcSessionQueryService::class.java)
}
@Test
fun `Can use entity manager in constructor`() {
nodeA.services.cordaService(EntityManagerService::class.java)
}
@StartableByService
class DummyServiceFlow : FlowLogic<InvocationContext>() {
companion object {
@ -160,4 +170,20 @@ class CordaServiceTest {
assertNotNull(Thread.currentThread().contextClassLoader, "thread context classloader should not be null during service initialisation")
}
}
@CordaService
class JdbcSessionQueryService(val serviceHub: AppServiceHub): SingletonSerializeAsToken() {
init {
serviceHub.jdbcSession().prepareStatement("SELECT * FROM VAULT_STATES").execute()
}
}
@CordaService
class EntityManagerService(val serviceHub: AppServiceHub): SingletonSerializeAsToken() {
init {
serviceHub.withEntityManager {
createNativeQuery("SELECT * FROM VAULT_STATES").resultList
}
}
}
}