-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds integration test for rate limiter
- Loading branch information
paulbrejla
committed
Dec 1, 2023
1 parent
dd88f47
commit e3a35d1
Showing
3 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/test/kotlin/de/paulbrejla/holidays/rest/impl/HolidayWsV1ImplITest.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,46 @@ | ||
package de.paulbrejla.holidays.rest.impl | ||
|
||
import de.paulbrejla.holidays.application.api.HolidayService | ||
import de.paulbrejla.holidays.rest.api.HolidayWsV1 | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
|
||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest | ||
@ExtendWith( | ||
SpringExtension::class | ||
) | ||
@TestInstance(TestInstance.Lifecycle.PER_METHOD) | ||
class HolidayWsV1ImplITest { | ||
@Autowired | ||
lateinit var mvc: MockMvc | ||
|
||
@Test | ||
fun `api responds with a 429 if rate limit is reached after 10 requests`() { | ||
repeat(11) { rep -> | ||
mvc.perform( | ||
MockMvcRequestBuilders | ||
.get("/api/v1/holidays/HB") | ||
) | ||
.andExpect { | ||
if (rep <= 10) { | ||
status().isOk | ||
} else { | ||
status().isTooManyRequests | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
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