-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for :di-kodein-advanced, including one with overridden depen…
…dency.
- Loading branch information
1 parent
0e2a507
commit 89ea9b6
Showing
2 changed files
with
118 additions
and
22 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
93 changes: 93 additions & 0 deletions
93
other/di-kodein-advanced/test/KodeinAdvancedApplicationTest.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,93 @@ | ||
package io.ktor.samples.kodein | ||
|
||
import io.ktor.http.HttpMethod | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.testing.withTestApplication | ||
import org.kodein.di.generic.bind | ||
import org.kodein.di.generic.singleton | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
/** | ||
* Integration tests for the [advancedApplication] module from KodeinAdvancedApplication. | ||
*/ | ||
class KodeinAdvancedApplicationTest { | ||
|
||
@Test | ||
fun `get user`() = withTestApplication<Unit>( | ||
{ | ||
kodeinApplication { advancedApplication(it) } | ||
} | ||
) { | ||
handleRequest { method = HttpMethod.Get; uri = "/users/fake" }.apply { | ||
assertEquals(HttpStatusCode.OK, response.status()) | ||
assertEquals( | ||
""" | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<h1>fake</h1> | ||
</body> | ||
</html> | ||
""".trimIndent() + "\n", | ||
response.content | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun `get default users`() = withTestApplication<Unit>( | ||
{ | ||
kodeinApplication { advancedApplication(it) } | ||
} | ||
) { | ||
handleRequest { method = HttpMethod.Get; uri = "/users/" }.apply { | ||
assertEquals(HttpStatusCode.OK, response.status()) | ||
assertEquals( | ||
""" | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<ul> | ||
<li><a href="/users/test">test</a></li> | ||
<li><a href="/users/demo">demo</a></li> | ||
</ul> | ||
</body> | ||
</html> | ||
""".trimIndent() + "\n", | ||
response.content | ||
) | ||
} | ||
} | ||
|
||
// Note: a JVM bug prevents us from using `nice test names` when there's a local class defined in it. | ||
@Test | ||
fun testGetFakeUsers() = withTestApplication<Unit>( | ||
{ | ||
class FakeRepository : Users.IRepository { | ||
override fun list() = listOf(Users.User("fake")) | ||
} | ||
kodeinApplication { | ||
advancedApplication(it) | ||
bind<Users.IRepository>(overrides = true) with singleton { FakeRepository() } | ||
} | ||
} | ||
) { | ||
handleRequest { method = HttpMethod.Get; uri = "/users/" }.apply { | ||
assertEquals(HttpStatusCode.OK, response.status()) | ||
assertEquals( | ||
""" | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<ul> | ||
<li><a href="/users/fake">fake</a></li> | ||
</ul> | ||
</body> | ||
</html> | ||
""".trimIndent() + "\n", | ||
response.content | ||
) | ||
} | ||
} | ||
} |