-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: enable cache when get events * test: check cache exist * docs: update open-api.yaml --------- Co-authored-by: Git Actions <no-reply@github.com>
- Loading branch information
1 parent
38304fe
commit 293ca91
Showing
7 changed files
with
68 additions
and
5 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
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
33 changes: 33 additions & 0 deletions
33
src/integrationTest/kotlin/com/group4/ticketingservice/Event/EventControllerTest.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,33 @@ | ||
package com.group4.ticketingservice.Event | ||
|
||
import com.group4.ticketingservice.AbstractIntegrationTest | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.cache.CacheManager | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders | ||
|
||
@AutoConfigureMockMvc | ||
class EventControllerTest : AbstractIntegrationTest() { | ||
@Autowired | ||
private lateinit var mockMvc: MockMvc | ||
|
||
@Autowired | ||
private lateinit var cacheManager: CacheManager | ||
|
||
@Test | ||
fun `getEvents caches the result`() { | ||
mockMvc.perform( | ||
MockMvcRequestBuilders.get("/events") | ||
.param("page", "0") | ||
.param("size", "10") | ||
|
||
) | ||
|
||
val cache = cacheManager.getCache("getEvents") | ||
val cachedValue = cache!!.get(0) | ||
|
||
assert(cachedValue != null) | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/group4/ticketingservice/config/CacheConfig.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,23 @@ | ||
package com.group4.ticketingservice.config | ||
|
||
import org.springframework.cache.CacheManager | ||
import org.springframework.cache.annotation.EnableCaching | ||
import org.springframework.cache.concurrent.ConcurrentMapCache | ||
import org.springframework.cache.support.SimpleCacheManager | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
@EnableCaching | ||
class CacheConfig { | ||
@Bean | ||
fun cacheManager(): CacheManager { | ||
val simpleCacheManager = SimpleCacheManager() | ||
simpleCacheManager.setCaches( | ||
listOf( | ||
ConcurrentMapCache("getEvents") | ||
) | ||
) | ||
return simpleCacheManager | ||
} | ||
} |
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