From 86de8f73b8bddd8a7d18593079f383756f23ecd0 Mon Sep 17 00:00:00 2001 From: Artur Konczak Date: Fri, 1 Nov 2013 21:26:32 +0000 Subject: [PATCH] ISSUE #20 - added more tests to cover complex custom repository with manual wiring --- ...stomMethodRepositoryManualWiringTests.java | 63 +++++++++++++++++++ ...exElasticsearchRepositoryManualWiring.java | 26 ++++++++ ...asticsearchRepositoryManualWiringImpl.java | 23 +++++++ ...m-method-repository-manual-wiring-test.xml | 22 +++++++ 4 files changed, 134 insertions(+) create mode 100644 src/test/java/org/springframework/data/elasticsearch/repositories/ComplexCustomMethodRepositoryManualWiringTests.java create mode 100644 src/test/java/org/springframework/data/elasticsearch/repositories/ComplexElasticsearchRepositoryManualWiring.java create mode 100644 src/test/java/org/springframework/data/elasticsearch/repositories/impl/ComplexElasticsearchRepositoryManualWiringImpl.java create mode 100644 src/test/resources/complex-custom-method-repository-manual-wiring-test.xml diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexCustomMethodRepositoryManualWiringTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexCustomMethodRepositoryManualWiringTests.java new file mode 100644 index 000000000..77a310df6 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexCustomMethodRepositoryManualWiringTests.java @@ -0,0 +1,63 @@ +/* + * Copyright 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.data.elasticsearch.repositories; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.elasticsearch.SampleEntity; +import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import javax.annotation.Resource; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +/** + * @author Artur Konczak + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("classpath:complex-custom-method-repository-manual-wiring-test.xml") +public class ComplexCustomMethodRepositoryManualWiringTests { + + @Resource + private ComplexElasticsearchRepositoryManualWiring complexRepository; + + @Autowired + private ElasticsearchTemplate elasticsearchTemplate; + + @Before + public void before() { + elasticsearchTemplate.deleteIndex(SampleEntity.class); + elasticsearchTemplate.createIndex(SampleEntity.class); + elasticsearchTemplate.refresh(SampleEntity.class, true); + } + + @Test + public void shouldExecuteComplexCustomMethod() { + //Given + + //When + String result = complexRepository.doSomethingSpecial(); + //Then + assertThat(result, is("3+3=6")); + + } + +} diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexElasticsearchRepositoryManualWiring.java b/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexElasticsearchRepositoryManualWiring.java new file mode 100644 index 000000000..f4f854078 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexElasticsearchRepositoryManualWiring.java @@ -0,0 +1,26 @@ +/* + * Copyright 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.data.elasticsearch.repositories; + +import org.springframework.data.elasticsearch.SampleEntity; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +/** + * @author Artur Konczak + */ +public interface ComplexElasticsearchRepositoryManualWiring extends ElasticsearchRepository, ComplexElasticsearchRepositoryCustom { + +} diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/impl/ComplexElasticsearchRepositoryManualWiringImpl.java b/src/test/java/org/springframework/data/elasticsearch/repositories/impl/ComplexElasticsearchRepositoryManualWiringImpl.java new file mode 100644 index 000000000..47aad47e0 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/impl/ComplexElasticsearchRepositoryManualWiringImpl.java @@ -0,0 +1,23 @@ +package org.springframework.data.elasticsearch.repositories.impl; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; +import org.springframework.data.elasticsearch.repositories.ComplexElasticsearchRepositoryCustom; + +/** + * @author Artur Konczak + */ +public class ComplexElasticsearchRepositoryManualWiringImpl implements ComplexElasticsearchRepositoryCustom { + + private ElasticsearchTemplate template; + + @Override + public String doSomethingSpecial() { + assert(template.getElasticsearchConverter()!=null); + return "3+3=6"; + } + + public void setTemplate(ElasticsearchTemplate template) { + this.template = template; + } +} diff --git a/src/test/resources/complex-custom-method-repository-manual-wiring-test.xml b/src/test/resources/complex-custom-method-repository-manual-wiring-test.xml new file mode 100644 index 000000000..1262d4e2b --- /dev/null +++ b/src/test/resources/complex-custom-method-repository-manual-wiring-test.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + \ No newline at end of file