Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 'this' to Step processing (via allure-framework#615) #377

Merged
merged 3 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -79,7 +79,7 @@ public void attachment(final JoinPoint joinPoint, final Object result) {

final String name = attachment.value().isEmpty()
? methodSignature.getName()
: processNameTemplate(attachment.value(), getParametersMap(methodSignature, joinPoint.getArgs()));
: processNameTemplate(attachment.value(), getParametersMap(joinPoint));
getLifecycle().addAttachment(name, attachment.type(), attachment.fileExtension(), bytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void stepStart(final JoinPoint joinPoint) {
final Step step = methodSignature.getMethod().getAnnotation(Step.class);

final String uuid = UUID.randomUUID().toString();
final String name = getName(step.value(), methodSignature, joinPoint.getArgs());
final String name = getName(step.value(), joinPoint);
final List<Parameter> parameters = getParameters(methodSignature, joinPoint.getArgs());

final StepResult result = new StepResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.qameta.allure.util;

import io.qameta.allure.model.Parameter;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.MethodSignature;

import java.util.HashMap;
Expand All @@ -37,19 +38,20 @@ private AspectUtils() {
throw new IllegalStateException("Do not instance");
}

public static String getName(final String nameTemplate,
final MethodSignature methodSignature,
final Object... args) {
public static String getName(final String nameTemplate, final JoinPoint joinPoint) {
baev marked this conversation as resolved.
Show resolved Hide resolved
return Optional.of(nameTemplate)
.filter(v -> !v.isEmpty())
.map(value -> processNameTemplate(value, getParametersMap(methodSignature, args)))
.orElseGet(methodSignature::getName);
.map(value -> processNameTemplate(value, getParametersMap(joinPoint)))
.orElseGet(joinPoint.getSignature()::getName);
}

public static Map<String, Object> getParametersMap(final MethodSignature signature, final Object... args) {
final String[] parameterNames = signature.getParameterNames();
public static Map<String, Object> getParametersMap(final JoinPoint joinPoint) {
baev marked this conversation as resolved.
Show resolved Hide resolved
final MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
final String[] parameterNames = methodSignature.getParameterNames();
final Map<String, Object> params = new HashMap<>();
params.put("method", signature.getName());
params.put("method", methodSignature.getName());
params.put("this", joinPoint.getThis());
final Object[] args = joinPoint.getArgs();
for (int i = 0; i < Math.max(parameterNames.length, args.length); i++) {
params.put(parameterNames[i], args[i]);
params.put(Integer.toString(i), args[i]);
Expand Down