From 0ac8c6698e149f3f1758b59267f04c348c086051 Mon Sep 17 00:00:00 2001 From: Artur Konczak Date: Fri, 1 Nov 2013 13:51:13 +0000 Subject: [PATCH] ISSUE #20 - added more tests to cover this case --- .../ComplexCustomMethodRepositoryTests.java | 70 +++++++++++++++++++ .../ComplexElasticsearchRepository.java | 26 +++++++ .../ComplexElasticsearchRepositoryCustom.java | 10 +++ .../ComplexElasticsearchRepositoryImpl.java | 22 ++++++ .../complex-custom-method-repository-test.xml | 18 +++++ 5 files changed, 146 insertions(+) create mode 100644 src/test/java/org/springframework/data/elasticsearch/repositories/ComplexCustomMethodRepositoryTests.java create mode 100644 src/test/java/org/springframework/data/elasticsearch/repositories/ComplexElasticsearchRepository.java create mode 100644 src/test/java/org/springframework/data/elasticsearch/repositories/ComplexElasticsearchRepositoryCustom.java create mode 100644 src/test/java/org/springframework/data/elasticsearch/repositories/impl/ComplexElasticsearchRepositoryImpl.java create mode 100644 src/test/resources/complex-custom-method-repository-test.xml diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexCustomMethodRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexCustomMethodRepositoryTests.java new file mode 100644 index 000000000..0e9058a0f --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexCustomMethodRepositoryTests.java @@ -0,0 +1,70 @@ +/* + * 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.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +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 java.util.Arrays; +import java.util.List; + +import static org.apache.commons.lang.RandomStringUtils.random; +import static org.apache.commons.lang.RandomStringUtils.randomNumeric; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.assertThat; + +/** + * @author Artur Konczak + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("classpath:complex-custom-method-repository-test.xml") +public class ComplexCustomMethodRepositoryTests { + + @Resource + private ComplexElasticsearchRepository 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("2+2=4")); + + } + +} diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexElasticsearchRepository.java b/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexElasticsearchRepository.java new file mode 100644 index 000000000..c23bc918d --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexElasticsearchRepository.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 ComplexElasticsearchRepository extends ElasticsearchRepository, ComplexElasticsearchRepositoryCustom { + +} diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexElasticsearchRepositoryCustom.java b/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexElasticsearchRepositoryCustom.java new file mode 100644 index 000000000..b1adbff9f --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/ComplexElasticsearchRepositoryCustom.java @@ -0,0 +1,10 @@ +package org.springframework.data.elasticsearch.repositories; + +/** + * @author Artur Konczak + */ +public interface ComplexElasticsearchRepositoryCustom { + + public String doSomethingSpecial(); + +} diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/impl/ComplexElasticsearchRepositoryImpl.java b/src/test/java/org/springframework/data/elasticsearch/repositories/impl/ComplexElasticsearchRepositoryImpl.java new file mode 100644 index 000000000..c72c5693e --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/impl/ComplexElasticsearchRepositoryImpl.java @@ -0,0 +1,22 @@ +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 ComplexElasticsearchRepositoryImpl implements ComplexElasticsearchRepositoryCustom { + + @Autowired + private ElasticsearchTemplate template; + + @Override + public String doSomethingSpecial() { + assert(template.getElasticsearchConverter()!=null); + return "2+2=4"; + } + + +} diff --git a/src/test/resources/complex-custom-method-repository-test.xml b/src/test/resources/complex-custom-method-repository-test.xml new file mode 100644 index 000000000..316af0b9d --- /dev/null +++ b/src/test/resources/complex-custom-method-repository-test.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + \ No newline at end of file