From b36fec8c970d0077f329112bc984a6dfe96852e0 Mon Sep 17 00:00:00 2001 From: siarhei_hrabko Date: Thu, 12 Dec 2024 11:57:26 +0300 Subject: [PATCH 1/3] EPMRPP-97593 update dependencies. add unit test --- build.gradle | 19 +- gradle.properties | 2 + .../extension/slack/SlackPluginExtension.java | 6 +- .../SlackLaunchFinishEventListener.java | 22 +- .../message-template/finish-launch.json | 2 +- .../SlackLaunchFinishEventListenerTest.java | 64 ++++++ .../extension/slack/utils/MockData.java | 103 +++++++++ .../slack/utils/SampleAttachment.java | 215 ++++++++++++++++++ 8 files changed, 414 insertions(+), 19 deletions(-) create mode 100644 src/test/java/com/epam/reportportal/extension/slack/event/launch/SlackLaunchFinishEventListenerTest.java create mode 100644 src/test/java/com/epam/reportportal/extension/slack/utils/MockData.java create mode 100644 src/test/java/com/epam/reportportal/extension/slack/utils/SampleAttachment.java diff --git a/build.gradle b/build.gradle index 46a2370..92f3f51 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,8 @@ dependencyManagement { } } +ext['junit-jupiter.version'] = "${junitVersion}" + dependencies { if (releaseMode) { implementation 'com.epam.reportportal:commons-dao' @@ -49,12 +51,20 @@ dependencies { annotationProcessor 'com.github.reportportal:plugin-api:develop-SNAPSHOT' } - implementation("com.slack.api:slack-api-client:1.27.1") { - exclude group: "org.slf4j" - } + compileOnly "org.projectlombok:lombok:${lombokVersion}" + annotationProcessor "org.projectlombok:lombok:${lombokVersion}" + testCompileOnly "org.projectlombok:lombok:${lombokVersion}" + testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}" + implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.2' - implementation 'com.squareup.okhttp3:okhttp:4.12.0' 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' + //testImplementation "org.junit.jupiter:mockito-junit-jupiter:${junitVersion}" } test { @@ -115,6 +125,7 @@ shadowJar { configurations = [project.configurations.compileClasspath] zip64 true dependencies { + include(dependency('commons-io:commons-io:2.15.1')) } } 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/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java b/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java index 9730bc1..0a9a7c8 100644 --- a/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java +++ b/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java @@ -47,6 +47,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 +101,9 @@ public class SlackPluginExtension implements ReportPortalExtensionPoint, Disposa @Autowired private ProjectRepository projectRepository; + @Autowired + private RestTemplate restTemplate; + @Autowired private ApplicationContext applicationContext; @@ -131,7 +135,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/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 index aa79cec..00b400c 100644 --- a/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/src/main/resources/message-template/finish-launch.json b/src/main/resources/message-template/finish-launch.json index abecb2b..891e640 100644 --- a/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/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..9a79267 --- /dev/null +++ b/src/test/java/com/epam/reportportal/extension/slack/event/launch/SlackLaunchFinishEventListenerTest.java @@ -0,0 +1,64 @@ +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.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; + +@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 + 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..00fede4 --- /dev/null +++ b/src/test/java/com/epam/reportportal/extension/slack/utils/MockData.java @@ -0,0 +1,103 @@ +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..f2eebe7 --- /dev/null +++ b/src/test/java/com/epam/reportportal/extension/slack/utils/SampleAttachment.java @@ -0,0 +1,215 @@ +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" + } + ] + } + ] + } + ] + } + ] + } + """; + +} From 0135d8c10ae5a7ea543804b282cc9a48fa5443e1 Mon Sep 17 00:00:00 2001 From: siarhei_hrabko Date: Thu, 12 Dec 2024 12:23:57 +0300 Subject: [PATCH 2/3] EPMRPP-97593 copyright added --- .../extension/slack/SlackPluginExtension.java | 16 ++++++++++++++++ .../SlackLaunchFinishEventListenerTest.java | 19 +++++++++++++++++++ .../extension/slack/utils/MockData.java | 16 ++++++++++++++++ .../slack/utils/SampleAttachment.java | 16 ++++++++++++++++ 4 files changed, 67 insertions(+) diff --git a/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java b/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java index 0a9a7c8..e2ac9a2 100644 --- a/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; 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 index 9a79267..355231c 100644 --- 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 @@ -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.event.launch; import static com.epam.reportportal.extension.slack.utils.SampleAttachment.SAMPLE_ATTACHMENT; @@ -25,6 +41,9 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.web.client.RestTemplate; +/** + * @author Siarhei Hrabko + */ @ExtendWith(MockitoExtension.class) class SlackLaunchFinishEventListenerTest { 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 index 00fede4..3a1b203 100644 --- a/src/test/java/com/epam/reportportal/extension/slack/utils/MockData.java +++ b/src/test/java/com/epam/reportportal/extension/slack/utils/MockData.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.utils; import static com.epam.reportportal.extension.slack.event.launch.SlackLaunchFinishEventListener.PLUGIN_NOTIFICATION_TYPE; 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 index f2eebe7..8623a71 100644 --- a/src/test/java/com/epam/reportportal/extension/slack/utils/SampleAttachment.java +++ b/src/test/java/com/epam/reportportal/extension/slack/utils/SampleAttachment.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.utils; public class SampleAttachment { From 3d168569ea5626719fcdf1e478523b364eed5aba Mon Sep 17 00:00:00 2001 From: siarhei_hrabko Date: Thu, 12 Dec 2024 12:50:06 +0300 Subject: [PATCH 3/3] EPMRPP-97593 get restTemplate via constructor --- build.gradle | 1 - .../reportportal/extension/slack/SlackPluginExtension.java | 4 ++-- .../event/launch/SlackLaunchFinishEventListenerTest.java | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 92f3f51..71aaadd 100644 --- a/build.gradle +++ b/build.gradle @@ -64,7 +64,6 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter-api" testImplementation "org.junit.jupiter:junit-jupiter-engine" testImplementation 'net.bytebuddy:byte-buddy:1.14.9' - //testImplementation "org.junit.jupiter:mockito-junit-jupiter:${junitVersion}" } test { diff --git a/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java b/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java index e2ac9a2..7731941 100644 --- a/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java +++ b/src/main/java/com/epam/reportportal/extension/slack/SlackPluginExtension.java @@ -117,8 +117,8 @@ public class SlackPluginExtension implements ReportPortalExtensionPoint, Disposa @Autowired private ProjectRepository projectRepository; - @Autowired - private RestTemplate restTemplate; + // @Autowired // uncomment for future release + private final RestTemplate restTemplate = new RestTemplate(); @Autowired private ApplicationContext applicationContext; 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 index 355231c..65a6af5 100644 --- 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 @@ -34,6 +34,7 @@ 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; @@ -61,6 +62,7 @@ class SlackLaunchFinishEventListenerTest { 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);