@ -18,7 +18,11 @@ package org.springframework.boot.autoconfigure.neo4j;
import java.time.Duration ;
import org.junit.jupiter.api.Nested ;
import org.junit.jupiter.api.Test ;
import org.neo4j.driver.AuthTokenManager ;
import org.neo4j.driver.AuthTokenManagers ;
import org.neo4j.driver.AuthTokens ;
import org.neo4j.driver.Driver ;
import org.neo4j.driver.Result ;
import org.neo4j.driver.Session ;
@ -31,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration ;
import org.springframework.boot.test.context.SpringBootTest ;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.test.context.DynamicPropertyRegistry ;
import org.springframework.test.context.DynamicPropertySource ;
@ -43,7 +48,6 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Michael J . Simons
* @author Stephane Nicoll
* /
@SpringBootTest
@Testcontainers ( disabledWithoutDocker = true )
class Neo4jAutoConfigurationIntegrationTests {
@ -52,28 +56,71 @@ class Neo4jAutoConfigurationIntegrationTests {
. withStartupAttempts ( 5 )
. withStartupTimeout ( Duration . ofMinutes ( 10 ) ) ;
@DynamicPropertySource
static void neo4jProperties ( DynamicPropertyRegistry registry ) {
registry . add ( "spring.neo4j.uri" , neo4jServer : : getBoltUrl ) ;
registry . add ( "spring.neo4j.authentication.username" , ( ) - > "neo4j" ) ;
registry . add ( "spring.neo4j.authentication.password" , neo4jServer : : getAdminPassword ) ;
}
@SpringBootTest
@Nested
class DriverWithDefaultAuthToken {
@DynamicPropertySource
static void neo4jProperties ( DynamicPropertyRegistry registry ) {
registry . add ( "spring.neo4j.uri" , neo4jServer : : getBoltUrl ) ;
registry . add ( "spring.neo4j.authentication.username" , ( ) - > "neo4j" ) ;
registry . add ( "spring.neo4j.authentication.password" , neo4jServer : : getAdminPassword ) ;
}
@Autowired
private Driver driver ;
@Autowired
private Driver driver ;
@Test
void driverCanHandleRequest ( ) {
try ( Session session = this . driver . session ( ) ; Transaction tx = session . beginTransaction ( ) ) {
Result statementResult = tx . run ( "MATCH (n:Thing) RETURN n LIMIT 1" ) ;
assertThat ( statementResult . hasNext ( ) ) . isFalse ( ) ;
tx . commit ( ) ;
}
}
@Configuration ( proxyBeanMethods = false )
@ImportAutoConfiguration ( Neo4jAutoConfiguration . class )
static class TestConfiguration {
@Test
void driverCanHandleRequest ( ) {
try ( Session session = this . driver . session ( ) ; Transaction tx = session . beginTransaction ( ) ) {
Result statementResult = tx . run ( "MATCH (n:Thing) RETURN n LIMIT 1" ) ;
assertThat ( statementResult . hasNext ( ) ) . isFalse ( ) ;
tx . commit ( ) ;
}
}
@Configuration ( proxyBeanMethods = false )
@ImportAutoConfiguration ( Neo4jAutoConfiguration . class )
static class TestConfiguration {
@SpringBootTest
@Nested
class DriverWithDynamicAuthToken {
@DynamicPropertySource
static void neo4jProperties ( DynamicPropertyRegistry registry ) {
registry . add ( "spring.neo4j.uri" , neo4jServer : : getBoltUrl ) ;
registry . add ( "spring.neo4j.authentication.username" , ( ) - > "wrong" ) ;
registry . add ( "spring.neo4j.authentication.password" , ( ) - > "alsowrong" ) ;
}
@Autowired
private Driver driver ;
@Test
void driverCanHandleRequest ( ) {
try ( Session session = this . driver . session ( ) ; Transaction tx = session . beginTransaction ( ) ) {
Result statementResult = tx . run ( "MATCH (n:Thing) RETURN n LIMIT 1" ) ;
assertThat ( statementResult . hasNext ( ) ) . isFalse ( ) ;
tx . commit ( ) ;
}
}
@Configuration ( proxyBeanMethods = false )
@ImportAutoConfiguration ( Neo4jAutoConfiguration . class )
static class TestConfiguration {
@Bean
AuthTokenManager authTokenManager ( ) {
return AuthTokenManagers . expirationBased ( ( ) - > AuthTokens . basic ( "neo4j" , neo4jServer . getAdminPassword ( ) )
. expiringAt ( System . currentTimeMillis ( ) + 5_000 ) ) ;
}
}
}