|
1 | 1 | package com.github.invictum.reportportal;
|
2 | 2 |
|
3 |
| -import com.epam.reportportal.service.Launch; |
4 |
| -import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; |
5 |
| -import com.epam.ta.reportportal.ws.model.StartTestItemRQ; |
6 |
| -import com.github.invictum.reportportal.injector.IntegrationInjector; |
7 |
| -import com.google.inject.Inject; |
8 |
| -import io.reactivex.Maybe; |
| 3 | +import com.github.invictum.reportportal.handler.FlatHandler; |
| 4 | +import com.github.invictum.reportportal.handler.Handler; |
| 5 | +import com.github.invictum.reportportal.handler.HandlerType; |
| 6 | +import com.github.invictum.reportportal.handler.TreeHandler; |
9 | 7 | import net.thucydides.core.model.DataTable;
|
10 | 8 | import net.thucydides.core.model.Story;
|
11 | 9 | import net.thucydides.core.model.TestOutcome;
|
12 |
| -import net.thucydides.core.requirements.annotations.NarrativeFinder; |
13 | 10 | import net.thucydides.core.steps.ExecutedStepDescription;
|
14 | 11 | import net.thucydides.core.steps.StepFailure;
|
15 | 12 | import net.thucydides.core.steps.StepListener;
|
16 | 13 |
|
17 |
| -import java.time.Duration; |
18 |
| -import java.util.Calendar; |
19 |
| -import java.util.Date; |
20 | 14 | import java.util.Map;
|
21 | 15 |
|
22 | 16 | public class ReportPortalListener implements StepListener {
|
23 | 17 |
|
24 |
| - @Inject |
25 |
| - private Launch launch; |
26 |
| - |
27 |
| - @Inject |
28 |
| - private StepProcessorsHolder holder; |
29 |
| - |
30 |
| - @Inject |
31 |
| - private NarrativeFormatter narrativeFormatter; |
32 |
| - |
33 |
| - private Maybe<String> suiteId = null; |
34 |
| - private Maybe<String> testId = null; |
| 18 | + private Handler handler; |
35 | 19 |
|
36 | 20 | public ReportPortalListener() {
|
37 |
| - IntegrationInjector.getInjector().injectMembers(this); |
| 21 | + handler = (ReportIntegrationConfig.handlerType == HandlerType.FLAT) ? new FlatHandler() : new TreeHandler(); |
38 | 22 | }
|
39 | 23 |
|
40 | 24 | public void testSuiteStarted(Class<?> storyClass) {
|
41 |
| - if (suiteId == null) { |
42 |
| - StartTestItemRQ startSuite = new StartTestItemRQ(); |
43 |
| - startSuite.setType(ItemType.SUITE.key()); |
44 |
| - startSuite.setName(storyClass.getSimpleName()); |
45 |
| - startSuite.setStartTime(Calendar.getInstance().getTime()); |
46 |
| - /* Add narrative to description if present */ |
47 |
| - if (NarrativeFinder.forClass(storyClass).isPresent()) { |
48 |
| - String description = narrativeFormatter.format(NarrativeFinder.forClass(storyClass).get().text()); |
49 |
| - startSuite.setDescription(description); |
50 |
| - } |
51 |
| - suiteId = launch.startTestItem(startSuite); |
52 |
| - } |
| 25 | + handler.startSuite(storyClass); |
53 | 26 | }
|
54 | 27 |
|
55 | 28 | public void testSuiteStarted(Story story) {
|
56 |
| - if (suiteId == null) { |
57 |
| - StartTestItemRQ startSuite = new StartTestItemRQ(); |
58 |
| - startSuite.setType(ItemType.SUITE.key()); |
59 |
| - startSuite.setName(story.getDisplayName()); |
60 |
| - startSuite.setStartTime(Calendar.getInstance().getTime()); |
61 |
| - startSuite.setDescription(story.getNarrative()); |
62 |
| - suiteId = launch.startTestItem(startSuite); |
63 |
| - } |
| 29 | + handler.startSuite(story); |
64 | 30 | }
|
65 | 31 |
|
66 | 32 | public void testSuiteFinished() {
|
67 |
| - if (suiteId != null) { |
68 |
| - FinishTestItemRQ finishSuite = new FinishTestItemRQ(); |
69 |
| - finishSuite.setEndTime(Calendar.getInstance().getTime()); |
70 |
| - finishSuite.setStatus(Status.PASSED.toString()); |
71 |
| - launch.finishTestItem(suiteId, finishSuite); |
72 |
| - suiteId = null; |
73 |
| - } |
| 33 | + handler.finishSuite(); |
74 | 34 | }
|
75 | 35 |
|
76 | 36 | public void testStarted(String description) {
|
77 |
| - if (testId == null) { |
78 |
| - StartTestItemRQ startTest = new StartTestItemRQ(); |
79 |
| - startTest.setType(ItemType.TEST.key()); |
80 |
| - startTest.setName(description); |
81 |
| - startTest.setStartTime(Calendar.getInstance().getTime()); |
82 |
| - testId = launch.startTestItem(suiteId, startTest); |
83 |
| - } |
| 37 | + handler.startTest(description); |
84 | 38 | }
|
85 | 39 |
|
86 | 40 | public void testStarted(String description, String id) {
|
87 |
| - testStarted(description); |
| 41 | + handler.startTest(description); |
88 | 42 | }
|
89 | 43 |
|
90 | 44 | public void testFinished(TestOutcome result) {
|
91 |
| - if (testId != null) { |
92 |
| - /* Proceed all steps */ |
93 |
| - result.getFlattenedTestSteps().forEach(step -> holder.proceed(step)); |
94 |
| - /* Finish active test */ |
95 |
| - FinishTestItemRQ finishTest = new FinishTestItemRQ(); |
96 |
| - Date endDate = Date.from(result.getStartTime().plus(Duration.ofMillis(result.getDuration())).toInstant()); |
97 |
| - finishTest.setEndTime(endDate); |
98 |
| - finishTest.setStatus(Status.mapTo(result.getResult()).toString()); |
99 |
| - finishTest.setTags(Utils.refineTags(result)); |
100 |
| - launch.finishTestItem(testId, finishTest); |
101 |
| - testId = null; |
102 |
| - } |
| 45 | + handler.finishTest(result); |
103 | 46 | }
|
104 | 47 |
|
105 | 48 | public void testRetried() {
|
|
0 commit comments