Polish contribution
This commit polihes the original Neo4j contribution in several areas. Rather than providing the packages to scan, this commit rearranges the `EntityScan` and `EntityScanRegistrar` so that the logic can be shared for other components. If no package is provided, scanning now defaults to the "auto-configured" package(s) and a `@NodeEntityScan` annotation allows to override that. The configuration has also been updated to detect the driver based on the `uri` property. If the embedded driver is available we use that by default. If it is not available, we're trying to connect to a Neo4j server running on localhost. It is possible to disable the embedded mode or set the `uri` parameter explicitly to deviate from these defaults. The sample no longer relies on the embedded driver for licensing reason: rather it expects an instance running on localhost (like other data-related samples) and gracefully ignore any connection error. A README has been added in the sample to further explain the available options; Closes gh-5458
This commit is contained in:
@@ -16,35 +16,46 @@
|
||||
|
||||
package sample.data.neo4j;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import java.net.ConnectException;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link SampleNeo4jApplication}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleNeo4jApplication.class)
|
||||
@IntegrationTest
|
||||
public class SampleNeo4jApplicationTests {
|
||||
|
||||
@ClassRule
|
||||
public static OutputCapture outputCapture = new OutputCapture();
|
||||
@Rule
|
||||
public OutputCapture outputCapture = new OutputCapture();
|
||||
|
||||
@Test
|
||||
public void testDefaultSettings() throws Exception {
|
||||
String output = SampleNeo4jApplicationTests.outputCapture.toString();
|
||||
try {
|
||||
SampleNeo4jApplication.main(new String[0]);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (!neo4jServerRunning(ex)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("firstName='Alice', lastName='Smith'"));
|
||||
}
|
||||
|
||||
private boolean neo4jServerRunning(Throwable ex) {
|
||||
System.out.println(ex.getMessage());
|
||||
if (ex instanceof ConnectException) {
|
||||
return false;
|
||||
}
|
||||
return (ex.getCause() == null || neo4jServerRunning(ex.getCause()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user