-
Notifications
You must be signed in to change notification settings - Fork 17
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 #108 from entrudo/RPP_Agents_Java_JUnit_LastErrorLog
RPP_Agents_Java_JUnit_LastErrorLog
- Loading branch information
Showing
3 changed files
with
144 additions
and
0 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
91 changes: 91 additions & 0 deletions
91
src/test/java/com/epam/reportportal/junit/callback/FailedDescriptionTest.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,91 @@ | ||
package com.epam.reportportal.junit.callback; | ||
|
||
import static com.epam.reportportal.junit.utils.TestUtils.PROCESSING_TIMEOUT; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.startsWith; | ||
import static org.mockito.ArgumentMatchers.same; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.timeout; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import com.epam.reportportal.junit.ReportPortalListener; | ||
import com.epam.reportportal.junit.features.callback.FailedDescriptionFeatureTest; | ||
import com.epam.reportportal.junit.utils.TestUtils; | ||
import com.epam.reportportal.listeners.ListenerParameters; | ||
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.FinishTestItemRQ; | ||
import com.epam.ta.reportportal.ws.model.StartTestItemRQ; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
|
||
public class FailedDescriptionTest { | ||
private final String suiteId = CommonUtils.namedId("suite_"); | ||
private final String classId = CommonUtils.namedId("class_"); | ||
private final List<String> methodIds = Stream.generate(() -> CommonUtils.namedId("method_")).limit(2).collect(Collectors.toList()); | ||
private final ReportPortalClient client = mock(ReportPortalClient.class); | ||
private final String testWithDescriptionAndAssertException = "testWithDescriptionAndAssertException"; | ||
private final String testWithDescriptionAndStepError = "testWithDescriptionAndStepError"; | ||
private final String testWithDescriptionAndException = "testWithDescriptionAndException"; | ||
private final String testErrorMessagePattern = "%s(com.epam.reportportal.junit.features.callback.FailedDescriptionFeatureTest)\nError: \n%s"; | ||
private final String assertErrorMessage = "java.lang.AssertionError: expected:<0> but was:<1>"; | ||
private final String exceptionStepErrorMessage = "java.util.NoSuchElementException: Test error message"; | ||
private final String exceptionErrorMessage = "java.lang.RuntimeException: Test error message"; | ||
private final String failedStatus = "FAILED"; | ||
private final String passedStatus = "PASSED"; | ||
|
||
@BeforeEach | ||
public void setupMock() { | ||
TestUtils.mockLaunch(client, null, suiteId, classId, methodIds); | ||
TestUtils.mockBatchLogging(client); | ||
ListenerParameters params = TestUtils.standardParameters(); | ||
ReportPortalListener.setReportPortal(ReportPortal.create(client, params, TestUtils.testExecutor())); | ||
} | ||
|
||
@Test | ||
public void verify_retrieve_by_description() { | ||
TestUtils.runClasses(FailedDescriptionFeatureTest.class); | ||
|
||
ArgumentCaptor<StartTestItemRQ> startTestCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client, timeout(PROCESSING_TIMEOUT).atLeastOnce()).startTestItem(same(suiteId), startTestCaptor.capture()); | ||
|
||
ArgumentCaptor<FinishTestItemRQ> finishTestCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); | ||
verify(client, timeout(PROCESSING_TIMEOUT).atLeastOnce()).finishTestItem(same(classId), finishTestCaptor.capture()); | ||
|
||
List<FinishTestItemRQ> finishTests = finishTestCaptor.getAllValues(); | ||
FinishTestItemRQ testCaseWithDescriptionAndAssertException = finishTests.stream() | ||
.filter(f -> f.getDescription().startsWith(testWithDescriptionAndAssertException)) | ||
.findFirst() | ||
.orElseThrow(NoSuchElementException::new); | ||
FinishTestItemRQ testCaseWithDescriptionAndStepError = finishTests.stream() | ||
.filter(f -> f.getDescription().startsWith(testWithDescriptionAndStepError)) | ||
.findFirst() | ||
.orElseThrow(NoSuchElementException::new); | ||
FinishTestItemRQ tesCaseWithDescriptionAndException = finishTests.stream() | ||
.filter(f -> f.getDescription().startsWith(testWithDescriptionAndException)) | ||
.findFirst() | ||
.orElseThrow(NoSuchElementException::new); | ||
FinishTestItemRQ tesCaseWithDescriptionAndPassed = finishTests.stream() | ||
.filter(f -> f.getDescription() == null) | ||
.findFirst() | ||
.orElseThrow(NoSuchElementException::new); | ||
|
||
assertThat(testCaseWithDescriptionAndAssertException.getDescription(), startsWith(String.format(testErrorMessagePattern, testWithDescriptionAndAssertException, assertErrorMessage))); | ||
assertThat(testCaseWithDescriptionAndAssertException.getStatus(), equalTo(failedStatus)); | ||
|
||
assertThat(testCaseWithDescriptionAndStepError.getDescription(), startsWith(String.format(testErrorMessagePattern, testWithDescriptionAndStepError, exceptionStepErrorMessage))); | ||
assertThat(testCaseWithDescriptionAndStepError.getStatus(), equalTo(failedStatus)); | ||
|
||
assertThat(tesCaseWithDescriptionAndException.getDescription(), startsWith(String.format(testErrorMessagePattern, testWithDescriptionAndException, exceptionErrorMessage))); | ||
assertThat(tesCaseWithDescriptionAndException.getStatus(), equalTo(failedStatus)); | ||
|
||
assertThat(tesCaseWithDescriptionAndPassed.getStatus(), equalTo(passedStatus)); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...test/java/com/epam/reportportal/junit/features/callback/FailedDescriptionFeatureTest.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,45 @@ | ||
package com.epam.reportportal.junit.features.callback; | ||
|
||
import com.epam.reportportal.annotations.Step; | ||
import java.util.NoSuchElementException; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class FailedDescriptionFeatureTest { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(RetrieveByDescriptionFeatureTest.class); | ||
|
||
@Test | ||
public void testWithDescriptionAndException() { | ||
throw new RuntimeException("Test error message"); | ||
} | ||
|
||
@Test | ||
public void testWithDescriptionAndAssertException() { | ||
Assert.assertEquals(0, 1); | ||
} | ||
|
||
@Test | ||
public void testWithDescriptionAndStepError() { | ||
loginWithException(); | ||
Assert.assertTrue(true); | ||
} | ||
|
||
@Test | ||
public void testWithDescriptionAndPassed() { | ||
login(); | ||
Assert.assertTrue(true); | ||
} | ||
|
||
@Step | ||
public void login() { | ||
LOGGER.info("Login class method"); | ||
} | ||
|
||
@Step | ||
public void loginWithException() { | ||
throw new NoSuchElementException("Test error message"); | ||
} | ||
} |