|
17 | 17 |
|
18 | 18 | import io.qameta.allure.http.HttpExchange; |
19 | 19 | import io.qameta.allure.http.HttpExchangeSerializer; |
20 | | -import io.qameta.allure.listener.LifecycleNotifier; |
21 | 20 | import io.qameta.allure.model.Label; |
22 | 21 | import io.qameta.allure.model.Link; |
23 | 22 | import io.qameta.allure.model.Parameter; |
|
47 | 46 | /** |
48 | 47 | * The class contains some useful methods to work with {@link AllureLifecycle}. |
49 | 48 | */ |
50 | | -@SuppressWarnings({"PMD.TooManyMethods", "PMD.GodClass"}) |
| 49 | +@SuppressWarnings("PMD.TooManyMethods") |
51 | 50 | public final class Allure { |
52 | 51 |
|
53 | 52 | private static final String TEXT_PLAIN = "text/plain"; |
@@ -98,8 +97,7 @@ public static void step(final String name) { |
98 | 97 | * @param status the step status. |
99 | 98 | */ |
100 | 99 | public static void step(final String name, final Status status) { |
101 | | - getLifecycle().startStep(new StepResult().setName(name).setStatus(status)); |
102 | | - getLifecycle().stopStep(); |
| 100 | + getLifecycle().logStep(new StepResult().setName(name).setStatus(status)); |
103 | 101 | } |
104 | 102 |
|
105 | 103 | /** |
@@ -479,31 +477,7 @@ public static CompletableFuture<Void> attachmentAsync( |
479 | 477 | final String name, final String type, |
480 | 478 | final CompletionStage<? extends InputStream> body, |
481 | 479 | final AttachmentOptions options) { |
482 | | - final AllureLifecycle lifecycle = getLifecycle(); |
483 | | - if (isDirectAttachmentWrite()) { |
484 | | - return lifecycle.addAttachmentAsync(name, type, body, options); |
485 | | - } |
486 | | - |
487 | | - final StepResult step = new StepResult() |
488 | | - .setName(attachmentStepName(name)) |
489 | | - .setStatus(Status.PASSED); |
490 | | - lifecycle.startStep(step); |
491 | | - try { |
492 | | - // the status update runs inside the tracked future, so a failed async attachment is |
493 | | - // guaranteed to mark the step before the owning test result is written |
494 | | - return lifecycle.addAttachmentAsync(name, type, body, options, (result, throwable) -> { |
495 | | - if (Objects.nonNull(throwable)) { |
496 | | - step.setStatus(getStatus(throwable).orElse(Status.BROKEN)) |
497 | | - .setStatusDetails(getStatusDetails(throwable).orElse(null)); |
498 | | - } |
499 | | - }); |
500 | | - } catch (Throwable throwable) { |
501 | | - step.setStatus(getStatus(throwable).orElse(Status.BROKEN)) |
502 | | - .setStatusDetails(getStatusDetails(throwable).orElse(null)); |
503 | | - throw ExceptionUtils.sneakyThrow(throwable); |
504 | | - } finally { |
505 | | - lifecycle.stopStep(); |
506 | | - } |
| 480 | + return getLifecycle().addAttachmentStepAsync(name, type, body, options); |
507 | 481 | } |
508 | 482 |
|
509 | 483 | /** |
@@ -538,41 +512,7 @@ private static void addAttachmentAsStep(final String name, final String type, |
538 | 512 |
|
539 | 513 | private static void addAttachmentAsStep(final String name, final String type, |
540 | 514 | final InputStream content, final AttachmentOptions options) { |
541 | | - final AllureLifecycle lifecycle = getLifecycle(); |
542 | | - if (isDirectAttachmentWrite()) { |
543 | | - addAttachmentDirect(lifecycle, name, type, content, options); |
544 | | - return; |
545 | | - } |
546 | | - |
547 | | - lifecycle.startStep(new StepResult().setName(attachmentStepName(name))); |
548 | | - try { |
549 | | - lifecycle.addAttachment(name, type, content, options); |
550 | | - lifecycle.updateStep(step -> step.setStatus(Status.PASSED)); |
551 | | - } catch (Throwable throwable) { |
552 | | - lifecycle.updateStep( |
553 | | - step -> step |
554 | | - .setStatus(getStatus(throwable).orElse(Status.BROKEN)) |
555 | | - .setStatusDetails(getStatusDetails(throwable).orElse(null)) |
556 | | - ); |
557 | | - throw ExceptionUtils.sneakyThrow(throwable); |
558 | | - } finally { |
559 | | - lifecycle.stopStep(); |
560 | | - } |
561 | | - } |
562 | | - |
563 | | - private static void addAttachmentDirect(final AllureLifecycle lifecycle, |
564 | | - final String name, final String type, |
565 | | - final InputStream content, final AttachmentOptions options) { |
566 | | - lifecycle.addAttachment(name, type, content, options); |
567 | | - } |
568 | | - |
569 | | - private static boolean isDirectAttachmentWrite() { |
570 | | - return LifecycleNotifier.isListenerCallbackRunning() |
571 | | - || getLifecycle().getCurrentExecutableKey().isEmpty(); |
572 | | - } |
573 | | - |
574 | | - private static String attachmentStepName(final String name) { |
575 | | - return Objects.isNull(name) || name.isEmpty() ? "Attachment" : name; |
| 515 | + getLifecycle().addAttachmentStep(name, type, content, options); |
576 | 516 | } |
577 | 517 |
|
578 | 518 | /** |
|
0 commit comments