Prevents tests that use Elasticsearch from polluting the filesystem
By default, Elasticsearch writes it data to ./data. This led to data being left on the filesystem after a mvn clean which could cause failures when moving between branches that use different versions of Elasticsearch. This commit updates the tests for the Elasticsearch sample and the Elasticsearch auto-configuration classes to write the Elasticsearch data and logs into the target directory.
This commit is contained in:
parent
326bdf29c2
commit
dabbb02dfe
|
@ -1 +0,0 @@
|
|||
/data
|
|
@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.data.elasticsearch.city.CityReposi
|
|||
import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage;
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchDataAutoConfiguration;
|
||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||
|
@ -50,6 +51,9 @@ public class ElasticsearchRepositoriesAutoConfigurationTests {
|
|||
@Test
|
||||
public void testDefaultRepositoryConfiguration() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.data.elasticsearch.properties.path.data:target/data",
|
||||
"spring.data.elasticsearch.properties.path.logs:target/logs");
|
||||
this.context.register(TestConfiguration.class,
|
||||
ElasticsearchAutoConfiguration.class,
|
||||
ElasticsearchRepositoriesAutoConfiguration.class,
|
||||
|
@ -63,6 +67,9 @@ public class ElasticsearchRepositoriesAutoConfigurationTests {
|
|||
@Test
|
||||
public void testNoRepositoryConfiguration() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.data.elasticsearch.properties.path.data:target/data",
|
||||
"spring.data.elasticsearch.properties.path.logs:target/logs");
|
||||
this.context.register(EmptyConfiguration.class,
|
||||
ElasticsearchAutoConfiguration.class,
|
||||
ElasticsearchRepositoriesAutoConfiguration.class,
|
||||
|
@ -75,6 +82,9 @@ public class ElasticsearchRepositoriesAutoConfigurationTests {
|
|||
@Test
|
||||
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.data.elasticsearch.properties.path.data:target/data",
|
||||
"spring.data.elasticsearch.properties.path.logs:target/logs");
|
||||
this.context.register(CustomizedConfiguration.class,
|
||||
ElasticsearchAutoConfiguration.class,
|
||||
ElasticsearchRepositoriesAutoConfiguration.class,
|
||||
|
|
|
@ -56,7 +56,9 @@ public class ElasticsearchAutoConfigurationTests {
|
|||
public void createNodeClient() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.data.elasticsearch.properties.foo.bar:baz");
|
||||
"spring.data.elasticsearch.properties.foo.bar:baz",
|
||||
"spring.data.elasticsearch.properties.path.data:target/data",
|
||||
"spring.data.elasticsearch.properties.path.logs:target/logs");
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
ElasticsearchAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
@ -72,7 +74,9 @@ public class ElasticsearchAutoConfigurationTests {
|
|||
// a port and check the exception
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.data.elasticsearch.cluster-nodes:localhost");
|
||||
"spring.data.elasticsearch.cluster-nodes:localhost",
|
||||
"spring.data.elasticsearch.properties.path.data:target/data",
|
||||
"spring.data.elasticsearch.properties.path.logs:target/logs");
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
ElasticsearchAutoConfiguration.class);
|
||||
this.thrown.expect(BeanCreationException.class);
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.elasticsearch;
|
|||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
|
||||
|
@ -42,10 +43,14 @@ public class ElasticsearchDataAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void templateExists() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.data.elasticsearch.properties.path.data:target/data",
|
||||
"spring.data.elasticsearch.properties.path.logs:target/logs");
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
ElasticsearchAutoConfiguration.class,
|
||||
ElasticsearchDataAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertEquals(1,
|
||||
this.context.getBeanNamesForType(ElasticsearchTemplate.class).length);
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
/data
|
|
@ -20,6 +20,7 @@ import java.net.ConnectException;
|
|||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.core.NestedCheckedException;
|
||||
|
||||
|
@ -38,7 +39,11 @@ public class SampleElasticsearchApplicationTests {
|
|||
@Test
|
||||
public void testDefaultSettings() throws Exception {
|
||||
try {
|
||||
SampleElasticsearchApplication.main(new String[0]);
|
||||
new SpringApplicationBuilder(SampleElasticsearchApplication.class)
|
||||
.properties(
|
||||
"spring.data.elasticsearch.properties.path.data:target/data",
|
||||
"spring.data.elasticsearch.properties.path.logs:target/logs")
|
||||
.run();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
if (serverNotRunning(ex)) {
|
||||
|
|
Loading…
Reference in New Issue