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

External log integration in report #987

Merged
merged 3 commits into from
Oct 30, 2024
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
Prev Previous commit
Next Next commit
Make Customizer into biFunction and update readme
  • Loading branch information
vchaitanya committed Oct 30, 2024
commit 376e1e37d7f87743ca3377988484fa7009f2b09b
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ public enum State {
// no-op
};

private ReportCustomizer reportCustomizer = new ReportCustomizer() {
// no-op
};
private MotivationCustomizer motivationCustomizer = ( motivation, assrt ) -> motivation;

/**
* @param title The title of this test
Expand Down Expand Up @@ -378,8 +376,8 @@ public T behaviour( Consumer<Assertion> t ) {
* @param customizer How to modify the {@link FlowData}
* @return <code>this</code> for method chaining.
*/
public T motivation( ReportCustomizer customizer ) {
reportCustomizer = customizer;
public T motivation( MotivationCustomizer customizer ) {
motivationCustomizer = customizer;
return self();
}

Expand Down Expand Up @@ -562,7 +560,7 @@ private int processInteraction( Flow flow, Interaction ntr, List<Assertion> actu
reportUpdates.add( d -> logCapture.end( flow ).forEach( d.logs::add ) );
reportUpdates.add( d -> d.logs.add( error(
"Encountered error: " + LogEvent.stackTrace( e ) ) ) );
reportUpdates.add( d -> reportCustomizer.customizeReport( d, assrt ) );
reportUpdates.add( d -> d.motivation = motivationCustomizer.apply( d.motivation, assrt ) );
report( w -> w.with( flow, reportUpdates.stream()
.reduce( d -> {
// no-op
Expand Down Expand Up @@ -629,7 +627,8 @@ private int processMessage( Flow flow, Assertion assertion,
parseFailures.add( e );
}
finally {
reportUpdates.add( d -> reportCustomizer.customizeReport( d, assertion ) );
reportUpdates
.add( d -> d.motivation = motivationCustomizer.apply( d.motivation, assertion ) );
}
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mastercard.test.flow.assrt;

import java.util.function.BiFunction;

/**
* Customizes the motivation text in the report.
*/
public interface MotivationCustomizer extends BiFunction<String, Assertion, String> {
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.mastercard.test.flow.report.Reader;
import com.mastercard.test.flow.report.data.Entry;
import com.mastercard.test.flow.report.data.FlowData;
import com.mastercard.test.flow.report.data.Index;

/**
* Demonstrates the execution {@link ReportCustomizer}
* Demonstrates the execution {@link MotivationCustomizer}
*/
class ReportCustomizerTest {
class MotivationCustomizerTest {

/**
* Update motivation in the report even when flow is not processed due to some
Expand All @@ -21,12 +21,7 @@ class ReportCustomizerTest {
@Test
void motivationNoBehaviour() {
TestFlocessor tf = new TestFlocessor( "motivation without behaviour", TestModel.abc() )
.motivation( new ReportCustomizer() {
@Override
public void customizeReport( FlowData flowData, Assertion assertion ) {
flowData.motivation += "common motivation";
}
} )
.motivation( ( motivation, assertion ) -> motivation + "Common motivation" )
.reporting( Reporting.QUIETLY )
.system( AbstractFlocessor.State.LESS, TestModel.Actors.B );

Expand All @@ -39,7 +34,7 @@ public void customizeReport( FlowData flowData, Assertion assertion ) {
Index index = r.read();
Entry ie = index.entries.get( 0 );
FlowData fd = r.detail( ie );
assertEquals( "common motivation", fd.motivation );
assertEquals( "Common motivation", fd.motivation );
}

/**
Expand All @@ -48,18 +43,13 @@ public void customizeReport( FlowData flowData, Assertion assertion ) {
@Test
void motivation() {
TestFlocessor tf = new TestFlocessor( "motivation", TestModel.abc() )
.motivation( new ReportCustomizer() {
@Override
public void customizeReport( FlowData flowData, Assertion assertion ) {
String baseUrl = "https://www.google.com/search?q=";
// Extract data from request or response to build a link
String queryToken = new String( assertion.expected().request().content() ).substring( 0,
1 );
queryToken += new String( assertion.actual().response() ).substring( 0,
1 );
String logLink = baseUrl + queryToken;
flowData.motivation += "\n\n[View Logs](" + logLink + ")";
}
.motivation( ( motivation, assertion ) -> {
String baseUrl = "https://www.google.com/search?q=";
String queryToken = new String( assertion.expected().request().content() ).substring( 0,
1 );
queryToken += new String( assertion.actual().response() ).substring( 0, 1 );
String logLink = baseUrl + queryToken;
return motivation + "\n\n[View Logs](" + logLink + ")";
} )
.behaviour( assrt -> {
assrt.actual().response( assrt.expected().response().content() );
Expand Down
25 changes: 17 additions & 8 deletions doc/src/main/markdown/further.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The execution report includes tooling to aid in change review. If the reports ge

<!-- code_link_start -->

[AbstractFlocessor.reporting(Reporting,String...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L195-L204,195-204
[AbstractFlocessor.reporting(Reporting,String...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L197-L206,197-206
[Reporting]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/Reporting.java

<!-- code_link_end -->
Expand Down Expand Up @@ -80,8 +80,8 @@ Note that only the tag/index-based filtering can be used to avoid flow construct

<!-- code_link_start -->

[AbstractFlocessor.filtering(Consumer)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L316-L324,316-324
[AbstractFlocessor.exercising(Predicate,Consumer)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L329-L354,329-354
[AbstractFlocessor.filtering(Consumer)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L318-L326,318-326
[AbstractFlocessor.exercising(Predicate,Consumer)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L331-L356,331-356

<!-- code_link_end -->

Expand Down Expand Up @@ -125,10 +125,19 @@ Note that the assertion components will not make any assumptions about the forma
[LogCapture]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/LogCapture.java
[Tail]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/log/Tail.java
[Merge]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/log/Merge.java
[AbstractFlocessor.logs(LogCapture)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L284-L291,284-291
[AbstractFlocessor.logs(LogCapture)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L286-L293,286-293

<!-- code_link_end -->

## Motivation Customizer
The motivation text in the report can be enhanced with additional information such as providing links to external systems such as splunk, datadog, aws etc. by implementing the [`MotivationCustomizer`][MotivationCustomizer] interface when you build the `Flocessor` object via the [`motivation()`][AbstractFlocessor.motivation(MotivationCustomizer)] method.

<!-- code_link_start -->

[MotivationCustomizer]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/MotivationCustomizer.java
[AbstractFlocessor.motivation(MotivationCustomizer)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L373-L379,373-379

<!--code_link_end-->
## Interaction structure

The system in the [quickstart guide](quickstart.md) was extremely simple, and hence the flows that model it also had the simplest possible structure: two actors and a single request/response pair between them.
Expand Down Expand Up @@ -248,7 +257,7 @@ Consider the following worked example:

[flow.Unpredictable]: ../../../../api/src/main/java/com/mastercard/test/flow/Unpredictable.java
[AbstractMessage.masking(Unpredictable,UnaryOperator)]: ../../../../message/message-core/src/main/java/com/mastercard/test/flow/msg/AbstractMessage.java#L50-L57,50-57
[AbstractFlocessor.masking(Unpredictable...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L212-L219,212-219
[AbstractFlocessor.masking(Unpredictable...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L214-L221,214-221
[mask.BenSys]: ../../test/java/com/mastercard/test/flow/doc/mask/BenSys.java
[mask.DieSys]: ../../test/java/com/mastercard/test/flow/doc/mask/DieSys.java
[mask.Unpredictables]: ../../test/java/com/mastercard/test/flow/doc/mask/Unpredictables.java
Expand All @@ -258,7 +267,7 @@ Consider the following worked example:
[msg.Mask.andThen(Consumer)]: ../../../../message/message-core/src/main/java/com/mastercard/test/flow/msg/Mask.java#L290-L292,290-292
[BenDiceTest?masking]: ../../test/java/com/mastercard/test/flow/doc/mask/BenDiceTest.java#L31,31
[BenTest]: ../../test/java/com/mastercard/test/flow/doc/mask/BenTest.java
[AbstractFlocessor.masking(Unpredictable...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L212-L219,212-219
[AbstractFlocessor.masking(Unpredictable...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L214-L221,214-221

<!-- code_link_end -->

Expand All @@ -278,7 +287,7 @@ You can see usage of these types in the example system:
[flow.Context]: ../../../../api/src/main/java/com/mastercard/test/flow/Context.java
[Builder.context(Context)]: ../../../../builder/src/main/java/com/mastercard/test/flow/builder/Builder.java#L225-L232,225-232
[assrt.Applicator]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/Applicator.java
[AbstractFlocessor.applicators(Applicator...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L258-L264,258-264
[AbstractFlocessor.applicators(Applicator...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L260-L266,260-266
[model.ctx.QueueProcessing]: ../../../../example/app-model/src/main/java/com/mastercard/test/flow/example/app/model/ctx/QueueProcessing.java
[QueueProcessingApplicator]: ../../../../example/app-assert/src/main/java/com/mastercard/test/flow/example/app/assrt/ctx/QueueProcessingApplicator.java

Expand All @@ -301,7 +310,7 @@ You can see usage of these types in the example system:

[flow.Residue]: ../../../../api/src/main/java/com/mastercard/test/flow/Residue.java
[assrt.Checker]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/Checker.java
[AbstractFlocessor.checkers(Checker...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L271-L277,271-277
[AbstractFlocessor.checkers(Checker...)]: ../../../../assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java#L273-L279,273-279
[model.rsd.DBItems]: ../../../../example/app-model/src/main/java/com/mastercard/test/flow/example/app/model/rsd/DBItems.java
[DBItemsChecker]: ../../../../example/app-assert/src/main/java/com/mastercard/test/flow/example/app/assrt/rsd/DBItemsChecker.java

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FlowData {
public final Set<String> tags;
/**
* public access to allow for enhancing the report with additional information
* using {@link com.mastercard.test.flow.assrt.ReportCustomizer}
* using {@link com.mastercard.test.flow.assrt.MotivationCustomizer}
*
* @see Metadata#motivation()
*/
Expand Down
Loading