Skip to content

Commit 86de8f7

Browse files
committed
ISSUE spring-projects#20 - added more tests to cover complex custom repository with manual wiring
1 parent 2e0a428 commit 86de8f7

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.elasticsearch.SampleEntity;
23+
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
24+
import org.springframework.test.context.ContextConfiguration;
25+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
26+
27+
import javax.annotation.Resource;
28+
29+
import static org.hamcrest.Matchers.is;
30+
import static org.junit.Assert.assertThat;
31+
32+
/**
33+
* @author Artur Konczak
34+
*/
35+
@RunWith(SpringJUnit4ClassRunner.class)
36+
@ContextConfiguration("classpath:complex-custom-method-repository-manual-wiring-test.xml")
37+
public class ComplexCustomMethodRepositoryManualWiringTests {
38+
39+
@Resource
40+
private ComplexElasticsearchRepositoryManualWiring complexRepository;
41+
42+
@Autowired
43+
private ElasticsearchTemplate elasticsearchTemplate;
44+
45+
@Before
46+
public void before() {
47+
elasticsearchTemplate.deleteIndex(SampleEntity.class);
48+
elasticsearchTemplate.createIndex(SampleEntity.class);
49+
elasticsearchTemplate.refresh(SampleEntity.class, true);
50+
}
51+
52+
@Test
53+
public void shouldExecuteComplexCustomMethod() {
54+
//Given
55+
56+
//When
57+
String result = complexRepository.doSomethingSpecial();
58+
//Then
59+
assertThat(result, is("3+3=6"));
60+
61+
}
62+
63+
}
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 ComplexElasticsearchRepositoryManualWiring extends ElasticsearchRepository<SampleEntity, String>, ComplexElasticsearchRepositoryCustom {
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 ComplexElasticsearchRepositoryManualWiringImpl implements ComplexElasticsearchRepositoryCustom {
11+
12+
private ElasticsearchTemplate template;
13+
14+
@Override
15+
public String doSomethingSpecial() {
16+
assert(template.getElasticsearchConverter()!=null);
17+
return "3+3=6";
18+
}
19+
20+
public void setTemplate(ElasticsearchTemplate template) {
21+
this.template = template;
22+
}
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
<bean id="complexElasticsearchRepositoryManualWiringImpl" class="org.springframework.data.elasticsearch.repositories.impl.ComplexElasticsearchRepositoryManualWiringImpl">
19+
<property name="template" ref="elasticsearchTemplate"/>
20+
</bean>
21+
22+
</beans>

0 commit comments

Comments
 (0)