private Optional<ru.yandex.qatools.allure.model.Label> findLabel( final List<ru.yandex.qatools.allure.model.Label> labels, final String labelName) { return labels.stream() .filter(label -> labelName.equals(label.getName())) .findAny(); }
final Properties properties) { final TestResult dest = new TestResult(); final String suiteName = firstNonNull(testSuite.getTitle(), testSuite.getName(), "unknown test suite"); final String testClass = firstNonNull( findLabelValue(source.getLabels(), TEST_CLASS.value()), findLabelValue(testSuite.getLabels(), TEST_CLASS.value()), testSuite.getName(), UNKNOWN ); final String testMethod = firstNonNull( findLabelValue(source.getLabels(), TEST_METHOD.value()), source.getName(), UNKNOWN ); final String name = firstNonNull(source.getTitle(), source.getName(), "unknown test case"); final Optional<ru.yandex.qatools.allure.model.Label> historyId = findLabel(source.getLabels(), "historyId"); if (historyId.isPresent()) { dest.setHistoryId(historyId.get().getValue()); } else { dest.setHistoryId(getHistoryId(String.format("%s#%s", testClass, name), parameters)); final Status status = convert(source.getStatus()); dest.setStatus(status); dest.setTime(Time.create(source.getStart(), source.getStop())); dest.setParameters(parameters); dest.setDescription(getDescription(testSuite.getDescription(), source.getDescription())); dest.setDescriptionHtml(getDescriptionHtml(testSuite.getDescription(), source.getDescription())); Optional.ofNullable(source.getFailure()).ifPresent(failure -> {
private Step convert(final Path source, final ResultsVisitor visitor, final ru.yandex.qatools.allure.model.Step s, final Status testStatus, final String message, final String trace) { final Status status = convert(s.getStatus()); final Step current = new Step() .setName(s.getTitle() == null ? s.getName() : s.getTitle()) .setTime(new Time() .setStart(s.getStart()) .setStop(s.getStop()) .setDuration(s.getStop() - s.getStart())) .setStatus(status) .setSteps(convert(s.getSteps(), step -> convert(source, visitor, step, testStatus, message, trace))) .setAttachments(convert(s.getAttachments(), attach -> convert(source, visitor, attach))); //Copy test status details to each step set the same status if (Objects.equals(status, testStatus)) { current.setStatusMessage(message); current.setStatusMessage(trace); } return current; }
@Override public void readResults(final Configuration configuration, final ResultsVisitor visitor, final Path resultsDirectory) { final Properties allureProperties = loadAllureProperties(resultsDirectory); final RandomUidContext context = configuration.requireContext(RandomUidContext.class); final Map<String, String> environment = processEnvironment(resultsDirectory); getStreamOfAllure1Results(resultsDirectory).forEach(testSuite -> testSuite.getTestCases() .forEach(testCase -> { convert(context.getValue(), resultsDirectory, visitor, testSuite, testCase, allureProperties); getEnvironmentParameters(testCase).forEach(param -> environment.put(param.getName(), param.getValue()) ); }) ); visitor.visitExtra(ENVIRONMENT_BLOCK_NAME, environment); }
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); } }
private List<ru.yandex.qatools.allure.model.Parameter> getEnvironmentParameters(final TestCaseResult testCase) { return testCase.getParameters().stream().filter(this::hasEnvType).collect(toList()); }
/** * Create an instance of {@link Attachment } * */ public Attachment createAttachment() { return new Attachment(); }
/** * Create an instance of {@link Step } * */ public Step createStep() { return new Step(); }
/** * Create an instance of {@link TestCaseResult } * */ public TestCaseResult createTestCaseResult() { return new TestCaseResult(); }
/** * Create an instance of {@link Parameter } * */ public Parameter createParameter() { return new Parameter(); }
/** * Create an instance of {@link Label } * */ public Label createLabel() { return new Label(); }
private List<Parameter> getParameters(final TestCaseResult source) { final TreeSet<Parameter> parametersSet = new TreeSet<>( comparing(Parameter::getName, nullsFirst(naturalOrder())) .thenComparing(Parameter::getValue, nullsFirst(naturalOrder())) ); parametersSet.addAll(convert(source.getParameters(), this::hasArgumentType, this::convert)); return new ArrayList<>(parametersSet); }
private String findLabelValue(final List<ru.yandex.qatools.allure.model.Label> labels, final String labelName) { return labels.stream() .filter(label -> labelName.equals(label.getName())) .map(ru.yandex.qatools.allure.model.Label::getValue) .findAny() .orElse(null); }