Skip to content

Commit a2d0a78

Browse files
committed
Coverage
1 parent 01aeae0 commit a2d0a78

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

src/main/kotlin/io/github/tobi/laa/spring/boot/embedded/redis/server/RedisServerContextCustomizerFactory.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import org.springframework.test.context.ContextConfigurationAttributes
55
import org.springframework.test.context.ContextCustomizer
66
import org.springframework.test.context.ContextCustomizerFactory
77

8-
class RedisServerContextCustomizerFactory : ContextCustomizerFactory {
8+
internal class RedisServerContextCustomizerFactory : ContextCustomizerFactory {
99

1010
override fun createContextCustomizer(
1111
testClass: Class<*>,
1212
configAttributes: MutableList<ContextConfigurationAttributes>
13-
): ContextCustomizer? {
13+
): ContextCustomizer {
1414
val embeddedRedisServer = findTestClassAnnotation(testClass, EmbeddedRedisServer::class.java)
15-
return embeddedRedisServer?.let { RedisServerContextCustomizer(it) }
15+
return RedisServerContextCustomizer(embeddedRedisServer!!)
1616
}
1717
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package io.github.tobi.laa.spring.boot.embedded.redis.server
2+
3+
import io.github.tobi.laa.spring.boot.embedded.redis.IntegrationTest
4+
import io.github.tobi.laa.spring.boot.embedded.redis.RedisTests
5+
import org.junit.jupiter.api.DisplayName
6+
import org.junit.jupiter.api.Order
7+
import org.junit.jupiter.api.Test
8+
import org.springframework.beans.factory.annotation.Autowired
9+
10+
@IntegrationTest
11+
@EmbeddedRedisServer(
12+
port = 10000,
13+
settings = [
14+
"appendonly no",
15+
"protected-mode yes",
16+
"appendfsync everysec",
17+
"port 12345"]
18+
)
19+
@DisplayName("Using @EmbeddedRedisServer with custom settings")
20+
internal class CustomSettingsTest {
21+
22+
@Autowired
23+
private lateinit var given: RedisTests
24+
25+
@Test
26+
@DisplayName("It should be possible to write to Redis and the data should be available afterwards")
27+
@Order(2)
28+
fun givenRandomTestdata_writingToRedis_dataShouldBeAvailable() {
29+
given.randomTestdata()
30+
.whenRedis().isBeingWrittenTo()
31+
.then().redis().shouldContainTheTestdata()
32+
}
33+
34+
@Test
35+
@DisplayName("Redis should have been flushed after the first test")
36+
@Order(3)
37+
fun redisShouldHaveBeenFlushed() {
38+
given.nothing()
39+
.whenDoingNothing()
40+
.then().redis().shouldNotContainAnyTestdata()
41+
}
42+
43+
@Test
44+
@DisplayName("Settings from @EmbeddedRedisServer should have been applied to the embedded Redis server")
45+
@Order(4)
46+
fun configFileShouldHaveBeenApplied() {
47+
given.nothing()
48+
.whenDoingNothing()
49+
.then().embeddedRedis()
50+
.shouldHaveConfig().thatContainsDirective("appendonly", "no")
51+
.and().thatContainsDirective("protected-mode", "yes")
52+
.and().thatContainsDirective("appendfsync", "everysec")
53+
}
54+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.github.tobi.laa.spring.boot.embedded.redis.server
2+
3+
import io.github.tobi.laa.spring.boot.embedded.redis.IntegrationTest
4+
import io.github.tobi.laa.spring.boot.embedded.redis.RedisTests
5+
import org.junit.jupiter.api.DisplayName
6+
import org.junit.jupiter.api.Test
7+
import org.springframework.beans.factory.annotation.Autowired
8+
9+
@IntegrationTest
10+
@EmbeddedRedisServer(executeInDirectory = "build", port = 10001)
11+
@DisplayName("Using @EmbeddedRedisServer with custom execution dir")
12+
internal class ExecutionDirTest {
13+
14+
@Autowired
15+
private lateinit var given: RedisTests
16+
17+
@Test
18+
@DisplayName("It should be possible to write to Redis and the data should be available afterwards")
19+
fun givenRandomTestdata_writingToRedis_dataShouldBeAvailable() {
20+
given.randomTestdata()
21+
.whenRedis().isBeingWrittenTo()
22+
.then().redis().shouldContainTheTestdata()
23+
}
24+
}

0 commit comments

Comments
 (0)