Skip to content

Commit 0ac8c66

Browse files
committed
ISSUE spring-projects#20 - added more tests to cover this case
1 parent 485320b commit 0ac8c66

File tree

5 files changed

+146
-0
lines changed

5 files changed

+146
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.elasticsearch.repositories;
17+
18+
import org.junit.Before;
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.data.domain.Page;
23+
import org.springframework.data.domain.PageRequest;
24+
import org.springframework.data.domain.Sort;
25+
import org.springframework.data.elasticsearch.SampleEntity;
26+
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
27+
import org.springframework.test.context.ContextConfiguration;
28+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
29+
30+
import javax.annotation.Resource;
31+
import java.util.Arrays;
32+
import java.util.List;
33+
34+
import static org.apache.commons.lang.RandomStringUtils.random;
35+
import static org.apache.commons.lang.RandomStringUtils.randomNumeric;
36+
import static org.hamcrest.Matchers.*;
37+
import static org.junit.Assert.assertThat;
38+
39+
/**
40+
* @author Artur Konczak
41+
*/
42+
@RunWith(SpringJUnit4ClassRunner.class)
43+
@ContextConfiguration("classpath:complex-custom-method-repository-test.xml")
44+
public class ComplexCustomMethodRepositoryTests {
45+
46+
@Resource
47+
private ComplexElasticsearchRepository complexRepository;
48+
49+
@Autowired
50+
private ElasticsearchTemplate elasticsearchTemplate;
51+
52+
@Before
53+
public void before() {
54+
elasticsearchTemplate.deleteIndex(SampleEntity.class);
55+
elasticsearchTemplate.createIndex(SampleEntity.class);
56+
elasticsearchTemplate.refresh(SampleEntity.class, true);
57+
}
58+
59+
@Test
60+
public void shouldExecuteComplexCustomMethod() {
61+
//Given
62+
63+
//When
64+
String result = complexRepository.doSomethingSpecial();
65+
//Then
66+
assertThat(result, is("2+2=4"));
67+
68+
}
69+
70+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.elasticsearch.repositories;
17+
18+
import org.springframework.data.elasticsearch.SampleEntity;
19+
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
20+
21+
/**
22+
* @author Artur Konczak
23+
*/
24+
public interface ComplexElasticsearchRepository extends ElasticsearchRepository<SampleEntity, String>, ComplexElasticsearchRepositoryCustom {
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.springframework.data.elasticsearch.repositories;
2+
3+
/**
4+
* @author Artur Konczak
5+
*/
6+
public interface ComplexElasticsearchRepositoryCustom {
7+
8+
public String doSomethingSpecial();
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.springframework.data.elasticsearch.repositories.impl;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
5+
import org.springframework.data.elasticsearch.repositories.ComplexElasticsearchRepositoryCustom;
6+
7+
/**
8+
* @author Artur Konczak
9+
*/
10+
public class ComplexElasticsearchRepositoryImpl implements ComplexElasticsearchRepositoryCustom {
11+
12+
@Autowired
13+
private ElasticsearchTemplate template;
14+
15+
@Override
16+
public String doSomethingSpecial() {
17+
assert(template.getElasticsearchConverter()!=null);
18+
return "2+2=4";
19+
}
20+
21+
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
5+
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
6+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
7+
8+
<import resource="infrastructure.xml" />
9+
10+
<bean name="elasticsearchTemplate"
11+
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
12+
<constructor-arg name="client" ref="client" />
13+
</bean>
14+
15+
<elasticsearch:repositories
16+
base-package="org.springframework.data.elasticsearch.repositories" />
17+
18+
</beans>

0 commit comments

Comments
 (0)