Skip to content

Commit

Permalink
add parameter builder util method (fixes allure-framework#306, via al…
Browse files Browse the repository at this point in the history
  • Loading branch information
baev authored Feb 12, 2019
1 parent 51f256c commit 09257f6
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 34,6 @@
import io.qameta.allure.model.StatusDetails;
import io.qameta.allure.model.StepResult;
import io.qameta.allure.model.TestResult;
import io.qameta.allure.util.ObjectUtils;
import io.qameta.allure.util.ResultsUtils;

import java.lang.annotation.Annotation;
Expand All @@ -57,6 56,7 @@
import static io.qameta.allure.util.ResultsUtils.createFrameworkLabel;
import static io.qameta.allure.util.ResultsUtils.createHostLabel;
import static io.qameta.allure.util.ResultsUtils.createLanguageLabel;
import static io.qameta.allure.util.ResultsUtils.createParameter;
import static io.qameta.allure.util.ResultsUtils.createSuiteLabel;
import static io.qameta.allure.util.ResultsUtils.createThreadLabel;
import static io.qameta.allure.util.ResultsUtils.getProvidedLabels;
Expand Down Expand Up @@ -204,10 204,7 @@ private void stopTestCase(final TestCase testCase,
final String uuid = removeUuid(testCase);
final Map<String, Object> definitions = testCase.getVariableDefinitions();
final List<Parameter> parameters = definitions.entrySet().stream()
.map(entry -> new Parameter()
.setName(entry.getKey())
.setValue(ObjectUtils.toString(entry.getValue()))
)
.map(entry -> createParameter(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());

getLifecycle().updateTestCase(uuid, result -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 38,15 @@
import gherkin.pickles.PickleRow;
import gherkin.pickles.PickleTable;
import gherkin.pickles.PickleTag;

import io.qameta.allure.Allure;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.model.FixtureResult;
import io.qameta.allure.model.Parameter;
import io.qameta.allure.model.Status;
import io.qameta.allure.model.StatusDetails;
import io.qameta.allure.model.StepResult;
import io.qameta.allure.model.TestResult;
import io.qameta.allure.model.TestResultContainer;
import io.qameta.allure.model.FixtureResult;

import java.io.ByteArrayInputStream;
import java.nio.charset.Charset;
Expand All @@ -61,6 60,7 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static io.qameta.allure.util.ResultsUtils.createParameter;
import static io.qameta.allure.util.ResultsUtils.getStatus;
import static io.qameta.allure.util.ResultsUtils.getStatusDetails;
import static io.qameta.allure.util.ResultsUtils.md5;
Expand Down Expand Up @@ -273,7 273,7 @@ private List<Parameter> getExamplesAsParameters(final ScenarioOutline scenarioOu
return IntStream.range(0, examples.getTableHeader().getCells().size()).mapToObj(index -> {
final String name = examples.getTableHeader().getCells().get(index).getValue();
final String value = row.getCells().get(index).getValue();
return new Parameter().setName(name).setValue(value);
return createParameter(name, value);
}).collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 29,6 @@
import cucumber.api.event.TestStepFinished;
import cucumber.api.event.TestStepStarted;
import cucumber.api.formatter.Formatter;

import gherkin.ast.Examples;
import gherkin.ast.Feature;
import gherkin.ast.ScenarioDefinition;
Expand All @@ -41,12 40,12 @@
import gherkin.pickles.PickleTag;
import io.qameta.allure.Allure;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.model.FixtureResult;
import io.qameta.allure.model.Parameter;
import io.qameta.allure.model.Status;
import io.qameta.allure.model.StatusDetails;
import io.qameta.allure.model.StepResult;
import io.qameta.allure.model.TestResult;
import io.qameta.allure.model.FixtureResult;
import io.qameta.allure.model.TestResultContainer;

import java.io.ByteArrayInputStream;
Expand All @@ -62,6 61,7 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static io.qameta.allure.util.ResultsUtils.createParameter;
import static io.qameta.allure.util.ResultsUtils.getStatus;
import static io.qameta.allure.util.ResultsUtils.getStatusDetails;
import static io.qameta.allure.util.ResultsUtils.md5;
Expand Down Expand Up @@ -281,7 281,7 @@ private List<Parameter> getExamplesAsParameters(final ScenarioOutline scenarioOu
return IntStream.range(0, examplesBlock.get().getTableHeader().getCells().size()).mapToObj(index -> {
final String name = examplesBlock.get().getTableHeader().getCells().get(index).getValue();
final String value = row.getCells().get(index).getValue();
return new Parameter().setName(name).setValue(value);
return createParameter(name, value);
}).collect(Collectors.toList());
} else {
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,6 @@
import cucumber.api.PickleStepTestStep;
import cucumber.api.Result;
import cucumber.api.TestCase;

import cucumber.api.event.ConcurrentEventListener;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventPublisher;
Expand All @@ -30,7 29,6 @@
import cucumber.api.event.TestSourceRead;
import cucumber.api.event.TestStepFinished;
import cucumber.api.event.TestStepStarted;

import cucumber.runtime.formatter.TestSourcesModelProxy;
import gherkin.ast.Examples;
import gherkin.ast.Feature;
Expand All @@ -43,13 41,13 @@
import gherkin.pickles.PickleTag;
import io.qameta.allure.Allure;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.model.FixtureResult;
import io.qameta.allure.model.Parameter;
import io.qameta.allure.model.Status;
import io.qameta.allure.model.StatusDetails;
import io.qameta.allure.model.StepResult;
import io.qameta.allure.model.TestResult;
import io.qameta.allure.model.TestResultContainer;
import io.qameta.allure.model.FixtureResult;

import java.io.ByteArrayInputStream;
import java.nio.charset.Charset;
Expand All @@ -63,6 61,7 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static io.qameta.allure.util.ResultsUtils.createParameter;
import static io.qameta.allure.util.ResultsUtils.getStatus;
import static io.qameta.allure.util.ResultsUtils.getStatusDetails;
import static io.qameta.allure.util.ResultsUtils.md5;
Expand Down Expand Up @@ -283,7 282,7 @@ private List<Parameter> getExamplesAsParameters(
return IntStream.range(0, examplesBlock.get().getTableHeader().getCells().size()).mapToObj(index -> {
final String name = examplesBlock.get().getTableHeader().getCells().get(index).getValue();
final String value = row.getCells().get(index).getValue();
return new Parameter().setName(name).setValue(value);
return createParameter(name, value);
}).collect(Collectors.toList());
} else {
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,6 @@
import io.qameta.allure.model.Status;
import io.qameta.allure.model.StepResult;
import io.qameta.allure.util.ExceptionUtils;
import io.qameta.allure.util.ObjectUtils;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand All @@ -37,6 36,7 @@
import static io.qameta.allure.util.ResultsUtils.STORY_LABEL_NAME;
import static io.qameta.allure.util.ResultsUtils.SUITE_LABEL_NAME;
import static io.qameta.allure.util.ResultsUtils.TMS_LINK_TYPE;
import static io.qameta.allure.util.ResultsUtils.createParameter;
import static io.qameta.allure.util.ResultsUtils.getStatus;
import static io.qameta.allure.util.ResultsUtils.getStatusDetails;
import static java.util.Arrays.asList;
Expand Down Expand Up @@ -252,7 252,7 @@ public static void label(final String name, final String value) {
* @param value the value of parameter.
*/
public static <T> T parameter(final String name, final T value) {
final Parameter parameter = new Parameter().setName(name).setValue(ObjectUtils.toString(value));
final Parameter parameter = createParameter(name, value);
getLifecycle().updateTestCase(testResult -> testResult.getParameters().add(parameter));
return value;
}
Expand Down Expand Up @@ -511,7 511,7 @@ public void name(final String name) {

@Override
public <T> T parameter(final String name, final T value) {
final Parameter param = new Parameter().setName(name).setValue(ObjectUtils.toString(value));
final Parameter param = createParameter(name, value);
getLifecycle().updateStep(uuid, stepResult -> stepResult.getParameters().add(param));
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 26,7 @@
import java.util.stream.IntStream;

import static io.qameta.allure.util.NamingUtils.processNameTemplate;
import static io.qameta.allure.util.ResultsUtils.createParameter;

/**
* @author charlie (Dmitry Baev).
Expand Down Expand Up @@ -57,11 58,10 @@ public static Map<String, Object> getParametersMap(final MethodSignature signatu
}

public static List<Parameter> getParameters(final MethodSignature signature, final Object... args) {
return IntStream.range(0, args.length).mapToObj(index -> {
final String name = signature.getParameterNames()[index];
final String value = ObjectUtils.toString(args[index]);
return new Parameter().setName(name).setValue(value);
}).collect(Collectors.toList());
return IntStream
.range(0, args.length)
.mapToObj(index -> createParameter(signature.getParameterNames()[index], args[index]))
.collect(Collectors.toList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 24,7 @@
import io.qameta.allure.Story;
import io.qameta.allure.model.Label;
import io.qameta.allure.model.Link;
import io.qameta.allure.model.Parameter;
import io.qameta.allure.model.Status;
import io.qameta.allure.model.StatusDetails;
import org.apache.tika.io.IOUtils;
Expand Down Expand Up @@ -104,6 105,10 @@ private ResultsUtils() {
throw new IllegalStateException("Do not instance");
}

public static Parameter createParameter(final String name, final Object value) {
return new Parameter().setName(name).setValue(ObjectUtils.toString(value));
}

public static Label createSuiteLabel(final String suite) {
return new Label().setName(SUITE_LABEL_NAME).setValue(suite);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 34,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static io.qameta.allure.util.ResultsUtils.createParameter;

/**
* Allure labels utils.
*/
Expand Down Expand Up @@ -98,13 99,7 @@ public void updateParameters(final TestResult result) {
private List<Parameter> getMethodParameters() {
final String[] parameterNames = signature.getParameterNames();
return IntStream.range(0, parameterNames.length)
.mapToObj(index -> {
final String name = parameterNames[index];
final String value = Objects.toString(args[index]);
return new Parameter()
.setName(name)
.setValue(value);
})
.mapToObj(index -> createParameter(parameterNames[index], args[index]))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 26,8 @@

import java.util.Objects;

import static io.qameta.allure.util.ResultsUtils.createParameter;

/**
* Aspects for Allure1 Parameters.
*/
Expand Down Expand Up @@ -54,9 56,7 @@ public void parameterValueChanged(JoinPoint joinPoint) {
String value = Objects.toString(joinPoint.getArgs()[0]);

getLifecycle().updateTestCase(testResult ->
testResult.getParameters().add(new io.qameta.allure.model.Parameter()
.setName(name).setValue(value)
)
testResult.getParameters().add(createParameter(name, value))
);
} catch (Exception ignored) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 37,7 @@

import static io.qameta.allure.aspects.Allure1Utils.getName;
import static io.qameta.allure.aspects.Allure1Utils.getTitle;
import static io.qameta.allure.util.ResultsUtils.createParameter;
import static io.qameta.allure.util.ResultsUtils.getStatus;
import static io.qameta.allure.util.ResultsUtils.getStatusDetails;

Expand Down Expand Up @@ -93,11 94,9 @@ public String createTitle(final JoinPoint joinPoint) {
}

private static List<Parameter> getParameters(final MethodSignature signature, final Object... args) {
return IntStream.range(0, args.length).mapToObj(index -> {
final String name = signature.getParameterNames()[index];
final String value = Objects.toString(args[index]);
return new Parameter().setName(name).setValue(value);
}).collect(Collectors.toList());
return IntStream.range(0, args.length)
.mapToObj(index -> createParameter(signature.getParameterNames()[index], args[index]))
.collect(Collectors.toList());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 47,7 @@
import static io.qameta.allure.util.ResultsUtils.createFrameworkLabel;
import static io.qameta.allure.util.ResultsUtils.createHostLabel;
import static io.qameta.allure.util.ResultsUtils.createLanguageLabel;
import static io.qameta.allure.util.ResultsUtils.createParameter;
import static io.qameta.allure.util.ResultsUtils.createStoryLabel;
import static io.qameta.allure.util.ResultsUtils.createThreadLabel;
import static io.qameta.allure.util.ResultsUtils.getMd5Digest;
Expand Down Expand Up @@ -226,7 227,7 @@ protected void startTestCase(final String uuid,
final String fullName = String.format("%s: %s", story.getName(), name);

final List<Parameter> parameters = tableRow.entrySet().stream()
.map(entry -> new Parameter().setName(entry.getKey()).setValue(entry.getValue()))
.map(entry -> createParameter(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());

final List<Label> labels = Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 62,7 @@
import static io.qameta.allure.util.ResultsUtils.createHostLabel;
import static io.qameta.allure.util.ResultsUtils.createLanguageLabel;
import static io.qameta.allure.util.ResultsUtils.createPackageLabel;
import static io.qameta.allure.util.ResultsUtils.createParameter;
import static io.qameta.allure.util.ResultsUtils.createParentSuiteLabel;
import static io.qameta.allure.util.ResultsUtils.createSubSuiteLabel;
import static io.qameta.allure.util.ResultsUtils.createSuiteLabel;
Expand Down Expand Up @@ -322,9 323,7 @@ public void afterIteration(final IterationInfo iteration) {

private List<Parameter> getParameters(final List<String> names, final Object... values) {
return IntStream.range(0, Math.min(names.size(), values.length))
.mapToObj(index -> new Parameter()
.setName(names.get(index))
.setValue(Objects.toString(values[index])))
.mapToObj(index -> createParameter(names.get(index), values[index]))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 70,7 @@
import static io.qameta.allure.util.ResultsUtils.createHostLabel;
import static io.qameta.allure.util.ResultsUtils.createLanguageLabel;
import static io.qameta.allure.util.ResultsUtils.createPackageLabel;
import static io.qameta.allure.util.ResultsUtils.createParameter;
import static io.qameta.allure.util.ResultsUtils.createParentSuiteLabel;
import static io.qameta.allure.util.ResultsUtils.createSubSuiteLabel;
import static io.qameta.allure.util.ResultsUtils.createSuiteLabel;
Expand Down Expand Up @@ -655,7 656,7 @@ private List<Parameter> getParameters(final ITestContext context,
final Stream<Parameter> tagsParameters = context
.getCurrentXmlTest().getAllParameters().entrySet()
.stream()
.map(entry -> new Parameter().setName(entry.getKey()).setValue(entry.getValue()));
.map(entry -> createParameter(entry.getKey(), entry.getValue()));
final String[] parameterNames = getMethod(method)
.map(Executable::getParameters)
.map(Stream::of)
Expand All @@ -668,7 669,7 @@ private List<Parameter> getParameters(final ITestContext context,
.toArray(String[]::new)
: new String[]{};
final Stream<Parameter> methodParameters = range(0, min(parameterNames.length, parameterValues.length))
.mapToObj(i -> new Parameter().setName(parameterNames[i]).setValue(parameterValues[i]));
.mapToObj(i -> createParameter(parameterNames[i], parameterValues[i]));
return Stream.concat(tagsParameters, methodParameters)
.collect(Collectors.toList());
}
Expand Down

0 comments on commit 09257f6

Please sign in to comment.