Skip to content

Commit

Permalink
fix: syntax fixes for mr
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasBousselin committed Jun 19, 2024
1 parent d51f967 commit ee0f45b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class NotificationService(
Triple(
subscription,
notification,
mqttNotificationService.mqttNotifier(
mqttNotificationService.notify(
notification = notification,
subscription = subscription,
headers = headerMap
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.egm.stellio.subscription.service.mqtt

import com.egm.stellio.shared.model.BadSchemeException
import com.egm.stellio.shared.util.JsonUtils.serializeObject
import com.egm.stellio.subscription.model.Notification
import com.egm.stellio.subscription.model.Subscription
Expand All @@ -25,7 +24,7 @@ class MqttNotificationService(

private val logger = LoggerFactory.getLogger(javaClass)

suspend fun mqttNotifier(
suspend fun notify(
subscription: Subscription,
notification: Notification,
headers: Map<String, String>
Expand All @@ -36,12 +35,11 @@ class MqttNotificationService(
val username = userInfo.getOrNull(0) ?: ""
val password = userInfo.getOrNull(1)
val brokerScheme = Mqtt.SCHEME.brokerSchemeMap[uri.scheme]
?: throw BadSchemeException("${uri.scheme} is not a valid mqtt scheme")

val brokerPort = if (uri.port != -1) uri.port else Mqtt.SCHEME.defaultPortMap[uri.scheme]

val brokerUrl = "$brokerScheme://${uri.host}:$brokerPort"
val notifierInfo = endpoint.notifierInfo?.map { it.key to it.value }?.toMap() ?: emptyMap()
val notifierInfo = endpoint.notifierInfo?.associate { it.key to it.value } ?: emptyMap()
val qos =
notifierInfo[Mqtt.QualityOfService.KEY]?.let { Integer.parseInt(it) } ?: Mqtt.QualityOfService.AT_MOST_ONCE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,11 @@ class NotificationServiceTests {
coEvery { subscriptionService.getContextsLink(any()) } returns buildContextLinkHeader(NGSILD_TEST_CORE_CONTEXT)
coEvery { subscriptionService.updateSubscriptionNotification(any(), any(), any()) } returns 1

coEvery { mqttNotificationService.mqttNotifier(any(), any(), any()) } returns true
coEvery { mqttNotificationService.notify(any(), any(), any()) } returns true

notificationService.callSubscriber(subscription, rawEntity.deserializeAsMap())

coVerify(exactly = 1) { mqttNotificationService.mqttNotifier(any(), any(), any()) }
coVerify(exactly = 1) { mqttNotificationService.notify(any(), any(), any()) }
}

@Test
Expand All @@ -601,15 +601,15 @@ class NotificationServiceTests {
)
)

coEvery { mqttNotificationService.mqttNotifier(any(), any(), any()) } returns true
coEvery { mqttNotificationService.notify(any(), any(), any()) } returns true

coEvery { subscriptionService.getContextsLink(any()) } returns buildContextLinkHeader(NGSILD_TEST_CORE_CONTEXT)
coEvery { subscriptionService.updateSubscriptionNotification(any(), any(), any()) } returns 1

notificationService.callSubscriber(subscription, rawEntity.deserializeAsMap())

coVerify {
mqttNotificationService.mqttNotifier(
mqttNotificationService.notify(
any(),
any(),
match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.mockk.coVerify
import kotlinx.coroutines.test.runTest
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
import org.eclipse.paho.client.mqttv3.MqttException
import org.junit.jupiter.api.Assertions.assertTrue
import org.eclipse.paho.mqttv5.client.IMqttToken
import org.eclipse.paho.mqttv5.client.MqttDisconnectResponse
import org.eclipse.paho.mqttv5.common.MqttSubscription
Expand Down Expand Up @@ -106,13 +107,13 @@ class MqttNotificationServiceTest : WithMosquittoContainer {
)

@Test
fun `mqttNotifier should process endpoint uri to get connection information`() = runTest {
fun `notify should process endpoint uri to get connection information`() = runTest {
val subscription = mqttSubscriptionV3
coEvery { mqttNotificationService.callMqttV3(any()) } returns Unit
assert(
mqttNotificationService.mqttNotifier(
subscription,
getNotificationForSubscription(subscription),
assertTrue(
mqttNotificationService.notify(
mqttSubscriptionV3,
getNotificationForSubscription(mqttSubscriptionV3),
mapOf()
)
)
Expand All @@ -130,14 +131,13 @@ class MqttNotificationServiceTest : WithMosquittoContainer {
}

@Test
fun `mqttNotifier should use notifier info to choose the mqtt version`() = runTest {
val subscription = mqttSubscriptionV3
fun `notify should use notifier info to choose the mqtt version`() = runTest {
coEvery { mqttNotificationService.callMqttV3(any()) } returns Unit
coEvery { mqttNotificationService.callMqttV5(any()) } returns Unit

mqttNotificationService.mqttNotifier(
subscription,
getNotificationForSubscription(subscription),
mqttNotificationService.notify(
mqttSubscriptionV3,
getNotificationForSubscription(mqttSubscriptionV3),
mapOf()
)
coVerify(exactly = 1) {
Expand All @@ -151,9 +151,9 @@ class MqttNotificationServiceTest : WithMosquittoContainer {
)
}

mqttNotificationService.mqttNotifier(
mqttNotificationService.notify(
mqttSubscriptionV5,
getNotificationForSubscription(subscription),
getNotificationForSubscription(mqttSubscriptionV5),
mapOf()
)
coVerify(exactly = 1) {
Expand Down

0 comments on commit ee0f45b

Please sign in to comment.