-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from reportportal/develop
Release
- Loading branch information
Showing
15 changed files
with
426 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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,28 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: bug | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**Steps to Reproduce** | ||
Steps to reproduce the behavior: | ||
1. ... | ||
2. ... | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Actual behavior** | ||
What actually happened. | ||
|
||
**Dependency versions** | ||
Include version info of the following libraries: client-java, logger-java-log4j | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
This file contains 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,20 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
title: '' | ||
labels: enhancement | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Is your feature request related to a problem? Please describe.** | ||
A clear and concise description of what the issue is. Ex. I'm always frustrated when [...] | ||
|
||
**Describe the solution you'd like** | ||
A clear and concise description of what you want to happen. | ||
|
||
**Describe alternatives you've considered** | ||
A clear and concise description of any alternative solutions or features you've considered. | ||
|
||
**Additional context** | ||
Add any other context or screenshots about the feature request here. |
This file contains 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 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 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 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 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 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 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 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
118 changes: 118 additions & 0 deletions
118
src/test/java/com/epam/ta/reportportal/log4j/appender/ReportPortalAppenderTest.java
This file contains 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,118 @@ | ||
package com.epam.ta.reportportal.log4j.appender; | ||
|
||
import com.epam.reportportal.service.Launch; | ||
import com.epam.reportportal.service.LoggingContext; | ||
import com.epam.reportportal.service.ReportPortalClient; | ||
import com.epam.reportportal.service.logs.LoggingSubscriber; | ||
import com.epam.reportportal.util.test.CommonUtils; | ||
import com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS; | ||
import io.reactivex.Maybe; | ||
import io.reactivex.Scheduler; | ||
import io.reactivex.schedulers.Schedulers; | ||
import okhttp3.MediaType; | ||
import okhttp3.MultipartBody; | ||
import okhttp3.RequestBody; | ||
import org.apache.commons.io.IOUtils; | ||
import org.apache.log4j.Level; | ||
import org.apache.log4j.Logger; | ||
import org.apache.log4j.PatternLayout; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mock; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
import static java.util.Optional.ofNullable; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class ReportPortalAppenderTest { | ||
@Mock | ||
private ReportPortalClient client; | ||
|
||
private final ExecutorService executor = CommonUtils.testExecutor(); | ||
private final Scheduler scheduler = Schedulers.from(executor); | ||
|
||
private static Logger createLoggerFor(Class<?> clazz) { | ||
PatternLayout py = new PatternLayout("%date %level [%thread] %logger{10} [%file:%line] %msg%n"); | ||
ReportPortalAppender appender = new ReportPortalAppender(); | ||
appender.setLayout(py); | ||
|
||
Logger logger = Logger.getLogger(clazz); | ||
logger.addAppender(appender); | ||
logger.setLevel(Level.DEBUG); | ||
return logger; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private static void mockBatchLogging(ReportPortalClient client) { | ||
when(client.log(any(List.class))).thenReturn(Maybe.just(new BatchSaveOperatingRS())); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
CommonUtils.shutdownExecutorService(executor); | ||
} | ||
|
||
@Test | ||
@SuppressWarnings({ "unchecked", "ReactiveStreamsUnusedPublisher" }) | ||
public void test_logger_append() { | ||
mockBatchLogging(client); | ||
LoggingContext.init(Maybe.just("launch_uuid"), Maybe.just("item_uuid"), client, scheduler); | ||
Logger logger = createLoggerFor(Launch.class); | ||
logger.info("test message"); | ||
LoggingContext.complete(); | ||
verify(client).log(any(List.class)); | ||
} | ||
|
||
@Test | ||
@SuppressWarnings({ "unchecked", "ReactiveStreamsUnusedPublisher" }) | ||
public void test_logger_skip() { | ||
LoggingContext.init(Maybe.just("launch_uuid"), Maybe.just("item_uuid"), client, scheduler); | ||
Logger logger = createLoggerFor(LoggingSubscriber.class); | ||
logger.info("test message"); | ||
LoggingContext.complete(); | ||
verify(client, timeout(100).times(0)).log(any(List.class)); | ||
} | ||
|
||
@Test | ||
@SuppressWarnings({ "unchecked", "ReactiveStreamsUnusedPublisher" }) | ||
public void test_binary_file_message_encoding() throws IOException { | ||
mockBatchLogging(client); | ||
LoggingContext.init(Maybe.just("launch_uuid"), Maybe.just("item_uuid"), client, scheduler); | ||
String message = "test message"; | ||
Logger logger = createLoggerFor(this.getClass()); | ||
byte[] content; | ||
try (InputStream is = ofNullable(Thread.currentThread() | ||
.getContextClassLoader() | ||
.getResourceAsStream("pug/unlucky.jpg")).orElseThrow(() -> new IllegalStateException( | ||
"Unable to find test image file"))) { | ||
content = IOUtils.toByteArray(is); | ||
} | ||
logger.info(String.format("RP_MESSAGE#FILE#%s#%s", "src/test/resources/pug/unlucky.jpg", message)); | ||
LoggingContext.complete(); | ||
ArgumentCaptor<List<MultipartBody.Part>> captor = ArgumentCaptor.forClass(List.class); | ||
verify(client).log(captor.capture()); | ||
|
||
List<MultipartBody.Part> request = captor.getValue(); | ||
assertThat(request, hasSize(2)); | ||
|
||
RequestBody jsonPart = request.get(0).body(); | ||
MediaType jsonPartType = jsonPart.contentType(); | ||
assertThat(jsonPartType, notNullValue()); | ||
assertThat(jsonPartType.toString(), Matchers.startsWith("application/json")); | ||
|
||
RequestBody binaryPart = request.get(1).body(); | ||
MediaType binaryPartType = binaryPart.contentType(); | ||
assertThat(binaryPartType, notNullValue()); | ||
assertThat(binaryPartType.toString(), equalTo("image/jpeg")); | ||
assertThat(binaryPart.contentLength(), equalTo((long) content.length)); | ||
} | ||
} |
Oops, something went wrong.