ISSUE #20 - added more tests to cover this case

This commit is contained in:
Artur Konczak 2013-11-01 13:51:13 +00:00
parent 485320b388
commit 0ac8c6698e
5 changed files with 146 additions and 0 deletions

View File

@ -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"));
}
}

View File

@ -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<SampleEntity, String>, ComplexElasticsearchRepositoryCustom {
}

View File

@ -0,0 +1,10 @@
package org.springframework.data.elasticsearch.repositories;
/**
* @author Artur Konczak
*/
public interface ComplexElasticsearchRepositoryCustom {
public String doSomethingSpecial();
}

View File

@ -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";
}
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml" />
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client" />
</bean>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories" />
</beans>