diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a508772..e89896f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,11 +18,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: distribution: 'adopt' - java-version: '11' + java-version: '21' - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/.github/workflows/manually-release.yml b/.github/workflows/manually-release.yml index d7dee3d..96c2f26 100644 --- a/.github/workflows/manually-release.yml +++ b/.github/workflows/manually-release.yml @@ -26,11 +26,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: distribution: 'adopt' - java-version: '11' + java-version: '21' - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 519f7fd..9ad35cd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,11 +21,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: distribution: 'adopt' - java-version: '11' + java-version: '21' - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/plugin-slack/build.gradle b/build.gradle similarity index 64% rename from plugin-slack/build.gradle rename to build.gradle index 6b929b4..71aaadd 100644 --- a/plugin-slack/build.gradle +++ b/build.gradle @@ -1,20 +1,16 @@ -import com.github.spotbugs.SpotBugsTask - plugins { - id "io.spring.dependency-management" version "1.0.9.RELEASE" + id "io.spring.dependency-management" version "1.1.4" id 'java' id 'jacoco' - id "com.github.spotbugs" version "3.0.0" id "com.github.node-gradle.node" version "2.2.1" } - node { version = '20.11.0' npmVersion = '10.2.4' download = true - workDir = file("${project.buildDir}/plugin-slack/ui") - nodeModulesDir = file("${project.rootDir}/plugin-slack/ui") + workDir = file("${project.buildDir}/ui") + nodeModulesDir = file("${project.rootDir}/ui") } npm_run_build { @@ -42,33 +38,32 @@ dependencyManagement { } } +ext['junit-jupiter.version'] = "${junitVersion}" + dependencies { if (releaseMode) { implementation 'com.epam.reportportal:commons-dao' implementation 'com.epam.reportportal:plugin-api' annotationProcessor 'com.epam.reportportal:plugin-api' } else { - implementation 'com.github.reportportal:commons-dao:acf1ec7' - implementation 'com.github.reportportal:plugin-api:188792e' - annotationProcessor 'com.github.reportportal:plugin-api:188792e' + implementation 'com.github.reportportal:commons-dao:a98c172' + implementation 'com.github.reportportal:plugin-api:develop-SNAPSHOT' + annotationProcessor 'com.github.reportportal:plugin-api:develop-SNAPSHOT' } - compile("com.slack.api:slack-api-client:1.27.1") { - exclude group: "org.slf4j" - } - compile 'com.squareup.okhttp3:okhttp:4.12.0' - implementation 'org.hibernate:hibernate-core:5.6.15.Final' -} + compileOnly "org.projectlombok:lombok:${lombokVersion}" + annotationProcessor "org.projectlombok:lombok:${lombokVersion}" + testCompileOnly "org.projectlombok:lombok:${lombokVersion}" + testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}" -spotbugs { - sourceSets = [sourceSets.main] - reportLevel = "high" -} -tasks.withType(SpotBugsTask) { - reports { - xml.enabled false - html.enabled true - } + implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.2' + implementation 'org.hibernate:hibernate-core:5.6.15.Final' + testImplementation 'org.mockito:mockito-core:5.14.2' + testImplementation 'org.mockito:mockito-junit-jupiter:5.14.2' + testImplementation "org.junit.jupiter:junit-jupiter" + testImplementation "org.junit.jupiter:junit-jupiter-api" + testImplementation "org.junit.jupiter:junit-jupiter-engine" + testImplementation 'net.bytebuddy:byte-buddy:1.14.9' } test { @@ -79,7 +74,7 @@ test { exceptionFormat = 'short' } reports { - junitXml.enabled = true + junitXml.required = true } } @@ -109,7 +104,7 @@ jar { } manifest { attributes( - "Class-Path": configurations.compile.collect { it.getName() }.join(' '), + "Class-Path": configurations.compileClasspath.collect { it.getName() }.join(' '), "Plugin-Id": "${pluginId}", "Plugin-Version": "${project.version}", "Plugin-Provider": "Report Portal", @@ -126,9 +121,10 @@ shadowJar { from("ui/build") { into("/resources") } - configurations = [project.configurations.compile] + configurations = [project.configurations.compileClasspath] zip64 true dependencies { + include(dependency('commons-io:commons-io:2.15.1')) } } @@ -138,9 +134,9 @@ task plugin(type: Jar) { with jar } into('lib') { - from configurations.compile + from configurations.compileClasspath } - extension('zip') + archiveExtension.set('zip') } task assemblePlugin(type: Copy) { diff --git a/gradle.properties b/gradle.properties index 0c78520..b0472ab 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,5 @@ version=1.0.0 description=EPAM Report Portal. Slack plugin. pluginId = slack +lombokVersion=1.18.36 +junitVersion=5.11.0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf..afba109 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f4d7b2b..5c40527 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/plugin-slack/gradle.properties b/plugin-slack/gradle.properties deleted file mode 100644 index f8b6aba..0000000 --- a/plugin-slack/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -version=1.0.1 -description=EPAM Report Portal. Slack plugin. -pluginId = slack diff --git a/plugin-slack/project-properties.gradle b/plugin-slack/project-properties.gradle deleted file mode 100644 index b9a5220..0000000 --- a/plugin-slack/project-properties.gradle +++ /dev/null @@ -1,24 +0,0 @@ -sourceCompatibility = JavaVersion.VERSION_11 -targetCompatibility = JavaVersion.VERSION_11 - -def commonScriptsUrl = 'https://raw.githubusercontent.com/reportportal/gradle-scripts/' - -project.ext { - publishRepo = "https://maven.pkg.github.com/reportportal/plugin-slack" - releaseMode = project.hasProperty("releaseMode") - pluginsDir = "$buildDir/plugins" - scriptsUrl = commonScriptsUrl + (releaseMode ? getProperty('scripts.version') : 'develop') - excludeTests = [ - '**/entity/**', - '**/model/**', - ] - limits = [ - 'instruction': 30, - 'branch' : 17, - 'line' : 30, - 'complexity' : 26, - 'method' : 29, - 'class' : 30 - ] -} - diff --git a/project-properties.gradle b/project-properties.gradle index d47c492..a743a9c 100644 --- a/project-properties.gradle +++ b/project-properties.gradle @@ -1,12 +1,31 @@ -sourceCompatibility = JavaVersion.VERSION_11 -targetCompatibility = JavaVersion.VERSION_11 +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} + +def commonScriptsUrl = 'https://raw.githubusercontent.com/reportportal/gradle-scripts/' project.ext { + publishRepo = "https://maven.pkg.github.com/reportportal/plugin-slack" releaseMode = project.hasProperty("releaseMode") - pluginsDir = "$buildDir/jars" - + pluginsDir = "$buildDir/plugins" + scriptsUrl = commonScriptsUrl + (releaseMode ? getProperty('scripts.version') : 'develop') + excludeTests = [ + '**/entity/**', + '**/model/**', + ] + limits = [ + 'instruction': 30, + 'branch' : 17, + 'line' : 30, + 'complexity' : 26, + 'method' : 29, + 'class' : 30 + ] } wrapper { - gradleVersion = '5.4.1' + gradleVersion = '8.10.2' } + + diff --git a/settings.gradle b/settings.gradle index 132da54..330116d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,2 @@ -rootProject.name = 'plugin-slack-epam' -include 'plugin-slack' +rootProject.name = 'plugin-slack' diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/SlackPlugin.java b/src/main/java/com/epam/reportportal/extension/slack/SlackPlugin.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/SlackPlugin.java rename to src/main/java/com/epam/reportportal/extension/slack/SlackPlugin.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java b/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java similarity index 91% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java rename to src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java index 9730bc1..7731941 100644 --- a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java +++ b/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 EPAM Systems + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.epam.reportportal.extension.slack; import com.epam.reportportal.extension.CommonPluginCommand; @@ -47,6 +63,7 @@ import org.springframework.context.support.AbstractApplicationContext; import org.springframework.core.io.FileSystemResource; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; +import org.springframework.web.client.RestTemplate; /** * @author Andrei Piankouski @@ -100,6 +117,9 @@ public class SlackPluginExtension implements ReportPortalExtensionPoint, Disposa @Autowired private ProjectRepository projectRepository; + // @Autowired // uncomment for future release + private final RestTemplate restTemplate = new RestTemplate(); + @Autowired private ApplicationContext applicationContext; @@ -131,7 +151,7 @@ public SlackPluginExtension(Map initParams) { launchFinishEventListenerSupplier = new MemoizingSupplier<>( () -> new SlackLaunchFinishEventListener(projectRepository, - launchRepository, senderCaseMatcher.get(), attachmentResolverSupplier.get())); + launchRepository, senderCaseMatcher.get(), attachmentResolverSupplier.get(), restTemplate)); } @PostConstruct diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/binary/JsonObjectLoader.java b/src/main/java/com/epam/reportportal/extension/slack/binary/JsonObjectLoader.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/binary/JsonObjectLoader.java rename to src/main/java/com/epam/reportportal/extension/slack/binary/JsonObjectLoader.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/binary/MessageTemplateStore.java b/src/main/java/com/epam/reportportal/extension/slack/binary/MessageTemplateStore.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/binary/MessageTemplateStore.java rename to src/main/java/com/epam/reportportal/extension/slack/binary/MessageTemplateStore.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/collector/PropertyCollector.java b/src/main/java/com/epam/reportportal/extension/slack/collector/PropertyCollector.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/collector/PropertyCollector.java rename to src/main/java/com/epam/reportportal/extension/slack/collector/PropertyCollector.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/AttributesCollector.java b/src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/AttributesCollector.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/AttributesCollector.java rename to src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/AttributesCollector.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/LaunchPropertiesCollector.java b/src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/LaunchPropertiesCollector.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/LaunchPropertiesCollector.java rename to src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/LaunchPropertiesCollector.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/ResultColorCollector.java b/src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/ResultColorCollector.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/ResultColorCollector.java rename to src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/ResultColorCollector.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/StatisticsPropertiesCollector.java b/src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/StatisticsPropertiesCollector.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/StatisticsPropertiesCollector.java rename to src/main/java/com/epam/reportportal/extension/slack/collector/laucnh/StatisticsPropertiesCollector.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/EventHandlerFactory.java b/src/main/java/com/epam/reportportal/extension/slack/event/EventHandlerFactory.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/EventHandlerFactory.java rename to src/main/java/com/epam/reportportal/extension/slack/event/EventHandlerFactory.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/handler/EventHandler.java b/src/main/java/com/epam/reportportal/extension/slack/event/handler/EventHandler.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/handler/EventHandler.java rename to src/main/java/com/epam/reportportal/extension/slack/event/handler/EventHandler.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/handler/plugin/PluginLoadedEventHandler.java b/src/main/java/com/epam/reportportal/extension/slack/event/handler/plugin/PluginLoadedEventHandler.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/handler/plugin/PluginLoadedEventHandler.java rename to src/main/java/com/epam/reportportal/extension/slack/event/handler/plugin/PluginLoadedEventHandler.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/launch/SlackLaunchFinishEventListener.java b/src/main/java/com/epam/reportportal/extension/slack/event/launch/SlackLaunchFinishEventListener.java similarity index 88% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/launch/SlackLaunchFinishEventListener.java rename to src/main/java/com/epam/reportportal/extension/slack/event/launch/SlackLaunchFinishEventListener.java index aa79cec..00b400c 100644 --- a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/launch/SlackLaunchFinishEventListener.java +++ b/src/main/java/com/epam/reportportal/extension/slack/event/launch/SlackLaunchFinishEventListener.java @@ -27,11 +27,11 @@ import com.epam.ta.reportportal.entity.project.Project; import com.epam.ta.reportportal.entity.project.ProjectUtils; import com.epam.ta.reportportal.entity.project.email.SenderCase; -import com.slack.api.Slack; import java.util.Map; import java.util.Optional; import org.apache.commons.lang3.BooleanUtils; import org.springframework.context.ApplicationListener; +import org.springframework.web.client.RestTemplate; /** * @author Andrei Piankouski @@ -39,11 +39,11 @@ public class SlackLaunchFinishEventListener implements ApplicationListener { - private final static String SLACK_NOTIFICATION_ATTRIBUTE = "notifications.slack.enabled"; + public final static String SLACK_NOTIFICATION_ATTRIBUTE = "notifications.slack.enabled"; - private final static String WEBHOOK_DETAILS = "webhookURL"; + public final static String WEBHOOK_DETAILS = "webhookURL"; - private final static String PLUGIN_NOTIFICATION_TYPE = "slack"; + public final static String PLUGIN_NOTIFICATION_TYPE = "slack"; private final ProjectRepository projectRepository; @@ -52,15 +52,18 @@ public class SlackLaunchFinishEventListener implements private final SenderCaseMatcher senderCaseMatcher; private final AttachmentResolver attachmentResolver; + private final RestTemplate restTemplate; public SlackLaunchFinishEventListener( ProjectRepository projectRepository, LaunchRepository launchRepository, - SenderCaseMatcher senderCaseMatcher, AttachmentResolver attachmentResolver) { + SenderCaseMatcher senderCaseMatcher, AttachmentResolver attachmentResolver, + RestTemplate restTemplate) { this.projectRepository = projectRepository; this.launchRepository = launchRepository; this.senderCaseMatcher = senderCaseMatcher; this.attachmentResolver = attachmentResolver; + this.restTemplate = restTemplate; } @Override @@ -103,7 +106,7 @@ private void sendNotification(SenderCase senderCase, Launch launch, String launc Optional webhookUrl = getWebhookUrl(senderCase); Optional attachment = resolveAttachment(launch, launchLink); if (webhookUrl.isPresent() && attachment.isPresent()) { - sendSlackNotification(webhookUrl.get(), attachment.get()); + restTemplate.postForLocation(webhookUrl.get(), attachment.get()); } } @@ -116,13 +119,6 @@ private Optional resolveAttachment(Launch launch, String launchLink) { return attachmentResolver.resolve(launch, launchLink); } - private void sendSlackNotification(String webhookUrl, String attachment) { - try (Slack slack = Slack.getInstance()) { - slack.send(webhookUrl, attachment); - } catch (Exception e) { - throw new ReportPortalException("Failed to send Slack notification", e); - } - } private boolean isNotificationsEnabled(Project project) { Map projectConfig = ProjectUtils.getConfigParameters( diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/launch/resolver/AttachmentResolver.java b/src/main/java/com/epam/reportportal/extension/slack/event/launch/resolver/AttachmentResolver.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/launch/resolver/AttachmentResolver.java rename to src/main/java/com/epam/reportportal/extension/slack/event/launch/resolver/AttachmentResolver.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/launch/resolver/SenderCaseMatcher.java b/src/main/java/com/epam/reportportal/extension/slack/event/launch/resolver/SenderCaseMatcher.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/launch/resolver/SenderCaseMatcher.java rename to src/main/java/com/epam/reportportal/extension/slack/event/launch/resolver/SenderCaseMatcher.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/plugin/PluginEventHandlerFactory.java b/src/main/java/com/epam/reportportal/extension/slack/event/plugin/PluginEventHandlerFactory.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/plugin/PluginEventHandlerFactory.java rename to src/main/java/com/epam/reportportal/extension/slack/event/plugin/PluginEventHandlerFactory.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/plugin/PluginEventListener.java b/src/main/java/com/epam/reportportal/extension/slack/event/plugin/PluginEventListener.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/event/plugin/PluginEventListener.java rename to src/main/java/com/epam/reportportal/extension/slack/event/plugin/PluginEventListener.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/factory/PropertyCollectorFactory.java b/src/main/java/com/epam/reportportal/extension/slack/factory/PropertyCollectorFactory.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/factory/PropertyCollectorFactory.java rename to src/main/java/com/epam/reportportal/extension/slack/factory/PropertyCollectorFactory.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/info/PluginInfoProvider.java b/src/main/java/com/epam/reportportal/extension/slack/info/PluginInfoProvider.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/info/PluginInfoProvider.java rename to src/main/java/com/epam/reportportal/extension/slack/info/PluginInfoProvider.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/info/impl/PluginInfoProviderImpl.java b/src/main/java/com/epam/reportportal/extension/slack/info/impl/PluginInfoProviderImpl.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/info/impl/PluginInfoProviderImpl.java rename to src/main/java/com/epam/reportportal/extension/slack/info/impl/PluginInfoProviderImpl.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/enums/SlackEventType.java b/src/main/java/com/epam/reportportal/extension/slack/model/enums/SlackEventType.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/enums/SlackEventType.java rename to src/main/java/com/epam/reportportal/extension/slack/model/enums/SlackEventType.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/enums/SlackIntegrationProperties.java b/src/main/java/com/epam/reportportal/extension/slack/model/enums/SlackIntegrationProperties.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/enums/SlackIntegrationProperties.java rename to src/main/java/com/epam/reportportal/extension/slack/model/enums/SlackIntegrationProperties.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/enums/template/Color.java b/src/main/java/com/epam/reportportal/extension/slack/model/enums/template/Color.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/enums/template/Color.java rename to src/main/java/com/epam/reportportal/extension/slack/model/enums/template/Color.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/enums/template/DefaultTemplateProperty.java b/src/main/java/com/epam/reportportal/extension/slack/model/enums/template/DefaultTemplateProperty.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/enums/template/DefaultTemplateProperty.java rename to src/main/java/com/epam/reportportal/extension/slack/model/enums/template/DefaultTemplateProperty.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/enums/template/StatisticTemplateProperty.java b/src/main/java/com/epam/reportportal/extension/slack/model/enums/template/StatisticTemplateProperty.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/enums/template/StatisticTemplateProperty.java rename to src/main/java/com/epam/reportportal/extension/slack/model/enums/template/StatisticTemplateProperty.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/template/TemplateProperty.java b/src/main/java/com/epam/reportportal/extension/slack/model/template/TemplateProperty.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/template/TemplateProperty.java rename to src/main/java/com/epam/reportportal/extension/slack/model/template/TemplateProperty.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/template/TextProperty.java b/src/main/java/com/epam/reportportal/extension/slack/model/template/TextProperty.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/model/template/TextProperty.java rename to src/main/java/com/epam/reportportal/extension/slack/model/template/TextProperty.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/utils/MemoizingSupplier.java b/src/main/java/com/epam/reportportal/extension/slack/utils/MemoizingSupplier.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/utils/MemoizingSupplier.java rename to src/main/java/com/epam/reportportal/extension/slack/utils/MemoizingSupplier.java diff --git a/plugin-slack/src/main/java/com/epam/reportportal/extension/slack/utils/NotificationConfigConverter.java b/src/main/java/com/epam/reportportal/extension/slack/utils/NotificationConfigConverter.java similarity index 100% rename from plugin-slack/src/main/java/com/epam/reportportal/extension/slack/utils/NotificationConfigConverter.java rename to src/main/java/com/epam/reportportal/extension/slack/utils/NotificationConfigConverter.java diff --git a/plugin-slack/src/main/resources/binary-data.properties b/src/main/resources/binary-data.properties similarity index 100% rename from plugin-slack/src/main/resources/binary-data.properties rename to src/main/resources/binary-data.properties diff --git a/plugin-slack/src/main/resources/message-template/finish-launch.json b/src/main/resources/message-template/finish-launch.json similarity index 99% rename from plugin-slack/src/main/resources/message-template/finish-launch.json rename to src/main/resources/message-template/finish-launch.json index abecb2b..891e640 100644 --- a/plugin-slack/src/main/resources/message-template/finish-launch.json +++ b/src/main/resources/message-template/finish-launch.json @@ -204,4 +204,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/plugin-slack/src/main/resources/scripts/001_add_slack_notification_attribute.sql b/src/main/resources/scripts/001_add_slack_notification_attribute.sql similarity index 100% rename from plugin-slack/src/main/resources/scripts/001_add_slack_notification_attribute.sql rename to src/main/resources/scripts/001_add_slack_notification_attribute.sql diff --git a/src/test/java/com/epam/reportportal/extension/slack/event/launch/SlackLaunchFinishEventListenerTest.java b/src/test/java/com/epam/reportportal/extension/slack/event/launch/SlackLaunchFinishEventListenerTest.java new file mode 100644 index 0000000..65a6af5 --- /dev/null +++ b/src/test/java/com/epam/reportportal/extension/slack/event/launch/SlackLaunchFinishEventListenerTest.java @@ -0,0 +1,85 @@ +/* + * Copyright 2024 EPAM Systems + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.epam.reportportal.extension.slack.event.launch; + +import static com.epam.reportportal.extension.slack.utils.SampleAttachment.SAMPLE_ATTACHMENT; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.epam.reportportal.extension.event.LaunchFinishedPluginEvent; +import com.epam.reportportal.extension.slack.event.launch.resolver.AttachmentResolver; +import com.epam.reportportal.extension.slack.event.launch.resolver.SenderCaseMatcher; +import com.epam.reportportal.extension.slack.utils.MockData; +import com.epam.ta.reportportal.dao.LaunchRepository; +import com.epam.ta.reportportal.dao.ProjectRepository; +import com.epam.ta.reportportal.entity.launch.Launch; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Optional; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Answers; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.web.client.RestTemplate; + +/** + * @author Siarhei Hrabko + */ +@ExtendWith(MockitoExtension.class) +class SlackLaunchFinishEventListenerTest { + + private static final String LAUNCH_LINK = "http://localhost:8080/ui/#admin123/launches/all/55"; + + @Mock + RestTemplate restTemplate;// = new RestTemplate(); + @Mock + ProjectRepository projectRepository; + @Mock + LaunchRepository launchRepository; + @Mock(answer = Answers.CALLS_REAL_METHODS) + SenderCaseMatcher senderCaseMatcher; + @Mock + AttachmentResolver attachmentResolver; + + @Test + @Disabled("until RestTemplate initialization in SlackPluginExtension switched to @Autowired") + void sendNotificationPositive() throws URISyntaxException { + var slackLaunchFinishEventListener = new SlackLaunchFinishEventListener(projectRepository, + launchRepository, senderCaseMatcher, attachmentResolver, restTemplate); + + when(projectRepository.findById(anyLong())) + .thenReturn(Optional.of(MockData.getProjectSample())); + when(launchRepository.findById(anyLong())) + .thenReturn(Optional.of(MockData.getLaunch())); + when(attachmentResolver.resolve(any(Launch.class), anyString())) + .thenReturn(Optional.of(SAMPLE_ATTACHMENT)); + when(restTemplate.postForLocation(anyString(), anyString())) + .thenReturn(new URI("http://localhost:8080")); + + slackLaunchFinishEventListener.onApplicationEvent( + new LaunchFinishedPluginEvent(1L, 10L, LAUNCH_LINK)); + + verify(restTemplate, times(1)).postForLocation(anyString(), anyString()); + + } +} diff --git a/src/test/java/com/epam/reportportal/extension/slack/utils/MockData.java b/src/test/java/com/epam/reportportal/extension/slack/utils/MockData.java new file mode 100644 index 0000000..3a1b203 --- /dev/null +++ b/src/test/java/com/epam/reportportal/extension/slack/utils/MockData.java @@ -0,0 +1,119 @@ +/* + * Copyright 2024 EPAM Systems + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.epam.reportportal.extension.slack.utils; + +import static com.epam.reportportal.extension.slack.event.launch.SlackLaunchFinishEventListener.PLUGIN_NOTIFICATION_TYPE; +import static com.epam.reportportal.extension.slack.event.launch.SlackLaunchFinishEventListener.SLACK_NOTIFICATION_ATTRIBUTE; +import static com.epam.reportportal.extension.slack.event.launch.SlackLaunchFinishEventListener.WEBHOOK_DETAILS; +import static com.epam.ta.reportportal.entity.enums.ProjectAttributeEnum.NOTIFICATIONS_ENABLED; + +import com.epam.ta.reportportal.entity.attribute.Attribute; +import com.epam.ta.reportportal.entity.enums.SendCase; +import com.epam.ta.reportportal.entity.launch.Launch; +import com.epam.ta.reportportal.entity.project.Project; +import com.epam.ta.reportportal.entity.project.ProjectAttribute; +import com.epam.ta.reportportal.entity.project.email.SenderCase; +import com.epam.ta.reportportal.entity.project.email.SenderCaseOptions; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import java.util.stream.Stream; +import org.apache.commons.io.IOUtils; + +public class MockData { + + private static final String LAUNCH_NAME_1 = "Launch name 1"; + + public static Project getProjectSample() { + var project = new Project(); + + project.setId(1L); + project.setSenderCases(Collections.singleton(getSenderCase())); + project.setProjectAttributes(getProjectAttributes()); + return project; + } + + private static Set getProjectAttributes() { + var attribute1 = new Attribute(); + attribute1.setId(13L); + attribute1.setName(NOTIFICATIONS_ENABLED.getAttribute()); + + var attribute2 = new Attribute(); + attribute2.setId(21L); + attribute2.setName(SLACK_NOTIFICATION_ATTRIBUTE); + + ProjectAttribute projectAttribute1 = new ProjectAttribute() + .withAttribute(attribute1) + .withProject(new Project()) + .withValue("true"); + + ProjectAttribute projectAttribute2 = new ProjectAttribute() + .withAttribute(attribute2) + .withProject(new Project()) + .withValue("true"); + + return Set.of(projectAttribute1, projectAttribute2); + + } + + + public static SenderCase getSenderCase() { + var senderCase = new SenderCase(); + senderCase.setEnabled(true); + senderCase.setType(PLUGIN_NOTIFICATION_TYPE); + senderCase.setSendCase(SendCase.ALWAYS); + senderCase.setLaunchNames(Set.of(LAUNCH_NAME_1)); + senderCase.setRuleDetails(getSenderCaseOptions()); + return senderCase; + } + + public static Launch getLaunch() { + var launch = new Launch(); + launch.setId(20L); + launch.setName(LAUNCH_NAME_1); + return launch; + } + + public static SenderCaseOptions getSenderCaseOptions() { + SenderCaseOptions senderCaseOptions = new SenderCaseOptions(); + senderCaseOptions.setOptions( + Map.of(WEBHOOK_DETAILS, + "https://hooks.slack.com/services/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")); + return senderCaseOptions; + } + + public static String readFileToString(String path) throws IOException { + + try (InputStream resourceAsStream = MockData.class.getClassLoader().getResourceAsStream(path)) { + if (resourceAsStream != null) { + return IOUtils.toString(resourceAsStream, StandardCharsets.UTF_8); + } else { + StringBuilder sb = new StringBuilder(); + try (Stream lines = Files.lines(Paths.get(path))) { + lines.forEach(sb::append); + } + return sb.toString(); + } + } + } +} + diff --git a/src/test/java/com/epam/reportportal/extension/slack/utils/SampleAttachment.java b/src/test/java/com/epam/reportportal/extension/slack/utils/SampleAttachment.java new file mode 100644 index 0000000..8623a71 --- /dev/null +++ b/src/test/java/com/epam/reportportal/extension/slack/utils/SampleAttachment.java @@ -0,0 +1,231 @@ +/* + * Copyright 2024 EPAM Systems + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.epam.reportportal.extension.slack.utils; + +public class SampleAttachment { + + public static final String SAMPLE_ATTACHMENT = """ + { + "attachments": [ + { + "color": "#FF0000", + "blocks": [ + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": "*LAUNCH FINISHED:*\\n" + } + ] + }, + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": "*Start time:*\\n2024-12-11T21:14:52.790Z" + }, + { + "type": "mrkdwn", + "text": "*Finish time:*\\n2024-12-11T21:14:53.778Z" + } + ] + }, + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": "*ID:*\\n56" + }, + { + "type": "mrkdwn", + "text": "*UUID:*\\n7d45aa94-927e-430f-9819-e74253cb1e46" + } + ] + }, + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": "*Description*:\\nTest launch" + } + ] + }, + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": "*Attributes*:\\n[:string]" + } + ] + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "\\n" + } + }, + { + "type": "rich_text", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Execution Statistics:", + "style": { + "bold": true + } + }, + { + "type": "text", + "text": "\\n" + } + ] + }, + { + "type": "rich_text_quote", + "elements": [ + { + "type": "emoji", + "name": "black_circle", + "unicode": "26ab" + }, + { + "type": "text", + "text": " TOTAL:\\t2\\n" + }, + { + "type": "emoji", + "name": "large_green_circle", + "unicode": "1f7e2" + }, + { + "type": "text", + "text": " PASSED:\\t0\\n" + }, + { + "type": "emoji", + "name": "red_circle", + "unicode": "1f534" + }, + { + "type": "text", + "text": " FAILED:\\t2\\n" + }, + { + "type": "emoji", + "name": "white_circle", + "unicode": "26aa" + }, + { + "type": "text", + "text": " SKIPPED:\\t0" + } + ] + } + ] + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "\\n" + } + }, + { + "type": "rich_text", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Defect Statistics:", + "style": { + "bold": true + } + }, + { + "type": "text", + "text": "\\n" + } + ] + }, + { + "type": "rich_text_quote", + "elements": [ + { + "type": "emoji", + "name": "large_red_square", + "unicode": "1f7e5" + }, + { + "type": "text", + "text": " PRODUCT BUG GROUP:\\t\\t0\\n" + }, + { + "type": "emoji", + "name": "large_yellow_square", + "unicode": "1f7e8" + }, + { + "type": "text", + "text": " AUTOMATION BUG GROUP:\\t1\\n" + }, + { + "type": "emoji", + "name": "large_blue_square", + "unicode": "1f7e6" + }, + { + "type": "text", + "text": " SISTEM ISSUE GROUP: \\t\\t0\\n" + }, + { + "type": "emoji", + "name": "white_square" + }, + { + "type": "text", + "text": " NO DEFECT GROUP:\\t\\t\\t0\\n" + }, + { + "type": "emoji", + "name": "black_square" + }, + { + "type": "text", + "text": " TO INVESTIGATE GROUP:\\t\\t1" + } + ] + } + ] + } + ] + } + ] + } + """; + +} diff --git a/plugin-slack/ui/.editorconfig b/ui/.editorconfig similarity index 100% rename from plugin-slack/ui/.editorconfig rename to ui/.editorconfig diff --git a/plugin-slack/ui/.eslintignore b/ui/.eslintignore similarity index 100% rename from plugin-slack/ui/.eslintignore rename to ui/.eslintignore diff --git a/plugin-slack/ui/.eslintrc b/ui/.eslintrc similarity index 100% rename from plugin-slack/ui/.eslintrc rename to ui/.eslintrc diff --git a/plugin-slack/ui/.gitignore b/ui/.gitignore similarity index 100% rename from plugin-slack/ui/.gitignore rename to ui/.gitignore diff --git a/plugin-slack/ui/.prettierrc b/ui/.prettierrc similarity index 100% rename from plugin-slack/ui/.prettierrc rename to ui/.prettierrc diff --git a/plugin-slack/ui/README.md b/ui/README.md similarity index 100% rename from plugin-slack/ui/README.md rename to ui/README.md diff --git a/plugin-slack/ui/devServer.js b/ui/devServer.js similarity index 100% rename from plugin-slack/ui/devServer.js rename to ui/devServer.js diff --git a/plugin-slack/ui/package-lock.json b/ui/package-lock.json similarity index 100% rename from plugin-slack/ui/package-lock.json rename to ui/package-lock.json diff --git a/plugin-slack/ui/package.json b/ui/package.json similarity index 100% rename from plugin-slack/ui/package.json rename to ui/package.json diff --git a/plugin-slack/ui/src/common/css/colors.scss b/ui/src/common/css/colors.scss similarity index 100% rename from plugin-slack/ui/src/common/css/colors.scss rename to ui/src/common/css/colors.scss diff --git a/plugin-slack/ui/src/common/css/fonts.scss b/ui/src/common/css/fonts.scss similarity index 100% rename from plugin-slack/ui/src/common/css/fonts.scss rename to ui/src/common/css/fonts.scss diff --git a/plugin-slack/ui/src/common/css/screen-size.scss b/ui/src/common/css/screen-size.scss similarity index 100% rename from plugin-slack/ui/src/common/css/screen-size.scss rename to ui/src/common/css/screen-size.scss diff --git a/plugin-slack/ui/src/common/css/z-index.scss b/ui/src/common/css/z-index.scss similarity index 100% rename from plugin-slack/ui/src/common/css/z-index.scss rename to ui/src/common/css/z-index.scss diff --git a/plugin-slack/ui/src/components/moduleName/index.ts b/ui/src/components/moduleName/index.ts similarity index 100% rename from plugin-slack/ui/src/components/moduleName/index.ts rename to ui/src/components/moduleName/index.ts diff --git a/plugin-slack/ui/src/components/moduleName/moduleName.tsx b/ui/src/components/moduleName/moduleName.tsx similarity index 100% rename from plugin-slack/ui/src/components/moduleName/moduleName.tsx rename to ui/src/components/moduleName/moduleName.tsx diff --git a/plugin-slack/ui/src/declarations.d.ts b/ui/src/declarations.d.ts similarity index 100% rename from plugin-slack/ui/src/declarations.d.ts rename to ui/src/declarations.d.ts diff --git a/plugin-slack/ui/src/index.ts b/ui/src/index.ts similarity index 100% rename from plugin-slack/ui/src/index.ts rename to ui/src/index.ts diff --git a/plugin-slack/ui/src/metadata.json b/ui/src/metadata.json similarity index 100% rename from plugin-slack/ui/src/metadata.json rename to ui/src/metadata.json diff --git a/plugin-slack/ui/src/plugin-icon.svg b/ui/src/plugin-icon.svg similarity index 100% rename from plugin-slack/ui/src/plugin-icon.svg rename to ui/src/plugin-icon.svg diff --git a/plugin-slack/ui/tsconfig.eslint.json b/ui/tsconfig.eslint.json similarity index 100% rename from plugin-slack/ui/tsconfig.eslint.json rename to ui/tsconfig.eslint.json diff --git a/plugin-slack/ui/tsconfig.json b/ui/tsconfig.json similarity index 100% rename from plugin-slack/ui/tsconfig.json rename to ui/tsconfig.json diff --git a/plugin-slack/ui/webpack.config.js b/ui/webpack.config.js similarity index 100% rename from plugin-slack/ui/webpack.config.js rename to ui/webpack.config.js