private Attachment convert(final Path source, final ResultsVisitor visitor, final ru.yandex.qatools.allure.model.Attachment attachment) { final Path attachmentFile = source.resolve(attachment.getSource()); if (Files.isRegularFile(attachmentFile)) { final Attachment found = visitor.visitAttachmentFile(attachmentFile); if (Objects.nonNull(attachment.getType())) { found.setType(attachment.getType()); } if (Objects.nonNull(attachment.getTitle())) { found.setName(attachment.getTitle()); } return found; } else { visitor.error("Could not find attachment " + attachment.getSource() + " in directory " + source); return new Attachment() .setType(attachment.getType()) .setName(attachment.getTitle()) .setSize(0L); } }
/** * Create an instance of {@link Attachment } * */ public Attachment createAttachment() { return new Attachment(); }
public Attachment withSource(String value) { setSource(value); return this; }
lhsTitle = this.getTitle(); String rhsTitle; rhsTitle = that.getTitle(); if (!strategy.equals(LocatorUtils.property(thisLocator, "title", lhsTitle), LocatorUtils.property(thatLocator, "title", rhsTitle), lhsTitle, rhsTitle)) { return false; lhsSource = this.getSource(); String rhsSource; rhsSource = that.getSource(); if (!strategy.equals(LocatorUtils.property(thisLocator, "source", lhsSource), LocatorUtils.property(thatLocator, "source", rhsSource), lhsSource, rhsSource)) { return false; lhsType = this.getType(); String rhsType; rhsType = that.getType(); if (!strategy.equals(LocatorUtils.property(thisLocator, "type", lhsType), LocatorUtils.property(thatLocator, "type", rhsType), lhsType, rhsType)) { return false; lhsSize = this.getSize(); Integer rhsSize; rhsSize = that.getSize(); if (!strategy.equals(LocatorUtils.property(thisLocator, "size", lhsSize), LocatorUtils.property(thatLocator, "size", rhsSize), lhsSize, rhsSize)) { return false;
/** * Remove attachment form {@link #resultsDirectory} * * @param attachment to remove * @return true, if attachment removed successfully, false otherwise */ public static boolean deleteAttachment(Attachment attachment) { File attachmentFile = new File(getResultsDirectory(), attachment.getSource()); return attachmentFile.exists() && attachmentFile.canWrite() && attachmentFile.delete(); }
@Override public void process(Step step) { Attachment attachment = new Attachment(); String source = writeAttachment( getAttach(), getAttachmentType() ); attachment.setTitle(getTitle()); attachment.setType(getAttachmentType()); attachment.setSource(source); step.getAttachments().add(attachment); }
/** * Write attachment with specified type. Generate attachment name uses * {@link #generateAttachmentName()}, attachment extension uses * {@link #getExtensionByMimeType(String)} * * @param attachment byte array with attachment * @param title attachment title * @param type valid mime-type of attachment * @return Created {@link ru.yandex.qatools.allure.model.Attachment} * @throws IOException if can't write attachment */ public static Attachment writeAttachment(byte[] attachment, String title, String type) throws IOException { String name = generateAttachmentName(); String extension = getExtensionByMimeType(type); String source = name + extension; File file = new File(getResultsDirectory(), source); synchronized (ATTACHMENTS_LOCK) { if (!file.exists()) { try (FileOutputStream fos = new FileOutputStream(file)) { fos.write(attachment); } } } return new Attachment().withTitle(title).withSource(source).withType(type); }
public Attachment withTitle(String value) { setTitle(value); return this; }
public Attachment withType(String value) { setType(value); return this; }
public int hashCode(ObjectLocator locator, HashCodeStrategy strategy) { int currentHashCode = 1; { String theTitle; theTitle = this.getTitle(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "title", theTitle), currentHashCode, theTitle); } { String theSource; theSource = this.getSource(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "source", theSource), currentHashCode, theSource); } { String theType; theType = this.getType(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "type", theType), currentHashCode, theType); } { Integer theSize; theSize = this.getSize(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "size", theSize), currentHashCode, theSize); } return currentHashCode; }
public static boolean deleteAttachment(Attachment attachment) { File attachmentFile = new File(getResultsDirectory(), attachment.getSource()); return attachmentFile.exists() && attachmentFile.canWrite() && attachmentFile.delete(); }
private Attachment convert(final Path source, final ResultsVisitor visitor, final ru.yandex.qatools.allure.model.Attachment attachment) { final Path attachmentFile = source.resolve(attachment.getSource()); if (Files.isRegularFile(attachmentFile)) { final Attachment found = visitor.visitAttachmentFile(attachmentFile); if (Objects.nonNull(attachment.getType())) { found.setType(attachment.getType()); } if (Objects.nonNull(attachment.getTitle())) { found.setName(attachment.getTitle()); } return found; } else { visitor.error("Could not find attachment " + attachment.getSource() + " in directory " + source); return new Attachment() .setType(attachment.getType()) .setName(attachment.getTitle()) .setSize(0L); } }
@Override public void process(Step context) { Iterator<Attachment> iterator = context.getAttachments().listIterator(); while (iterator.hasNext()) { Attachment attachment = iterator.next(); if (pattern.matcher(attachment.getSource()).matches()) { deleteAttachment(attachment); iterator.remove(); } } for (Step step : context.getSteps()) { process(step); } } }
/** * Write throwable as attachment. * * @param throwable to write * @param title title of attachment * @return Created {@link ru.yandex.qatools.allure.model.Attachment} */ public static Attachment writeAttachmentWithErrorMessage(Throwable throwable, String title) { String message = throwable.getMessage(); try { return writeAttachment(message.getBytes(CONFIG.getAttachmentsEncoding()), title); } catch (Exception e) { e.addSuppressed(throwable); LOGGER.error(String.format("Can't write attachment \"%s\"", title), e); } return new Attachment(); }
/** * Remove attachments matches pattern from step and all step substeps * * @param context from which attachments will be removed */ @Override public void process(Step context) { Iterator<Attachment> iterator = context.getAttachments().listIterator(); while (iterator.hasNext()) { Attachment attachment = iterator.next(); if (pattern.matcher(attachment.getSource()).matches()) { deleteAttachment(attachment); iterator.remove(); } } for (Step step : context.getSteps()) { process(step); } } }