public <T> T findAllLabels(final String name, final Collector<String, ?, T> collector) { return getLabels().stream() .filter(label -> name.equals(label.getName())) .map(Label::getValue) .collect(collector); }
public void addLabelIfNotExists(final String name, final String value) { if (value == null || name == null) { return; } final Optional<String> any = getLabels().stream() .map(Label::getName) .filter(name::equals) .findAny(); if (!any.isPresent()) { addLabel(name, value); } }
public Optional<String> findOneLabel(final String name) { return getLabels().stream() .filter(label -> name.equals(label.getName())) .findAny() .map(Label::getValue); }
public Map<String, String> toMap() { final Map<String, String> map = new HashMap<String, String>(); for (Label l : getLabels()) { map.put(l.getName(), l.getValue()); } return map; } }
private static String getLabelValuesAsString(final List<LaunchResults> launchesResults, final LabelName labelName) { final String values = launchesResults.stream() .flatMap(results -> results.getResults().stream()) .flatMap(result -> result.getLabels().stream()) .filter(label -> labelName.value().equals(label.getName())) .map(Label::getValue) .distinct() .sorted() .collect(Collectors.joining(" ")) .toLowerCase(); return values.isEmpty() ? UNDEFINED : values; }
private void addIdeaLink(final TestResult testResult) { final String fileExtension = "java"; final String port = getProperty(ALLURE_IDEA_PORT).orElse("63342"); final Optional<String> testClassName = testResult.getLabels().stream() .filter(label -> "testClass".equals(label.getName())) .map(Label::getValue) .findFirst(); testClassName.ifPresent(name -> { final String path = name.replace(".", "/"); final String url = String.format("http://localhost:%s/api/file?file=%s.%s", port, path, fileExtension); testResult.getLinks().add(new Link().setName(IDEA_LINK_NAME).setType(IDEA_LINK_TYPE).setUrl(url)); }); }
public void addLabel(final String name, final String value) { getLabels().add(new Label().setName(name).setValue(value)); }
@Test public void shouldFindAllWithNullValue() throws Exception { final TestResult result = new TestResult(); result.getLabels().add(new Label().setName("hey").setValue(null)); result.getLabels().add(new Label().setName("hey").setValue("a")); result.getLabels().add(new Label().setName("hey").setValue("b")); final List<String> found = result.findAllLabels("hey"); assertThat(found) .containsExactlyInAnyOrder(null, "a", "b"); } }
@Test public void shouldFindOneWithNullValue() throws Exception { final TestResult result = new TestResult(); result.getLabels().add(new Label().setName("hey").setValue(null)); final Optional<String> found = result.findOneLabel("hey"); assertThat(found) .isEmpty(); }
public Optional<String> findOneLabel(final String name) { return getLabels().stream() .filter(label -> name.equals(label.getName())) .findAny() .map(Label::getValue); }
public <T> T findAllLabels(final String name, final Collector<String, ?, T> collector) { return getLabels().stream() .filter(label -> name.equals(label.getName())) .map(Label::getValue) .collect(collector); }
public void addLabelIfNotExists(final String name, final String value) { if (value == null || name == null) { return; } final Optional<String> any = getLabels().stream() .map(Label::getName) .filter(name::equals) .findAny(); if (!any.isPresent()) { addLabel(name, value); } }
private static String getLabelValuesAsString(final List<LaunchResults> launchesResults, final LabelName labelName) { final String values = launchesResults.stream() .flatMap(results -> results.getResults().stream()) .flatMap(result -> result.getLabels().stream()) .filter(label -> labelName.value().equals(label.getName())) .map(Label::getValue) .distinct() .sorted() .collect(Collectors.joining(" ")) .toLowerCase(); return values.isEmpty() ? UNDEFINED : values; }
public Map<String, String> toMap() { final Map<String, String> map = new HashMap<String, String>(); for (Label l : getLabels()) { map.put(l.getName(), l.getValue()); } return map; } }
private void addIdeaLink(final TestResult testResult) { final String fileExtension = "java"; final String port = getProperty(ALLURE_IDEA_PORT).orElse("63342"); final Optional<String> testClassName = testResult.getLabels().stream() .filter(label -> "testClass".equals(label.getName())) .map(Label::getValue) .findFirst(); testClassName.ifPresent(name -> { final String path = name.replace(".", "/"); final String url = String.format("http://localhost:%s/api/file?file=%s.%s", port, path, fileExtension); testResult.getLinks().add(new Link().setName(IDEA_LINK_NAME).setType(IDEA_LINK_TYPE).setUrl(url)); }); }
public void addLabel(final String name, final String value) { getLabels().add(new Label().setName(name).setValue(value)); }