Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -90,6 +91,9 @@
})
public class AllureJunitPlatform implements TestExecutionListener {

public static final String ALLURE_REPORT_ENTRY_BLANK_PREFIX
= "ALLURE_REPORT_ENTRY_BLANK_PREFIX__";

public static final String ALLURE_PARAMETER = "allure.parameter";
public static final String ALLURE_PARAMETER_VALUE_KEY = "value";
public static final String ALLURE_PARAMETER_MODE_KEY = "mode";
Expand Down Expand Up @@ -195,11 +199,11 @@ public void executionSkipped(final TestIdentifier testIdentifier,
);
}

@SuppressWarnings({"ReturnCount", "PMD.NcssCount", "CyclomaticComplexity"})
@SuppressWarnings({"ReturnCount", "PMD.NcssCount", "CyclomaticComplexity" })
@Override
public void reportingEntryPublished(final TestIdentifier testIdentifier,
final ReportEntry entry) {
final Map<String, String> keyValuePairs = entry.getKeyValuePairs();
final Map<String, String> keyValuePairs = unwrap(entry.getKeyValuePairs());
if (keyValuePairs.containsKey(ALLURE_FIXTURE)) {
processFixtureEvent(testIdentifier, keyValuePairs);
return;
Expand All @@ -220,11 +224,33 @@ public void reportingEntryPublished(final TestIdentifier testIdentifier,

}

private Map<String, String> unwrap(final Map<String, String> data) {
final Map<String, String> res = new HashMap<>();
data.forEach((key, value) -> {
if (Objects.nonNull(value)
&& value.trim().isEmpty()
&& value.startsWith(ALLURE_REPORT_ENTRY_BLANK_PREFIX)) {
res.put(key, value.substring(ALLURE_REPORT_ENTRY_BLANK_PREFIX.length()));
} else {
res.put(key, value);
}
}
);
return res;
}

private void processParameterEvent(final Map<String, String> keyValuePairs) {
final String name = keyValuePairs.get(ALLURE_PARAMETER);
final String value = keyValuePairs.get(ALLURE_PARAMETER_VALUE_KEY);

final Parameter parameter = ResultsUtils.createParameter(name, value);
final Parameter parameter;
if (Objects.nonNull(value) && value.startsWith(ALLURE_REPORT_ENTRY_BLANK_PREFIX)) {
parameter = ResultsUtils.createParameter(
name,
value.substring(ALLURE_REPORT_ENTRY_BLANK_PREFIX.length())
);
} else {
parameter = ResultsUtils.createParameter(name, value);
}
if (keyValuePairs.containsKey(ALLURE_PARAMETER_MODE_KEY)) {
final String modeString = keyValuePairs.get(ALLURE_PARAMETER_MODE_KEY);
Stream.of(Parameter.Mode.values())
Expand All @@ -244,7 +270,7 @@ private void processParameterEvent(final Map<String, String> keyValuePairs) {
);
}

@SuppressWarnings({"ReturnCount"})
@SuppressWarnings({"ReturnCount" })
private void processFixtureEvent(final TestIdentifier testIdentifier,
final Map<String, String> keyValuePairs) {
final String type = keyValuePairs.get(ALLURE_FIXTURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.lang.reflect.Parameter;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;
Expand All @@ -37,6 +38,7 @@
import static io.qameta.allure.junitplatform.AllureJunitPlatform.ALLURE_PARAMETER_EXCLUDED_KEY;
import static io.qameta.allure.junitplatform.AllureJunitPlatform.ALLURE_PARAMETER_MODE_KEY;
import static io.qameta.allure.junitplatform.AllureJunitPlatform.ALLURE_PARAMETER_VALUE_KEY;
import static io.qameta.allure.junitplatform.AllureJunitPlatform.ALLURE_REPORT_ENTRY_BLANK_PREFIX;
import static io.qameta.allure.junitplatform.AllureJunitPlatform.EVENT_FAILURE;
import static io.qameta.allure.junitplatform.AllureJunitPlatform.EVENT_START;
import static io.qameta.allure.junitplatform.AllureJunitPlatform.EVENT_STOP;
Expand Down Expand Up @@ -86,7 +88,7 @@ private void sendParameterEvent(final ReflectiveInvocationContext<Method> invoca
map.put(ALLURE_PARAMETER_EXCLUDED_KEY, Boolean.toString(param.excluded()));
});

extensionContext.publishReportEntry(map);
extensionContext.publishReportEntry(wrap(map));
}
}

Expand Down Expand Up @@ -128,22 +130,22 @@ protected void processFixture(final String type,
final ExtensionContext extensionContext) throws Throwable {
final String uuid = UUID.randomUUID().toString();
try {
extensionContext.publishReportEntry(buildStartEvent(
extensionContext.publishReportEntry(wrap(buildStartEvent(
type,
uuid,
invocationContext.getExecutable()
));
)));
invocation.proceed();
extensionContext.publishReportEntry(buildStopEvent(
extensionContext.publishReportEntry(wrap(buildStopEvent(
type,
uuid
));
)));
} catch (Throwable throwable) {
extensionContext.publishReportEntry(buildFailureEvent(
extensionContext.publishReportEntry(wrap(buildFailureEvent(
type,
uuid,
throwable
));
)));
throw throwable;
}
}
Expand Down Expand Up @@ -184,4 +186,17 @@ public Map<String, String> buildFailureEvent(final String type,
maybeDetails.map(StatusDetails::getTrace).ifPresent(trace -> map.put("trace", trace));
return map;
}

public Map<String, String> wrap(final Map<String, String> data) {
final Map<String, String> res = new HashMap<>();
data.forEach((key, value) -> {
if (Objects.isNull(value) || value.trim().isEmpty()) {
res.put(key, ALLURE_REPORT_ENTRY_BLANK_PREFIX + value);
} else {
res.put(key, value);
}
}
);
return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

import io.qameta.allure.Allure;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.Issue;
import io.qameta.allure.Step;
import io.qameta.allure.aspects.AttachmentsAspects;
import io.qameta.allure.aspects.StepsAspects;
import io.qameta.allure.junit5.features.AfterEachFixtureFailureSupport;
import io.qameta.allure.junit5.features.AllFixtureSupport;
import io.qameta.allure.junit5.features.BeforeEachFixtureFailureSupport;
import io.qameta.allure.junit5.features.EachFixtureSupport;
import io.qameta.allure.junit5.features.ParameterisedBlankParameterValueTests;
import io.qameta.allure.junit5.features.ParameterisedPrimitivesTests;
import io.qameta.allure.junit5.features.ParameterisedTests;
import io.qameta.allure.junit5.features.SkipOtherInjectables;
Expand Down Expand Up @@ -57,6 +59,20 @@
@AllureFeatures.Fixtures
class AllureJunit5Test {

@Issue("697")
@Test
void shouldSupportEmptyStringParameters() {
final AllureResults results = runClasses(ParameterisedBlankParameterValueTests.class);

assertThat(results.getTestResults())
.extracting(TestResult::getName, tr -> tr.getParameters().size())
.containsExactlyInAnyOrder(
tuple("first(String) [1] value=", 2),
tuple("first(String) [2] value= ", 2),
tuple("first(String) [3] value=null", 2)
);
}

@Test
void shouldSupportPrimitiveTypeParameters() {
final AllureResults results = runClasses(ParameterisedPrimitivesTests.class);
Expand All @@ -82,7 +98,7 @@ void shouldSupportPrimitiveTypeParameters() {
tuple("chars(char) [3] value=c", 2),
tuple("longs(long) [1] value=0", 2),
tuple("longs(long) [2] value=1", 2),
tuple("nullMethodSource(String) [1] value=null", 2),
tuple("nullMethodSource(String, Long) [1] stringValue=null, longValue=null", 3),
tuple("doubles(double) [1] value=0.1", 2),
tuple("doubles(double) [2] value=0.01", 2),
tuple("booleans(boolean) [1] value=true", 2),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2019 Qameta Software OÜ
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.qameta.allure.junit5.features;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.stream.Stream;

/**
* @author charlie (Dmitry Baev).
*/
public class ParameterisedBlankParameterValueTests {

@ParameterizedTest
@MethodSource("arguments")
void first(String value) {
}

static Stream<String> arguments() {
return Stream.of(
"",
" ",
null
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ void booleansMethodSource(final boolean a, final boolean b) {

@ParameterizedTest
@MethodSource("nulls")
void nullMethodSource(final String value) {
void nullMethodSource(final String stringValue,
final Long longValue) {
}

static Stream<Arguments> arguments() {
Expand All @@ -88,7 +89,7 @@ static Stream<Arguments> arguments() {

static Stream<Arguments> nulls() {
return Stream.of(
Arguments.of((String) null)
Arguments.of(null, null)
);
}

Expand Down
1 change: 1 addition & 0 deletions allure-junit5/src/test/resources/allure.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
allure.results.directory=build/allure-results
allure.label.epic=#project.description#
allure.link.issue.pattern=https://github.com/allure-framework/allure-java/issues/{}