-
Notifications
You must be signed in to change notification settings - Fork 19
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
Dynamic container junit5 #943
Merged
therealryan
merged 7 commits into
Mastercard:main
from
vchaitanya:DynamicContainer_junit5
Sep 30, 2024
Merged
Dynamic container junit5 #943
therealryan
merged 7 commits into
Mastercard:main
from
vchaitanya:DynamicContainer_junit5
Sep 30, 2024
+273
−29
Conversation
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
therealryan
reviewed
Sep 27, 2024
assert/assert-junit5/src/main/java/com/mastercard/test/flow/assrt/junit5/Flocessor.java
Outdated
Show resolved
Hide resolved
I've taken the liberty of writing a test that dumps out the container/test structure: /**
* A simple sequence of flows with no chains
*/
@Test
void simple() {
expectNodes( model( null, null, null, null, null ),
"test : 0 []",
"test : 1 []",
"test : 2 []",
"test : 3 []",
"test : 4 []" );
}
/**
* A single chain of a single flow
*/
@Test
void link() {
expectNodes( model( null, "a", null ),
"test : 0 []",
"container : Chain: 1 [chain:a]",
" test : 1 [chain:a]",
"test : 2 []" );
}
/**
* Consecutive single-flow chains
*/
@Test
void links() {
expectNodes( model( "a", "b", "c" ),
"container : Chain: 0 [chain:a]",
" test : 0 [chain:a]",
"container : Chain: 1 [chain:b]",
" test : 1 [chain:b]",
"container : Chain: 2 [chain:c]",
" test : 2 [chain:c]" );
}
/**
* A single multi-flow chain
*/
@Test
void chain() {
// in the middle
expectNodes( model( null, "a", "a", "a", null ),
"test : 0 []",
"container : Chain: 1 [chain:a]",
" test : 1 [chain:a]",
" test : 2 [chain:a]",
" test : 3 [chain:a]",
"test : 4 []" );
// at the start
expectNodes( model( "a", "a", "a", null ),
"container : Chain: 0 [chain:a]",
" test : 0 [chain:a]",
" test : 1 [chain:a]",
" test : 2 [chain:a]",
"test : 3 []" );
// at the end
expectNodes( model( null, "a", "a", "a" ),
"test : 0 []",
"container : Chain: 1 [chain:a]",
" test : 1 [chain:a]",
" test : 2 [chain:a]",
" test : 3 [chain:a]" );
}
/**
* Multiple multi-flow chains
*/
@Test
void chains() {
expectNodes( model( "a", "a", null, "b", "b", "c" ),
"container : Chain: 0 [chain:a]",
" test : 0 [chain:a]",
" test : 1 [chain:a]",
"test : 2 []",
"container : Chain: 3 [chain:b]",
" test : 3 [chain:b]",
" test : 4 [chain:b]",
"container : Chain: 5 [chain:c]",
" test : 5 [chain:c]" );
}
private static Model model( String... chains ) {
List<Flow> flows = new ArrayList<>();
for( int i = 0; i < chains.length; i++ ) {
int idx = i;
Flow flow = Creator
.build( f -> f.meta( data -> data
.description( String.valueOf( idx ) )
.tags( Tags.add( Optional.ofNullable( chains[idx] )
.map( v -> Chain.PREFIX + v )
.orElse( "" ) ) ) ) );
flows.add( flow );
}
Model model = mock( Model.class );
when( model.flows( anySet(), anySet() ) )
.thenReturn( flows.stream() );
return model;
}
private static void expectNodes( Model model, String... expected ) {
Flocessor flocessor = new Flocessor( "", model );
List<String> actual = new ArrayList<>();
flocessor.tests()
.forEach( node -> stringify( node, "", actual ) );
assertEquals(
copypasta( Stream.of( expected ) ),
copypasta( actual.stream() ) );
}
private static void stringify( DynamicNode node, String prefix, List<String> lines ) {
if( node instanceof DynamicTest ) {
DynamicTest test = (DynamicTest) node;
lines.add( prefix + "test : " + test.getDisplayName() );
}
else if( node instanceof DynamicContainer ) {
DynamicContainer container = (DynamicContainer) node;
lines.add( prefix + "container : " + container.getDisplayName() );
container.getChildren()
.forEach( child -> stringify( child, prefix + " ", lines ) );
}
else {
throw new IllegalStateException( "unexpected node " + node.getClass() );
}
}
/**
* @param content Some strings
* @return A string that can be trivially copy/pasted into java source
*/
private static String copypasta( Stream<String> content ) {
return content
.map( s -> s.replaceAll( "\r", "" ) )
.flatMap( s -> Stream.of( s.split( "\n" ) ) )
.map( s -> s.replaceAll( "\"", "'" ) )
.collect( Collectors.joining( "\",\n\"", "\"", "\"" ) );
} The flow structure looks good, but I think we should change the display name of the |
therealryan
reviewed
Sep 30, 2024
assert/assert-junit5/src/main/java/com/mastercard/test/flow/assrt/junit5/Flocessor.java
Outdated
Show resolved
Hide resolved
Looks great! |
Resolves #896 |
therealryan
added
enhancement
New feature or request
java
Pull requests that update Java code
labels
Oct 3, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
AbstractFlocessor flows() provides all chained transactions grouped together in the flattened list.
After the change, these chained transactions are grouped together under a dynamic container