Update PushMessageProviderServiceFactory implementation
This commit is contained in:
parent
5f81afcb08
commit
37fb9443ea
|
|
@ -1,23 +1,10 @@
|
|||
package ru.touchin.push.message.provider.factories
|
||||
|
||||
import org.springframework.stereotype.Component
|
||||
import ru.touchin.common.exceptions.CommonException
|
||||
import ru.touchin.push.message.provider.enums.PlatformType
|
||||
import ru.touchin.push.message.provider.properties.PushMessageProviderProperties
|
||||
import ru.touchin.push.message.provider.services.PushMessageProviderService
|
||||
|
||||
@Component
|
||||
class PushMessageProviderServiceFactory(
|
||||
private val pushMessageProviderProperties: PushMessageProviderProperties,
|
||||
private val pushMessageProviderServices: List<PushMessageProviderService>
|
||||
) {
|
||||
interface PushMessageProviderServiceFactory {
|
||||
|
||||
fun get(platformType: PlatformType): PushMessageProviderService {
|
||||
val supportedProviderTypes = pushMessageProviderProperties.platformProviders[platformType]?.firstOrNull()
|
||||
?: throw CommonException("No push message provider set for platform '$platformType'")
|
||||
|
||||
return pushMessageProviderServices.find { it.type == supportedProviderTypes }
|
||||
?: throw CommonException("No push message provider found for platform '$platformType'")
|
||||
}
|
||||
fun get(platformType: PlatformType): PushMessageProviderService
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package ru.touchin.push.message.provider.factories
|
||||
|
||||
import org.springframework.stereotype.Component
|
||||
import ru.touchin.common.exceptions.CommonException
|
||||
import ru.touchin.push.message.provider.enums.PlatformType
|
||||
import ru.touchin.push.message.provider.properties.PushMessageProviderProperties
|
||||
import ru.touchin.push.message.provider.services.PushMessageProviderService
|
||||
import kotlin.jvm.Throws
|
||||
|
||||
@Component
|
||||
class PushMessageProviderServiceFactoryImpl(
|
||||
private val pushMessageProviderProperties: PushMessageProviderProperties,
|
||||
private val pushMessageProviderServices: List<PushMessageProviderService>
|
||||
) : PushMessageProviderServiceFactory {
|
||||
|
||||
@Throws(CommonException::class)
|
||||
override fun get(platformType: PlatformType): PushMessageProviderService {
|
||||
val supportedProviderTypes = pushMessageProviderProperties.platformProviders[platformType]?.firstOrNull()
|
||||
?: throw CommonException("Configuration has no setup for platform '$platformType'")
|
||||
|
||||
return pushMessageProviderServices.find { it.type == supportedProviderTypes }
|
||||
?: throw CommonException("Configuration has no push message provider support for platform '$platformType'")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ import ru.touchin.push.message.provider.enums.PushMessageProviderType
|
|||
import ru.touchin.push.message.provider.properties.PushMessageProviderProperties
|
||||
import ru.touchin.push.message.provider.services.PushMessageProviderService
|
||||
|
||||
class PushMessageProviderServiceFactoryTest {
|
||||
class PushMessageProviderServiceFactoryImplTest {
|
||||
|
||||
private val pushMessageProviderServiceFcm = object : PushMessageProviderService {
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ class PushMessageProviderServiceFactoryTest {
|
|||
@Test
|
||||
@DisplayName("При отсутствии поддерживаемых платформ выбрасывается исключение")
|
||||
fun get_platformNotFound() {
|
||||
val pushMessageProviderServiceFactory = PushMessageProviderServiceFactory(
|
||||
val pushMessageProviderServiceFactory = PushMessageProviderServiceFactoryImpl(
|
||||
pushMessageProviderProperties = PushMessageProviderProperties(
|
||||
platformProviders = emptyMap()
|
||||
),
|
||||
|
|
@ -42,7 +42,7 @@ class PushMessageProviderServiceFactoryTest {
|
|||
@Test
|
||||
@DisplayName("При отсутствии назначенного провайдера у поддерживаемой платформы выбрасывается исключение")
|
||||
fun get_providerServiceForPlatformNotFound() {
|
||||
val pushMessageProviderServiceFactory = PushMessageProviderServiceFactory(
|
||||
val pushMessageProviderServiceFactory = PushMessageProviderServiceFactoryImpl(
|
||||
pushMessageProviderProperties = PushMessageProviderProperties(
|
||||
platformProviders = mapOf(
|
||||
PlatformType.IOS to emptyList()
|
||||
|
|
@ -62,7 +62,7 @@ class PushMessageProviderServiceFactoryTest {
|
|||
@Test
|
||||
@DisplayName("Настроенной платформе назначается первый сервис из доступных")
|
||||
fun get_firstSupportedProviderService() {
|
||||
val pushMessageProviderServiceFactory = PushMessageProviderServiceFactory(
|
||||
val pushMessageProviderServiceFactory = PushMessageProviderServiceFactoryImpl(
|
||||
pushMessageProviderProperties = PushMessageProviderProperties(
|
||||
platformProviders = mapOf(PlatformType.IOS to listOf(PushMessageProviderType.FCM))
|
||||
),
|
||||
Loading…
Reference in New Issue