-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
External log integration in report (#987)
* External log integration in report * Make Customizer into biFunction and update readme * Javadoc update for motivation
- Loading branch information
1 parent
e44dc9a
commit f99e9d3
Showing
6 changed files
with
122 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/MotivationCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...rt/assert-core/src/test/java/com/mastercard/test/flow/assrt/MotivationCustomizerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.mastercard.test.flow.assrt; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
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 MotivationCustomizer} | ||
*/ | ||
class MotivationCustomizerTest { | ||
|
||
/** | ||
* Update motivation in the report even when flow is not processed due to some | ||
* exception | ||
*/ | ||
@Test | ||
void motivationNoBehaviour() { | ||
TestFlocessor tf = new TestFlocessor( "motivation without behaviour", TestModel.abc() ) | ||
.motivation( ( motivation, assertion ) -> motivation + "Common motivation" ) | ||
.reporting( Reporting.QUIETLY ) | ||
.system( AbstractFlocessor.State.LESS, TestModel.Actors.B ); | ||
|
||
tf.execute(); | ||
|
||
assertEquals( "abc [] error No test behaviour specified", tf.events() ); | ||
|
||
// This is also recorded to the report | ||
Reader r = new Reader( tf.report() ); | ||
Index index = r.read(); | ||
Entry ie = index.entries.get( 0 ); | ||
FlowData fd = r.detail( ie ); | ||
assertEquals( "Common motivation", fd.motivation ); | ||
} | ||
|
||
/** | ||
* Motivation can be updated in the report after the flow is processed | ||
*/ | ||
@Test | ||
void motivation() { | ||
TestFlocessor tf = new TestFlocessor( "motivation", TestModel.abc() ) | ||
.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() ); | ||
} ) | ||
.reporting( Reporting.QUIETLY ) | ||
.system( AbstractFlocessor.State.LESS, TestModel.Actors.B ); | ||
|
||
tf.execute(); | ||
|
||
// This is also recorded to the report | ||
Reader r = new Reader( tf.report() ); | ||
Index index = r.read(); | ||
Entry ie = index.entries.get( 0 ); | ||
FlowData fd = r.detail( ie ); | ||
assertEquals( "\n\n[View Logs](https://www.google.com/search?q=AB)", fd.motivation ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters