mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-08 13:12:10 +00:00
DATAES-576 - Fix CustomMethodRepositoryRestTests.
Register custom template bean as workaround to delete the index before repository bootstrapping.
This commit is contained in:
parent
1f04e6453c
commit
807cfe78bc
@ -30,6 +30,7 @@ import org.springframework.data.domain.Page;
|
|||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.domain.Sort.Order;
|
import org.springframework.data.domain.Sort.Order;
|
||||||
|
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||||
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
||||||
import org.springframework.data.elasticsearch.repositories.custom.SampleCustomMethodRepository;
|
import org.springframework.data.elasticsearch.repositories.custom.SampleCustomMethodRepository;
|
||||||
@ -46,7 +47,6 @@ import org.springframework.data.geo.Point;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Don Wellington
|
* @author Don Wellington
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class CustomMethodRepositoryBaseTests {
|
public abstract class CustomMethodRepositoryBaseTests {
|
||||||
|
|
||||||
@Autowired private SampleCustomMethodRepository repository;
|
@Autowired private SampleCustomMethodRepository repository;
|
||||||
|
@ -12,10 +12,13 @@
|
|||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/package org.springframework.data.elasticsearch.repositories;
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.repositories;
|
||||||
|
|
||||||
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||||
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
||||||
@ -23,13 +26,13 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Don Wellington
|
* @author Don Wellington
|
||||||
*
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@ContextConfiguration("classpath:custom-method-repository-rest-test.xml")
|
@ContextConfiguration("classpath:custom-method-repository-rest-test.xml")
|
||||||
public class CustomMethodRepositoryRestTests extends CustomMethodRepositoryBaseTests {
|
public class CustomMethodRepositoryRestTests extends CustomMethodRepositoryBaseTests {
|
||||||
|
|
||||||
@Autowired private ElasticsearchRestTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchRestTemplate elasticsearchTemplate;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -39,4 +42,18 @@ public class CustomMethodRepositoryRestTests extends CustomMethodRepositoryBaseT
|
|||||||
elasticsearchTemplate.putMapping(SampleEntity.class);
|
elasticsearchTemplate.putMapping(SampleEntity.class);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Workaround because {@link SampleEntity} is used like everywhere and there's little chance to find the place where
|
||||||
|
* the mapping is altered so that it becomes incompatible with the one created on repository startup.
|
||||||
|
* <p>
|
||||||
|
* TODO: Remove me once the cause is fixed! See: https://jira.spring.io/browse/DATAES-576
|
||||||
|
*/
|
||||||
|
public static class CleanupOnStartElasticsearchTemplate extends ElasticsearchRestTemplate {
|
||||||
|
|
||||||
|
public CleanupOnStartElasticsearchTemplate(RestHighLevelClient client) {
|
||||||
|
super(client);
|
||||||
|
deleteIndex(SampleEntity.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.repositories;
|
package org.springframework.data.elasticsearch.repositories;
|
||||||
|
|
||||||
|
import org.elasticsearch.client.Client;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||||
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
||||||
@ -24,13 +26,13 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Don Wellington
|
* @author Don Wellington
|
||||||
*
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@ContextConfiguration("classpath:custom-method-repository-test.xml")
|
@ContextConfiguration("classpath:custom-method-repository-test.xml")
|
||||||
public class CustomMethodRepositoryTests extends CustomMethodRepositoryBaseTests {
|
public class CustomMethodRepositoryTests extends CustomMethodRepositoryBaseTests {
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -40,4 +42,18 @@ public class CustomMethodRepositoryTests extends CustomMethodRepositoryBaseTests
|
|||||||
elasticsearchTemplate.putMapping(SampleEntity.class);
|
elasticsearchTemplate.putMapping(SampleEntity.class);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Workaround because {@link SampleEntity} is used like everywhere and there's little chance to find the place where
|
||||||
|
* the mapping is altered so that it becomes incompatible with the one created on repository startup.
|
||||||
|
* <p>
|
||||||
|
* TODO: Remove me once the cause is fixed! See: https://jira.spring.io/browse/DATAES-576
|
||||||
|
*/
|
||||||
|
static class CleanupOnStartElasticsearchTemplate extends ElasticsearchTemplate {
|
||||||
|
|
||||||
|
public CleanupOnStartElasticsearchTemplate(Client client) {
|
||||||
|
super(client);
|
||||||
|
deleteIndex(SampleEntity.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,14 @@
|
|||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||||
|
|
||||||
<import resource="elasticsearch-rest-template-test.xml"/>
|
<import resource="infrastructure.xml"/>
|
||||||
|
|
||||||
|
<bean name="elasticsearchTemplate"
|
||||||
|
class="org.springframework.data.elasticsearch.repositories.CustomMethodRepositoryRestTests$CleanupOnStartElasticsearchTemplate">
|
||||||
|
<constructor-arg name="client" ref="restClient"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<elasticsearch:rest-client id="restClient"/>
|
||||||
|
|
||||||
<elasticsearch:repositories
|
<elasticsearch:repositories
|
||||||
base-package="org.springframework.data.elasticsearch.repositories.custom"/>
|
base-package="org.springframework.data.elasticsearch.repositories.custom"/>
|
||||||
|
@ -8,11 +8,10 @@
|
|||||||
<import resource="infrastructure.xml"/>
|
<import resource="infrastructure.xml"/>
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
<bean name="elasticsearchTemplate"
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
class="org.springframework.data.elasticsearch.repositories.CustomMethodRepositoryTests$CleanupOnStartElasticsearchTemplate">
|
||||||
<constructor-arg name="client" ref="client"/>
|
<constructor-arg name="client" ref="client"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
<elasticsearch:repositories
|
<elasticsearch:repositories
|
||||||
base-package="org.springframework.data.elasticsearch.repositories.custom"/>
|
base-package="org.springframework.data.elasticsearch.repositories.custom"/>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user