1515 */
1616package org .springframework .data .neo4j .test ;
1717
18+ import io .netty .channel .EventLoopGroup ;
19+ import io .netty .channel .nio .NioEventLoopGroup ;
20+ import io .netty .util .concurrent .DefaultThreadFactory ;
1821import org .apache .commons .logging .Log ;
1922import org .junit .jupiter .api .extension .BeforeAllCallback ;
2023import org .junit .jupiter .api .extension .BeforeEachCallback ;
2326import org .junit .platform .commons .support .ReflectionSupport ;
2427import org .neo4j .driver .AccessMode ;
2528import org .neo4j .driver .AuthToken ;
29+ import org .neo4j .driver .AuthTokenManagers ;
2630import org .neo4j .driver .AuthTokens ;
2731import org .neo4j .driver .Config ;
2832import org .neo4j .driver .Driver ;
29- import org .neo4j .driver .GraphDatabase ;
3033import org .neo4j .driver .Logging ;
3134import org .neo4j .driver .Record ;
3235import org .neo4j .driver .Session ;
3336import org .neo4j .driver .SessionConfig ;
37+ import org .neo4j .driver .internal .DriverFactory ;
38+ import org .neo4j .driver .internal .SecuritySettings ;
39+ import org .neo4j .driver .internal .security .SecurityPlans ;
3440import org .springframework .core .log .LogMessage ;
3541import org .springframework .lang .Nullable ;
3642import org .testcontainers .containers .Neo4jContainer ;
3743import org .testcontainers .utility .TestcontainersConfiguration ;
3844
3945import java .lang .reflect .Field ;
4046import java .lang .reflect .Modifier ;
47+ import java .net .URI ;
4148import java .util .List ;
4249import java .util .Locale ;
4350import java .util .Map ;
@@ -82,12 +89,14 @@ public class Neo4jExtension implements BeforeAllCallback, BeforeEachCallback {
8289 private static final String SYS_PROPERTY_FORCE_CONTAINER_REUSE = "SDN_FORCE_REUSE_OF_CONTAINERS" ;
8390 private static final Log log = org .apache .commons .logging .LogFactory .getLog (Neo4jExtension .class );
8491
85- private static Set <String > COMMUNITY_EDITION_INDICATOR = Set .of ("community" );
92+ private static final Set <String > COMMUNITY_EDITION_INDICATOR = Set .of ("community" );
93+ private static final Set <String > COMMERCIAL_EDITION_INDICATOR = Set .of ("commercial" , "enterprise" );
8694
87- private static Set < String > COMMERCIAL_EDITION_INDICATOR = Set . of ( "commercial" , "enterprise" );
95+ private static final EventLoopGroup EVENT_LOOP_GROUP = new NioEventLoopGroup ( new DefaultThreadFactory ( Neo4jExtension . class , true ) );
8896
8997 @ Override
9098 public void beforeAll (ExtensionContext context ) throws Exception {
99+
91100 List <Field > injectableFields = ReflectionSupport .findFields (context .getRequiredTestClass (),
92101 field -> Modifier .isStatic (field .getModifiers ()) && field .getType () == Neo4jConnectionSupport .class ,
93102 HierarchyTraversalMode .BOTTOM_UP );
@@ -163,6 +172,8 @@ private void checkRequiredFeatures(Neo4jConnectionSupport neo4jConnectionSupport
163172 */
164173 public static final class Neo4jConnectionSupport implements ExtensionContext .Store .CloseableResource {
165174
175+ private final DriverFactory driverFactory ;
176+
166177 public final String url ;
167178
168179 public final AuthToken authToken ;
@@ -182,6 +193,7 @@ public Neo4jConnectionSupport(String url, AuthToken authToken) {
182193 this .config = Config .builder ().withLogging (Logging .slf4j ())
183194 .withMaxConnectionPoolSize (Runtime .getRuntime ().availableProcessors ())
184195 .build ();
196+ this .driverFactory = new DriverFactory ();
185197 }
186198
187199 /**
@@ -198,14 +210,21 @@ public Driver getDriver() {
198210 synchronized (this ) {
199211 driver = this .driverInstance ;
200212 if (!isUsable (driver )) {
201- this .driverInstance = GraphDatabase . driver ( url , authToken , config );
213+ this .driverInstance = createDriverInstance ( );
202214 driver = this .driverInstance ;
203215 }
204216 }
205217 }
206218 return driver ;
207219 }
208220
221+ private Driver createDriverInstance () {
222+ var uri = URI .create (url );
223+ var settings = new SecuritySettings (config .encrypted (), config .trustStrategy ());
224+ var securityPlan = SecurityPlans .createSecurityPlan (settings , uri .getScheme ());
225+ return this .driverFactory .newInstance (uri , AuthTokenManagers .basic (() -> authToken ), config , securityPlan , EVENT_LOOP_GROUP , null );
226+ }
227+
209228 /**
210229 * A driver is usable if it's not null and can verify its connectivity. This method force closes
211230 * the bean if the connectivity cannot be verified to avoid having a netty pool dangling around.
0 commit comments