Загрузка данных



public class ScreenshotAttachmentEntry extends FileAttachmentEntry<Screenshot> {
  protected ScreenshotAttachmentEntry(String name, Screenshot content) {
    super(name, content);
  }

  public static ScreenshotAttachmentEntry of(@NotNull String name, @NotNull Screenshot content) {
    return new ScreenshotAttachmentEntry(name, content);
  }

  public String getDescription() {
    return "No text description for screenshot";
  }

  public @NotNull String getFileExtension() {
    return ((Screenshot)this.getContent().orElseThrow(() -> EmptyAttachment.exception(UtilsMessages.EMPTY_ATTACHMENT_ENTRY.getMessage(new Object[0])))).getFileExtension();
  }
}


public class AllureAttachmentProcessor implements AttachmentProcessor {
  public String processAttachment(@NotNull Attachment attachment) {
    attachment.getAttachmentEntries().filter((entry) -> entry instanceof FileAttachmentEntry).forEach((entry) -> {
      FileAttachmentEntry<?> fileAttachmentEntry = (FileAttachmentEntry)entry;
      String fileExtension = fileAttachmentEntry.getFileExtension();
      String var10000 = entry.getName();
      String fileName = var10000 + "." + fileExtension;
      if (fileAttachmentEntry instanceof HtmlAttachmentEntry) {
        String content = (String)((HtmlAttachmentEntry)fileAttachmentEntry).getContent().orElse("");
        Allure.addAttachment(fileName, "text/html", content, fileExtension);
      } else if (fileAttachmentEntry instanceof JsonAttachmentEntry) {
        String content = ((JsonNode)((JsonAttachmentEntry)fileAttachmentEntry).getContent().orElse(JsonUtils.createObjectNode())).toPrettyString();
        Allure.addAttachment(fileName, "application/json", content, fileExtension);
      } else if (fileAttachmentEntry instanceof ScreenshotAttachmentEntry) {
        Screenshot screenshot = (Screenshot)((ScreenshotAttachmentEntry)entry).getContent().orElseThrow(() -> EmptyAttachment.exception(UtilsMessages.EMPTY_ATTACHMENT_ENTRY.getMessage(new Object[0])));
        Allure.addAttachment(fileName, screenshot.getMimeType(), new ByteArrayInputStream(screenshot.getRaw()), screenshot.getFileExtension());
      } else if (fileAttachmentEntry instanceof BigTextAttachmentEntry) {
        String content = (String)((BigTextAttachmentEntry)fileAttachmentEntry).getContent().orElse("");
        Allure.addAttachment(fileName, "text/plain", content, fileExtension);
      }

    });
    attachment.getAttachmentEntries().filter((entry) -> entry instanceof TextAttachmentEntry).forEach((entry) -> Allure.addAttachment(entry.getName(), "text/plain", entry.getDescription()));
    return "";
  }
}