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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
* Captures user-side AssertJ factories and fluent calls, then delegates assertion-chain state
* to {@link AssertJRecorder}.
*
* @author charlie (Dmitry Baev).
* @author sskorol (Sergey Korol).
*/
@SuppressWarnings("all")
@Aspect
Expand All @@ -59,6 +57,10 @@ protected AllureLifecycle initialValue() {
+ " || call(public * org.assertj.core.api.*SoftAssertionsProvider+.then*(..))"
+ ")"
)

/**
* Handles the assert factory call callback.
*/
public void assertFactoryCall() {
//pointcut body, should be empty
}
Expand All @@ -71,10 +73,19 @@ public void assertFactoryCall() {
+ ")"
+ " && target(assertion)"
)

/**
* Handles the assert operation call callback.
*
* @param assertion the assertion
*/
public void assertOperationCall(final AbstractAssert<?, ?> assertion) {
//pointcut body, should be empty
}

/**
* Handles the user code call callback.
*/
@Pointcut("!within(org.assertj..*) && !within(io.qameta.allure.assertj.AllureAspectJ)")
public void userCodeCall() {
//pointcut body, should be empty
Expand All @@ -84,6 +95,13 @@ public void userCodeCall() {
pointcut = "assertFactoryCall() && userCodeCall()",
returning = "result"
)

/**
* Handles the log assert creation callback.
*
* @param joinPoint the join point
* @param result the model object or framework result to process
*/
public void logAssertCreation(final JoinPoint joinPoint, final Object result) {
if (isRecordingMuted() || !(result instanceof AbstractAssert)) {
return;
Expand All @@ -93,6 +111,14 @@ public void logAssertCreation(final JoinPoint joinPoint, final Object result) {
getRecorder().assertionCreated(getLifecycle(), assertion, firstArgumentOf(joinPoint));
}

/**
* Returns the log assert operation.
*
* @param joinPoint the join point
* @param assertion the assertion
* @return the log assert operation
* @throws Throwable if the underlying framework operation fails
*/
@Around("assertOperationCall(assertion) && userCodeCall()")
public Object logAssertOperation(final ProceedingJoinPoint joinPoint,
final AbstractAssert<?, ?> assertion)
Expand Down Expand Up @@ -122,6 +148,12 @@ public Object logAssertOperation(final ProceedingJoinPoint joinPoint,
"execution(public void org.assertj.core.api.DefaultAssertionErrorCollector.collectAssertionError("
+ "java.lang.AssertionError)) && args(error)"
)

/**
* Handles the soft assertion failed callback.
*
* @param error the error reported by the framework
*/
public void softAssertionFailed(final AssertionError error) {
getRecorder().softAssertionFailed(error);
}
Expand All @@ -136,10 +168,18 @@ public static void setLifecycle(final AllureLifecycle allure) {
clearContext();
}

/**
* Returns the lifecycle.
*
* @return the Allure lifecycle used by this integration
*/
public static AllureLifecycle getLifecycle() {
return lifecycle.get();
}

/**
* Handles the clear context callback.
*/
public static void clearContext() {
RECORDER.remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@
*/
public class AssertJLifecycleListener implements TestLifecycleListener, FixtureLifecycleListener {

/**
* {@inheritDoc}
*/
@Override
public void afterTestWrite(final TestResult result) {
AllureAspectJ.clearContext();
}

/**
* {@inheritDoc}
*/
@Override
public void afterFixtureStop(final FixtureResult result) {
AllureAspectJ.clearContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
import static io.qameta.allure.test.RunUtils.runWithinTestContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;

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

@AllureFeatures.Steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,31 @@
package io.qameta.allure.attachment;

/**
* @author charlie (Dmitry Baev).
* Defines the attachment content contract used by Allure attachment support.
*
* <p>Implement this interface when custom code needs to participate in the same integration flow as the built-in Allure adapter components.</p>
*/
public interface AttachmentContent {

/**
* Returns the content.
*
* @return the content
*/
String getContent();

/**
* Returns the content type.
*
* @return the content type
*/
String getContentType();

/**
* Returns the file extension.
*
* @return the file extension
*/
String getFileExtension();

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
/**
* Marker interface for complex Allure attachments.
*
* @author charlie (Dmitry Baev).
*/
@FunctionalInterface
public interface AttachmentData {

/**
* Returns the name.
*
* @return the attachment or display name
*/
String getName();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@

/**
* @param <T> the type of attachment data.
* @author charlie (Dmitry Baev).
*/
@FunctionalInterface
public interface AttachmentProcessor<T extends AttachmentData> {

/**
* Adds the attachment.
*
* @param attachmentData the attachment data
* @param renderer the renderer used to turn attachment data into content
*/
void addAttachment(T attachmentData, AttachmentRenderer<T> renderer);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@
package io.qameta.allure.attachment;

/**
* @author charlie (Dmitry Baev).
* Supports Allure attachment integration with Allure reporting.
*
* <p>Use this type through the module that owns it when translating framework execution, result metadata, or attachments into Allure report data.</p>
*/
public class AttachmentRenderException extends RuntimeException {

/**
* Creates an attachment render exception with the supplied values.
*
* @param message the message
* @param cause the failure cause reported by the framework
*/
public AttachmentRenderException(final String message, final Throwable cause) {
super(message, cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

/**
* @param <T> the type of attachment data
* @author charlie (Dmitry Baev).
*/
@FunctionalInterface
public interface AttachmentRenderer<T extends AttachmentData> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package io.qameta.allure.attachment;

/**
* @author charlie (Dmitry Baev).
* Supports Allure attachment integration with Allure reporting.
*
* <p>Use this type through the module that owns it when translating framework execution, result metadata, or attachments into Allure report data.</p>
*/
public class DefaultAttachmentContent implements AttachmentContent {

Expand All @@ -26,6 +28,13 @@ public class DefaultAttachmentContent implements AttachmentContent {

private final String fileExtension;

/**
* Creates a default attachment content with the supplied values.
*
* @param content the attachment content
* @param contentType the attachment content type
* @param fileExtension the attachment file extension
*/
public DefaultAttachmentContent(final String content,
final String contentType,
final String fileExtension) {
Expand All @@ -34,16 +43,25 @@ public DefaultAttachmentContent(final String content,
this.fileExtension = fileExtension;
}

/**
* {@inheritDoc}
*/
@Override
public String getContent() {
return content;
}

/**
* {@inheritDoc}
*/
@Override
public String getContentType() {
return contentType;
}

/**
* {@inheritDoc}
*/
@Override
public String getFileExtension() {
return fileExtension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,33 @@
import java.nio.charset.StandardCharsets;

/**
* @author charlie (Dmitry Baev).
* Supports Allure attachment integration with Allure reporting.
*
* <p>Use this type through the module that owns it when translating framework execution, result metadata, or attachments into Allure report data.</p>
*/
public class DefaultAttachmentProcessor implements AttachmentProcessor<AttachmentData> {

private final AllureLifecycle lifecycle;

/**
* Creates a default attachment processor with default configuration.
*/
public DefaultAttachmentProcessor() {
this(Allure.getLifecycle());
}

/**
* Creates a default attachment processor with the supplied values.
*
* @param lifecycle the Allure lifecycle to use
*/
public DefaultAttachmentProcessor(final AllureLifecycle lifecycle) {
this.lifecycle = lifecycle;
}

/**
* {@inheritDoc}
*/
@Override
public void addAttachment(final AttachmentData attachmentData,
final AttachmentRenderer<AttachmentData> renderer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import java.util.Collections;

/**
* @author charlie (Dmitry Baev).
* Supports Allure attachment integration with Allure reporting.
*
* <p>Use this type through the module that owns it when translating framework execution, result metadata, or attachments into Allure report data.</p>
*/
public class FreemarkerAttachmentRenderer implements AttachmentRenderer<AttachmentData> {

Expand All @@ -36,6 +38,11 @@ public class FreemarkerAttachmentRenderer implements AttachmentRenderer<Attachme

private final String templateName;

/**
* Creates a freemarker attachment renderer with the supplied values.
*
* @param templateName the template name
*/
public FreemarkerAttachmentRenderer(final String templateName) {
this.templateName = templateName;
this.configuration = new Configuration(Configuration.VERSION_2_3_23);
Expand All @@ -45,6 +52,9 @@ public FreemarkerAttachmentRenderer(final String templateName) {
this.configuration.setClassLoaderForTemplateLoading(getClass().getClassLoader(), "tpl");
}

/**
* {@inheritDoc}
*/
@Override
public DefaultAttachmentContent render(final AttachmentData data) {
try (Writer writer = new StringWriter()) {
Expand Down
Loading
Loading