-
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.
- Loading branch information
Showing
6 changed files
with
92 additions
and
0 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
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/yourssu/soongpt/common/config/SlackProperties.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,8 @@ | ||
package com.yourssu.soongpt.common.config | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
|
||
@ConfigurationProperties(prefix = "slack") | ||
class SlackProperties( | ||
val channelId: String, | ||
) |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/yourssu/soongpt/common/infrastructure/SlackAlarmFeignClient.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,16 @@ | ||
package com.yourssu.soongpt.common.infrastructure | ||
|
||
import com.yourssu.soongpt.common.infrastructure.dto.SlackAlarmRequest | ||
import org.springframework.cloud.openfeign.FeignClient | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
|
||
@Component | ||
@FeignClient( | ||
name = "slackAlarmClient", | ||
) | ||
interface SlackAlarmFeignClient { | ||
@PostMapping | ||
fun sendAlarm(@RequestBody request: SlackAlarmRequest) | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/yourssu/soongpt/common/infrastructure/SlackAlarmProducer.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,21 @@ | ||
package com.yourssu.soongpt.common.infrastructure | ||
|
||
import com.yourssu.soongpt.common.config.SlackProperties | ||
import com.yourssu.soongpt.common.infrastructure.dto.SlackAlarmRequest | ||
import org.springframework.scheduling.annotation.Async | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class SlackAlarmProducer( | ||
private val slackAlarmFeignClient: SlackAlarmFeignClient, | ||
private val slackProperties: SlackProperties, | ||
) { | ||
@Async | ||
fun sendAlarm(message: String) { | ||
try { | ||
slackAlarmFeignClient.sendAlarm(SlackAlarmRequest(channel = slackProperties.channelId, text = message)) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/yourssu/soongpt/common/infrastructure/dto/SlackAlarmRequest.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,6 @@ | ||
package com.yourssu.soongpt.common.infrastructure.dto | ||
|
||
data class SlackAlarmRequest( | ||
val channel: String, | ||
val text: String, | ||
) |
37 changes: 37 additions & 0 deletions
37
src/test/kotlin/com/yourssu/soongpt/common/infrastructure/SlackAlarmProducerTest.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.yourssu.soongpt.common.infrastructure | ||
|
||
import com.yourssu.soongpt.common.support.config.ApplicationTest | ||
import org.junit.jupiter.api.* | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.times | ||
import org.mockito.kotlin.verify | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.test.context.bean.override.mockito.MockitoBean | ||
|
||
@ApplicationTest | ||
class SlackAlarmProducerTest { | ||
@Autowired | ||
private lateinit var slackAlarmProducer: SlackAlarmProducer | ||
|
||
@MockitoBean | ||
private lateinit var slackAlarmFeignClient: SlackAlarmFeignClient | ||
|
||
@Nested | ||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores::class) | ||
inner class sendAlarm_메서드는 { | ||
private val message = "메세지 형식 테스트" | ||
|
||
@Nested | ||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores::class) | ||
inner class 메세지가_주어지면 { | ||
@Test | ||
@DisplayName("yaml 파일에 설정된 채널로 슬랙 메세지를 비동기 방식으로 보낸다.") | ||
fun success() { | ||
slackAlarmProducer.sendAlarm(message) | ||
|
||
verify(slackAlarmFeignClient, times(1)) | ||
.sendAlarm(any()) | ||
} | ||
} | ||
} | ||
} |