-
Notifications
You must be signed in to change notification settings - Fork 15
Release #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Release #48
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e0150fb
Add attachment embedding
HardNorth a8050e3
Update attachment embedding
HardNorth d3c9f79
Update attachment embedding
HardNorth 42faa84
Add embedding test
HardNorth 5999d6c
CHANGELOG.md update
HardNorth 6e5d072
Update src/main/java/com/epam/reportportal/karate/ReportPortalHook.java
HardNorth 89dba6e
reformat
HardNorth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| # Changelog | ||
|
|
||
| ## [Unreleased] | ||
| ### Added | ||
| - Attachment logging, by @HardNorth | ||
|
|
||
| ## [5.3.0] | ||
| ### Changed | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/test/java/com/epam/reportportal/karate/logging/EmbedLoggingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * Copyright 2025 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 | ||
| * | ||
| * https://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.karate.logging; | ||
|
|
||
| import com.epam.reportportal.karate.utils.TestUtils; | ||
| import com.epam.reportportal.listeners.LogLevel; | ||
| import com.epam.reportportal.service.ReportPortal; | ||
| import com.epam.reportportal.service.ReportPortalClient; | ||
| import com.epam.reportportal.util.test.CommonUtils; | ||
| import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; | ||
| import com.intuit.karate.Results; | ||
| import okhttp3.MultipartBody; | ||
| import org.apache.commons.lang3.tuple.Pair; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
| import org.mockito.ArgumentCaptor; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static com.epam.reportportal.karate.utils.TestUtils.*; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.*; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
| public class EmbedLoggingTest { | ||
| private static final String TEST_FEATURE = "classpath:feature/embed.feature"; | ||
| private final String launchUuid = CommonUtils.namedId("launch_"); | ||
| private final String featureId = CommonUtils.namedId("feature_"); | ||
| private final String scenarioId = CommonUtils.namedId("scenario_"); | ||
| private final List<String> stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(2).collect(Collectors.toList()); | ||
|
|
||
| private final ReportPortalClient client = mock(ReportPortalClient.class); | ||
| private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); | ||
|
|
||
| @BeforeEach | ||
| public void setupMock() { | ||
| mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); | ||
| mockBatchLogging(client); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(booleans = { true, false }) | ||
| @SuppressWarnings({ "unchecked", "rawtypes" }) | ||
| public void test_embed_image_attachment(boolean report) { | ||
| Results results; | ||
| if (report) { | ||
| results = TestUtils.runAsReport(rp, TEST_FEATURE); | ||
| } else { | ||
| results = TestUtils.runAsHook(rp, TEST_FEATURE); | ||
| } | ||
| assertThat(results.getFailCount(), equalTo(0)); | ||
|
|
||
| ArgumentCaptor<List> logCaptor = ArgumentCaptor.forClass(List.class); | ||
| verify(client).log(logCaptor.capture()); | ||
|
|
||
| List<SaveLogRQ> logs = logCaptor.getAllValues() | ||
| .stream() | ||
| .flatMap(rq -> extractJsonParts((List<MultipartBody.Part>) rq).stream()) | ||
| .collect(Collectors.toList()); | ||
| assertThat(logs, hasSize(2)); | ||
|
|
||
| List<SaveLogRQ> attachmentLogs = logs.stream() | ||
| .filter(log -> log.getFile() != null) | ||
| .filter(log -> log.getMessage() != null && log.getMessage().startsWith("Attachment: ")) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| assertThat("Should have one attachment log message", attachmentLogs, hasSize(1)); | ||
|
|
||
| // Verify the attachment log properties | ||
| SaveLogRQ attachmentLog = attachmentLogs.get(0); | ||
| assertThat("Attachment log should have INFO level", attachmentLog.getLevel(), equalTo(LogLevel.INFO.name())); | ||
| assertThat("Attachment log should have item UUID", attachmentLog.getItemUuid(), notNullValue()); | ||
| assertThat("Attachment log should have log time", attachmentLog.getLogTime(), notNullValue()); | ||
| assertThat("Attachment message should contain image/png", attachmentLog.getMessage(), equalTo("Attachment: image/png")); | ||
|
|
||
| List<Pair<String, byte[]>> attachments = logCaptor.getAllValues() | ||
| .stream() | ||
| .flatMap(rq -> extractBinaryParts((List<MultipartBody.Part>) rq).stream()) | ||
| .collect(Collectors.toList()); | ||
| assertThat(attachments, hasSize(1)); | ||
| assertThat(attachments.get(0).getKey(), equalTo("image/png")); | ||
| assertThat(attachments.get(0).getValue().length, greaterThan(0)); | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Feature: Demonstrate image attachment | ||
|
|
||
| Scenario: I attach image to report | ||
| When def bytes = karate.read('classpath:pug/lucky.png') | ||
| Then karate.embed(bytes, 'image/png') |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.