Skip to content

Commit 47c568a

Browse files
committed
Polish contribution
Closes gh-6746
1 parent bb7b789 commit 47c568a

File tree

2 files changed

+20
-64
lines changed

2 files changed

+20
-64
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jProperties.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public class Neo4jProperties implements ApplicationContextAware {
4747

4848
static final String BOLT_DRIVER = "org.neo4j.ogm.drivers.bolt.driver.BoltDriver";
4949

50-
static final String DEFAULT_BOLT_URI = "bolt://localhost:7687";
51-
5250
/**
5351
* URI used by the driver. Auto-detected by default.
5452
*/
@@ -173,11 +171,6 @@ private void configureDriverWithDefaults(DriverConfiguration driverConfiguration
173171
driverConfiguration.setDriverClassName(EMBEDDED_DRIVER);
174172
return;
175173
}
176-
if (ClassUtils.isPresent(BOLT_DRIVER, this.classLoader)) {
177-
driverConfiguration.setDriverClassName(BOLT_DRIVER);
178-
driverConfiguration.setURI( DEFAULT_BOLT_URI );
179-
return;
180-
}
181174
driverConfiguration.setDriverClassName(HTTP_DRIVER);
182175
driverConfiguration.setURI(DEFAULT_HTTP_URI);
183176
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jPropertiesTests.java

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import java.net.URL;
2020
import java.net.URLClassLoader;
21-
import java.util.EnumSet;
22-
import java.util.Set;
2321

2422
import com.hazelcast.util.Base64;
2523
import org.junit.After;
@@ -31,6 +29,7 @@
3129
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3230
import org.springframework.boot.test.util.EnvironmentTestUtils;
3331
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
32+
3433
import static org.assertj.core.api.Assertions.assertThat;
3534

3635
/**
@@ -51,45 +50,38 @@ public void close() {
5150

5251
@Test
5352
public void defaultUseEmbeddedInMemoryIfAvailable() {
54-
Neo4jProperties properties = load(EnumSet.of( AvailableDriver.EMBEDDED ));
53+
Neo4jProperties properties = load(true);
5554
Configuration configuration = properties.createConfiguration();
5655
assertDriver(configuration, Neo4jProperties.EMBEDDED_DRIVER, null);
5756
}
5857

5958
@Test
60-
public void defaultUseBoltIfAvailableAndEmbeddedNot() {
61-
Neo4jProperties properties = load(EnumSet.of( AvailableDriver.BOLT ));
62-
Configuration configuration = properties.createConfiguration();
63-
assertDriver(configuration, Neo4jProperties.BOLT_DRIVER, "bolt://localhost:7687");
64-
}
65-
66-
@Test
67-
public void defaultUseHttpIfEmbeddedAndBoltIsNotAvailable() {
68-
Neo4jProperties properties = load(EnumSet.noneOf( AvailableDriver.class ));
59+
public void defaultUseHttpDriverIfEmbeddedDriverIsNotAvailable() {
60+
Neo4jProperties properties = load(false);
6961
Configuration configuration = properties.createConfiguration();
7062
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER,
7163
Neo4jProperties.DEFAULT_HTTP_URI);
7264
}
7365

7466
@Test
7567
public void httpUriUseHttpServer() {
76-
Neo4jProperties properties = load(EnumSet.of( AvailableDriver.EMBEDDED ),
68+
Neo4jProperties properties = load(true,
7769
"spring.data.neo4j.uri=http://localhost:7474");
7870
Configuration configuration = properties.createConfiguration();
7971
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER, "http://localhost:7474");
8072
}
8173

8274
@Test
83-
public void boltUriUseBolt() {
84-
Neo4jProperties properties = load(EnumSet.of( AvailableDriver.EMBEDDED, AvailableDriver.BOLT ),
75+
public void boltUriUseBoltDriver() {
76+
Neo4jProperties properties = load(true,
8577
"spring.data.neo4j.uri=bolt://localhost:7687");
8678
Configuration configuration = properties.createConfiguration();
8779
assertDriver(configuration, Neo4jProperties.BOLT_DRIVER, "bolt://localhost:7687");
8880
}
8981

9082
@Test
9183
public void fileUriUseEmbeddedServer() {
92-
Neo4jProperties properties = load(EnumSet.of( AvailableDriver.EMBEDDED ),
84+
Neo4jProperties properties = load(true,
9385
"spring.data.neo4j.uri=file://var/tmp/graph.db");
9486
Configuration configuration = properties.createConfiguration();
9587
assertDriver(configuration, Neo4jProperties.EMBEDDED_DRIVER,
@@ -98,7 +90,7 @@ public void fileUriUseEmbeddedServer() {
9890

9991
@Test
10092
public void credentialsAreSet() {
101-
Neo4jProperties properties = load(EnumSet.of( AvailableDriver.EMBEDDED ),
93+
Neo4jProperties properties = load(true,
10294
"spring.data.neo4j.uri=http://localhost:7474",
10395
"spring.data.neo4j.username=user", "spring.data.neo4j.password=secret");
10496
Configuration configuration = properties.createConfiguration();
@@ -108,7 +100,7 @@ public void credentialsAreSet() {
108100

109101
@Test
110102
public void credentialsAreSetFromUri() {
111-
Neo4jProperties properties = load(EnumSet.of( AvailableDriver.EMBEDDED ),
103+
Neo4jProperties properties = load(true,
112104
"spring.data.neo4j.uri=http://user:secret@my-server:7474");
113105
Configuration configuration = properties.createConfiguration();
114106
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER,
@@ -118,7 +110,7 @@ public void credentialsAreSetFromUri() {
118110

119111
@Test
120112
public void embeddedModeDisabledUseHttpUri() {
121-
Neo4jProperties properties = load(EnumSet.of( AvailableDriver.EMBEDDED ),
113+
Neo4jProperties properties = load(true,
122114
"spring.data.neo4j.embedded.enabled=false");
123115
Configuration configuration = properties.createConfiguration();
124116
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER,
@@ -127,7 +119,7 @@ public void embeddedModeDisabledUseHttpUri() {
127119

128120
@Test
129121
public void embeddedModeWithRelativeLocation() {
130-
Neo4jProperties properties = load(EnumSet.of( AvailableDriver.EMBEDDED ),
122+
Neo4jProperties properties = load(true,
131123
"spring.data.neo4j.uri=target/neo4j/my.db");
132124
Configuration configuration = properties.createConfiguration();
133125
assertDriver(configuration, Neo4jProperties.EMBEDDED_DRIVER,
@@ -159,15 +151,20 @@ private static void assertCredentials(Configuration actual, String username,
159151
}
160152
}
161153

162-
public Neo4jProperties load( final Set<AvailableDriver> availableDrivers, String... environment) {
154+
public Neo4jProperties load(final boolean embeddedAvailable, String... environment) {
163155
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
164156
ctx.setClassLoader(new URLClassLoader(new URL[0], getClass().getClassLoader()) {
165157

166158
@Override
167159
protected Class<?> loadClass(String name, boolean resolve)
168160
throws ClassNotFoundException {
169-
if ( AvailableDriver.shouldLoad( availableDrivers, name )) {
170-
return AvailableDriver.loadClass( name );
161+
if (name.equals(Neo4jProperties.EMBEDDED_DRIVER)) {
162+
if (embeddedAvailable) {
163+
return TestEmbeddedDriver.class;
164+
}
165+
else {
166+
throw new ClassNotFoundException();
167+
}
171168
}
172169
return super.loadClass(name, resolve);
173170
}
@@ -186,42 +183,8 @@ static class TestConfiguration {
186183

187184
}
188185

189-
private enum AvailableDriver {
190-
EMBEDDED( Neo4jProperties.EMBEDDED_DRIVER, TestEmbeddedDriver.class ),
191-
BOLT( Neo4jProperties.BOLT_DRIVER, TestBoltDriver.class );
192-
193-
private final String driverName;
194-
private final Class<?> driverStub;
195-
196-
AvailableDriver( final String driverName, final Class<?> driverStub ) {
197-
this.driverName = driverName;
198-
this.driverStub = driverStub;
199-
}
200-
201-
public static boolean shouldLoad( Set<AvailableDriver> availableDrivers, String name ) {
202-
for ( AvailableDriver driver : availableDrivers ) {
203-
if ( driver.driverName.equals( name ) ) {
204-
return true;
205-
}
206-
}
207-
return false;
208-
}
209-
210-
public static Class<?> loadClass( String className ) throws ClassNotFoundException {
211-
for ( AvailableDriver driver : AvailableDriver.values() ) {
212-
if ( driver.driverName.equals( className ) ) {
213-
return driver.driverStub;
214-
}
215-
}
216-
throw new ClassNotFoundException();
217-
}
218-
}
219-
220186
private static class TestEmbeddedDriver {
221187

222188
}
223189

224-
private static class TestBoltDriver {
225-
}
226-
227190
}

0 commit comments

Comments
 (0)