From 3da164024d9124c9fa297bf3e9c6adcfc9ec553c Mon Sep 17 00:00:00 2001 From: ahmed-ali-55 Date: Mon, 28 Aug 2023 10:22:12 +0200 Subject: [PATCH] moving interfaces to the domain package --- .../gitlab/broker/connector/runner/InitialStateRunner.kt | 2 +- .../webhook/adapter/feign/GitlabWebhookProvider.kt | 9 +++------ .../webhook/application/GitlabWebhookServiceImpl.kt | 4 ++-- .../vsm/gitlab/broker/webhook/domain/WebhookProvider.kt | 8 ++++++-- .../vsm/gitlab/broker/webhook/domain/WebhookService.kt | 5 +++-- .../webhook/application/GitlabWebhookServiceImplTest.kt | 5 +++-- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/net/leanix/vsm/gitlab/broker/connector/runner/InitialStateRunner.kt b/src/main/kotlin/net/leanix/vsm/gitlab/broker/connector/runner/InitialStateRunner.kt index 1b77d15..6543dde 100644 --- a/src/main/kotlin/net/leanix/vsm/gitlab/broker/connector/runner/InitialStateRunner.kt +++ b/src/main/kotlin/net/leanix/vsm/gitlab/broker/connector/runner/InitialStateRunner.kt @@ -2,7 +2,7 @@ package net.leanix.vsm.gitlab.broker.connector.runner import net.leanix.vsm.gitlab.broker.connector.application.AssignmentService import net.leanix.vsm.gitlab.broker.shared.cache.AssignmentsCache -import net.leanix.vsm.gitlab.broker.webhook.application.WebhookService +import net.leanix.vsm.gitlab.broker.webhook.domain.WebhookService import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.boot.ApplicationArguments diff --git a/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/adapter/feign/GitlabWebhookProvider.kt b/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/adapter/feign/GitlabWebhookProvider.kt index a8d1834..17ef21c 100644 --- a/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/adapter/feign/GitlabWebhookProvider.kt +++ b/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/adapter/feign/GitlabWebhookProvider.kt @@ -2,15 +2,12 @@ package net.leanix.vsm.gitlab.broker.webhook.adapter.feign import net.leanix.vsm.gitlab.broker.connector.application.AssignmentService import net.leanix.vsm.gitlab.broker.webhook.domain.GitlabWebhook +import net.leanix.vsm.gitlab.broker.webhook.domain.WebhookProvider import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Component -interface WebhookProvider { - fun getAllWebhooks(): List - fun deleteWebhook(webhookId: Int) - fun createWebhook(): GitlabWebhook -} +const val LEANIX_WEBHOOK_PATH = "/leanix-vsm/webhook" @Component class GitlabWebhookProvider( @@ -45,7 +42,7 @@ class GitlabWebhookProvider( override fun createWebhook(): GitlabWebhook { return kotlin.runCatching { webhookClient.createWebhook( - url = "$gitlabWebhookUrl/webhook", + url = "$gitlabWebhookUrl$LEANIX_WEBHOOK_PATH", token = leanixId, receivePushEvents = true, receiveTagPushEvents = false, diff --git a/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/application/GitlabWebhookServiceImpl.kt b/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/application/GitlabWebhookServiceImpl.kt index c618b36..fc85845 100644 --- a/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/application/GitlabWebhookServiceImpl.kt +++ b/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/application/GitlabWebhookServiceImpl.kt @@ -1,6 +1,6 @@ package net.leanix.vsm.gitlab.broker.webhook.application -import net.leanix.vsm.gitlab.broker.webhook.adapter.feign.leanixWebhookPath +import net.leanix.vsm.gitlab.broker.webhook.adapter.feign.LEANIX_WEBHOOK_PATH import net.leanix.vsm.gitlab.broker.webhook.domain.GitlabWebhook import net.leanix.vsm.gitlab.broker.webhook.domain.WebhookProvider import net.leanix.vsm.gitlab.broker.webhook.domain.WebhookService @@ -15,7 +15,7 @@ class GitlabWebhookServiceImpl( val webhook = webhookProvider.createWebhook() webhookProvider.getAllWebhooks() - .filter { it.url.contains(leanixWebhookPath) && it.id != webhook.id } + .filter { it.url.contains(LEANIX_WEBHOOK_PATH) && it.id != webhook.id } .forEach { webhookProvider.deleteWebhook(it.id) } return webhook diff --git a/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/domain/WebhookProvider.kt b/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/domain/WebhookProvider.kt index a82cbee..ce7b7b5 100644 --- a/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/domain/WebhookProvider.kt +++ b/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/domain/WebhookProvider.kt @@ -1,4 +1,8 @@ package net.leanix.vsm.gitlab.broker.webhook.domain -class WebhookProvider { -} \ No newline at end of file +interface WebhookProvider { + + fun getAllWebhooks(): List + fun deleteWebhook(webhookId: Int) + fun createWebhook(): GitlabWebhook +} diff --git a/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/domain/WebhookService.kt b/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/domain/WebhookService.kt index 0b0edd4..8176b9d 100644 --- a/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/domain/WebhookService.kt +++ b/src/main/kotlin/net/leanix/vsm/gitlab/broker/webhook/domain/WebhookService.kt @@ -1,4 +1,5 @@ package net.leanix.vsm.gitlab.broker.webhook.domain -class WebhookService { -} \ No newline at end of file +interface WebhookService { + fun registerWebhook(): GitlabWebhook +} diff --git a/src/test/kotlin/net/leanix/vsm/gitlab/broker/webhook/application/GitlabWebhookServiceImplTest.kt b/src/test/kotlin/net/leanix/vsm/gitlab/broker/webhook/application/GitlabWebhookServiceImplTest.kt index 155fb2d..1ae780a 100644 --- a/src/test/kotlin/net/leanix/vsm/gitlab/broker/webhook/application/GitlabWebhookServiceImplTest.kt +++ b/src/test/kotlin/net/leanix/vsm/gitlab/broker/webhook/application/GitlabWebhookServiceImplTest.kt @@ -1,7 +1,8 @@ package net.leanix.vsm.gitlab.broker.webhook.application -import net.leanix.vsm.gitlab.broker.webhook.adapter.feign.WebhookProvider +import net.leanix.vsm.gitlab.broker.webhook.adapter.feign.LEANIX_WEBHOOK_PATH import net.leanix.vsm.gitlab.broker.webhook.domain.GitlabWebhook +import net.leanix.vsm.gitlab.broker.webhook.domain.WebhookProvider import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.eq import org.mockito.Mockito.mock @@ -34,7 +35,7 @@ class GitlabWebhookServiceImplTest { fun dummyGitlabWebhookDto(id: Int) = GitlabWebhook( id = id, - url = "https://gitlab.example.com/hook", + url = "https://gitlab.example.com$LEANIX_WEBHOOK_PATH", createdAt = Date(), pushEvents = true, tagPushEvents = false,