From e5cda040b0b66d5ab7a9d54eea2e9d8f07a8f9b5 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 1 Jun 2014 13:11:25 +0100 Subject: [PATCH] Restore test classes Restore test classes accidentally deleted and ignored in c43fd04f3e. --- spring-boot-autoconfigure/.gitignore | 2 +- ...rchRepositoriesAutoConfigurationTests.java | 105 ++++++++++++++++++ .../CityElasticsearchDbRepository.java | 24 ++++ .../data/alt/jpa/CityJpaRepository.java | 24 ++++ .../data/alt/mongo/CityMongoDbRepository.java | 24 ++++ .../data/alt/solr/CitySolrRepository.java | 24 ++++ .../data/elasticsearch/City.java | 69 ++++++++++++ .../data/elasticsearch/CityRepository.java | 32 ++++++ .../data/empty/EmptyDataPackage.java | 26 +++++ .../.gitignore | 2 +- 10 files changed, 330 insertions(+), 2 deletions(-) create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfigurationTests.java create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/elasticsearch/CityElasticsearchDbRepository.java create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/jpa/CityJpaRepository.java create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/mongo/CityMongoDbRepository.java create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/solr/CitySolrRepository.java create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/City.java create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/CityRepository.java create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/empty/EmptyDataPackage.java diff --git a/spring-boot-autoconfigure/.gitignore b/spring-boot-autoconfigure/.gitignore index 1269488f7fb..3af0ccb687b 100644 --- a/spring-boot-autoconfigure/.gitignore +++ b/spring-boot-autoconfigure/.gitignore @@ -1 +1 @@ -data +/data diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfigurationTests.java new file mode 100644 index 00000000000..4c27d8a1ba1 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/ElasticsearchRepositoriesAutoConfigurationTests.java @@ -0,0 +1,105 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.data; + +import org.elasticsearch.client.Client; +import org.junit.After; +import org.junit.Test; +import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.data.alt.elasticsearch.CityElasticsearchDbRepository; +import org.springframework.boot.autoconfigure.data.elasticsearch.City; +import org.springframework.boot.autoconfigure.data.elasticsearch.CityRepository; +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.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; + +import static org.junit.Assert.assertNotNull; + +/** + * Tests for {@link ElasticsearchRepositoriesAutoConfiguration}. + * + * @author Phillip Webb + */ +public class ElasticsearchRepositoriesAutoConfigurationTests { + + private AnnotationConfigApplicationContext context; + + @After + public void close() { + this.context.close(); + } + + @Test + public void testDefaultRepositoryConfiguration() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(TestConfiguration.class, + ElasticsearchAutoConfiguration.class, + ElasticsearchRepositoriesAutoConfiguration.class, + ElasticsearchDataAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(CityRepository.class)); + assertNotNull(this.context.getBean(Client.class)); + } + + @Test + public void testNoRepositoryConfiguration() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(EmptyConfiguration.class, + ElasticsearchAutoConfiguration.class, + ElasticsearchRepositoriesAutoConfiguration.class, + ElasticsearchDataAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(Client.class)); + } + + @Test + public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(CustomizedConfiguration.class, + ElasticsearchAutoConfiguration.class, + ElasticsearchRepositoriesAutoConfiguration.class, + ElasticsearchDataAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(CityElasticsearchDbRepository.class)); + } + + @Configuration + @TestAutoConfigurationPackage(City.class) + protected static class TestConfiguration { + + } + + @Configuration + @TestAutoConfigurationPackage(EmptyDataPackage.class) + protected static class EmptyConfiguration { + + } + + @Configuration + @TestAutoConfigurationPackage(ElasticsearchRepositoriesAutoConfigurationTests.class) + @EnableElasticsearchRepositories(basePackageClasses = CityElasticsearchDbRepository.class) + protected static class CustomizedConfiguration { + + } +} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/elasticsearch/CityElasticsearchDbRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/elasticsearch/CityElasticsearchDbRepository.java new file mode 100644 index 00000000000..e5ec2311f78 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/elasticsearch/CityElasticsearchDbRepository.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.data.alt.elasticsearch; + +import org.springframework.boot.autoconfigure.data.elasticsearch.City; +import org.springframework.data.repository.Repository; + +public interface CityElasticsearchDbRepository extends Repository { + +} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/jpa/CityJpaRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/jpa/CityJpaRepository.java new file mode 100644 index 00000000000..18cf20af74b --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/jpa/CityJpaRepository.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.data.alt.jpa; + +import org.springframework.boot.autoconfigure.data.jpa.City; +import org.springframework.data.repository.Repository; + +public interface CityJpaRepository extends Repository { + +} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/mongo/CityMongoDbRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/mongo/CityMongoDbRepository.java new file mode 100644 index 00000000000..4a7702c22a4 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/mongo/CityMongoDbRepository.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.data.alt.mongo; + +import org.springframework.boot.autoconfigure.data.mongo.City; +import org.springframework.data.repository.Repository; + +public interface CityMongoDbRepository extends Repository { + +} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/solr/CitySolrRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/solr/CitySolrRepository.java new file mode 100644 index 00000000000..7c49a0b1fc3 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/solr/CitySolrRepository.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.data.alt.solr; + +import org.springframework.boot.autoconfigure.data.solr.City; +import org.springframework.data.repository.Repository; + +public interface CitySolrRepository extends Repository { + +} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/City.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/City.java new file mode 100644 index 00000000000..45051d3206f --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/City.java @@ -0,0 +1,69 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.data.elasticsearch; + +import java.io.Serializable; + +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; + +@Document(indexName = "city", type = "city", shards = 1, replicas = 0, refreshInterval = "-1") +public class City implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + private Long id; + + private String name; + + private String state; + + private String country; + + private String map; + + protected City() { + } + + public City(String name, String country) { + super(); + this.name = name; + this.country = country; + } + + public String getName() { + return this.name; + } + + public String getState() { + return this.state; + } + + public String getCountry() { + return this.country; + } + + public String getMap() { + return this.map; + } + + @Override + public String toString() { + return getName() + "," + getState() + "," + getCountry(); + } +} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/CityRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/CityRepository.java new file mode 100644 index 00000000000..217999948f8 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/CityRepository.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.data.elasticsearch; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.repository.Repository; + +public interface CityRepository extends Repository { + + Page findAll(Pageable pageable); + + Page findByNameLikeAndCountryLikeAllIgnoringCase(String name, String country, + Pageable pageable); + + City findByNameAndCountryAllIgnoringCase(String name, String country); + +} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/empty/EmptyDataPackage.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/empty/EmptyDataPackage.java new file mode 100644 index 00000000000..ab8c6520a32 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/empty/EmptyDataPackage.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.data.empty; + +/** + * Empty package used with data tests. + * + * @author Phillip Webb + */ +public class EmptyDataPackage { + +} diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/.gitignore b/spring-boot-samples/spring-boot-sample-data-elasticsearch/.gitignore index 1269488f7fb..3af0ccb687b 100644 --- a/spring-boot-samples/spring-boot-sample-data-elasticsearch/.gitignore +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/.gitignore @@ -1 +1 @@ -data +/data