-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into db2-newer-image
- Loading branch information
Showing
7 changed files
with
145 additions
and
1 deletion.
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
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 @@ | ||
plugins { | ||
id("org.springframework.boot") version "2.1.5.RELEASE" | ||
id("org.jetbrains.kotlin.jvm") version "1.3.31" | ||
id("org.jetbrains.kotlin.plugin.spring") version "1.3.31" | ||
} | ||
|
||
apply plugin: 'io.spring.dependency-management' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("org.springframework.boot:spring-boot-starter") | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") | ||
implementation("org.springframework.boot:spring-boot-starter-data-redis") | ||
implementation("org.springframework.boot:spring-boot-starter-web") | ||
|
||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
testImplementation("org.testcontainers:testcontainers") | ||
} | ||
|
||
compileKotlin { | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
freeCompilerArgs = ["-Xjsr305=strict"] | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
examples/spring-boot-kotlin-redis/src/main/kotlin/com/example/redis/ExampleController.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,27 @@ | ||
package com.example.redis | ||
|
||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.data.redis.core.RedisTemplate | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
class ExampleController { | ||
|
||
private val key = "testcontainers" | ||
|
||
@Autowired | ||
private lateinit var redisTemplate: RedisTemplate<String, String> | ||
|
||
@PostMapping("/set-foo") | ||
fun setFoo(@RequestBody value: String) { | ||
redisTemplate.opsForValue().set(key, value) | ||
} | ||
|
||
@GetMapping("/get-foo") | ||
fun getFoo(): String? { | ||
return redisTemplate.opsForValue().get(key) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/spring-boot-kotlin-redis/src/main/kotlin/com/example/redis/RedisApplication.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,11 @@ | ||
package com.example.redis | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.runApplication | ||
|
||
@SpringBootApplication | ||
class RedisApplication | ||
|
||
fun main(args: Array<String>) { | ||
runApplication<RedisApplication>(*args) | ||
} |
37 changes: 37 additions & 0 deletions
37
...les/spring-boot-kotlin-redis/src/test/kotlin/com/example/redis/AbstractIntegrationTest.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,37 @@ | ||
package com.example.redis | ||
|
||
import org.junit.runner.RunWith | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.util.TestPropertyValues | ||
import org.springframework.context.ApplicationContextInitializer | ||
import org.springframework.context.ConfigurableApplicationContext | ||
import org.springframework.test.context.ContextConfiguration | ||
import org.springframework.test.context.junit4.SpringRunner | ||
import org.testcontainers.containers.GenericContainer | ||
|
||
@RunWith(SpringRunner::class) | ||
@SpringBootTest | ||
@ContextConfiguration(initializers = [AbstractIntegrationTest.Initializer::class]) | ||
@AutoConfigureMockMvc | ||
abstract class AbstractIntegrationTest { | ||
|
||
companion object { | ||
val redisContainer = object : GenericContainer<Nothing>("redis:3-alpine") { | ||
init { | ||
withExposedPorts(6379) | ||
} | ||
} | ||
} | ||
|
||
internal class Initializer : ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
override fun initialize(configurableApplicationContext: ConfigurableApplicationContext) { | ||
redisContainer.start() | ||
|
||
TestPropertyValues.of( | ||
"spring.redis.host=${redisContainer.containerIpAddress}", | ||
"spring.redis.port=${redisContainer.firstMappedPort}" | ||
).applyTo(configurableApplicationContext.environment) | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/spring-boot-kotlin-redis/src/test/kotlin/com/example/redis/RedisApplicationTests.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,11 @@ | ||
package com.example.redis | ||
|
||
import org.junit.Test | ||
|
||
class RedisApplicationTests : AbstractIntegrationTest() { | ||
|
||
@Test | ||
fun contextLoads() { | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
examples/spring-boot-kotlin-redis/src/test/kotlin/com/example/redis/RedisTest.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,29 @@ | ||
package com.example.redis | ||
|
||
import org.hamcrest.CoreMatchers.containsString | ||
import org.junit.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders | ||
|
||
|
||
class RedisTest : AbstractIntegrationTest() { | ||
|
||
@Autowired | ||
private lateinit var mockMvc: MockMvc | ||
|
||
@Test | ||
fun testRedisFunctionality() { | ||
val greeting = "Hello Testcontainers with Kotlin" | ||
mockMvc.perform(post("/set-foo").content(greeting)) | ||
.andExpect(status().isOk) | ||
|
||
mockMvc.perform(get("/get-foo")) | ||
.andExpect(status().isOk) | ||
.andExpect(content().string(containsString(greeting))) | ||
} | ||
} |