|
18 | 18 | */
|
19 | 19 | package org.neo4j.driver.integration;
|
20 | 20 |
|
| 21 | +import org.hamcrest.BaseMatcher; |
| 22 | +import org.hamcrest.Description; |
21 | 23 | import org.junit.jupiter.api.BeforeEach;
|
22 | 24 | import org.junit.jupiter.api.Test;
|
23 | 25 | import org.junit.jupiter.api.extension.RegisterExtension;
|
24 | 26 |
|
| 27 | +import java.util.UUID; |
| 28 | + |
25 | 29 | import org.neo4j.driver.Driver;
|
26 | 30 | import org.neo4j.driver.Session;
|
27 | 31 | import org.neo4j.driver.Transaction;
|
|
33 | 37 | import org.neo4j.driver.util.ParallelizableIT;
|
34 | 38 | import org.neo4j.driver.util.SessionExtension;
|
35 | 39 |
|
36 |
| -import static org.hamcrest.Matchers.not; |
37 | 40 | import static org.hamcrest.Matchers.startsWith;
|
38 | 41 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
39 | 42 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
@@ -84,8 +87,26 @@ void shouldReceiveNewBookmarkOnSuccessfulCommit() throws Throwable
|
84 | 87 | createNodeInTx( session );
|
85 | 88 |
|
86 | 89 | // Then
|
87 |
| - assertBookmarkContainsSingleValue( session.lastBookmark(), startsWith( "neo4j:" ) ); |
88 |
| - assertBookmarkContainsSingleValue( session.lastBookmark(), not( startsWith( "neo4j:bookmark:v1:tx" ) ) ); |
| 90 | + assertBookmarkContainsSingleValue( session.lastBookmark(), new BaseMatcher<String>() |
| 91 | + { |
| 92 | + @Override |
| 93 | + public boolean matches( Object item ) |
| 94 | + { |
| 95 | + if ( item instanceof String ) |
| 96 | + { |
| 97 | + String bookmark = (String) item; |
| 98 | + String[] split = bookmark.split( ":" ); |
| 99 | + return split.length == 2 && isUuid( split[0] ) && isNumeric( split[1] ); |
| 100 | + } |
| 101 | + return false; |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public void describeTo( Description description ) |
| 106 | + { |
| 107 | + description.appendText( "Expecting a bookmark with format 'database_uuid:tx_id'" ); |
| 108 | + } |
| 109 | + } ); |
89 | 110 | }
|
90 | 111 |
|
91 | 112 | @Test
|
@@ -212,4 +233,30 @@ private static void createNodeInTx( Session session )
|
212 | 233 | tx.commit();
|
213 | 234 | }
|
214 | 235 | }
|
| 236 | + |
| 237 | + private static boolean isUuid( String string ) |
| 238 | + { |
| 239 | + try |
| 240 | + { |
| 241 | + UUID.fromString( string ); |
| 242 | + } |
| 243 | + catch ( IllegalArgumentException | NullPointerException e ) |
| 244 | + { |
| 245 | + return false; |
| 246 | + } |
| 247 | + return true; |
| 248 | + } |
| 249 | + |
| 250 | + private static boolean isNumeric( String string ) |
| 251 | + { |
| 252 | + try |
| 253 | + { |
| 254 | + Long.parseLong( string ); |
| 255 | + } |
| 256 | + catch ( NumberFormatException | NullPointerException e ) |
| 257 | + { |
| 258 | + return false; |
| 259 | + } |
| 260 | + return true; |
| 261 | + } |
215 | 262 | }
|
0 commit comments