DATAES-113 Add support for custom implementations in CDI repositories

This commit is contained in:
Mark Paluch
2014-08-07 20:43:53 +02:00
committed by Mohsin Husen
parent 1f99dcb911
commit b77b8ba0f2
7 changed files with 124 additions and 6 deletions

View File

@@ -24,6 +24,8 @@ import javax.inject.Inject;
class CdiRepositoryClient {
private CdiProductRepository repository;
private SamplePersonRepository samplePersonRepository;
public CdiProductRepository getRepository() {
return repository;
@@ -33,4 +35,13 @@ class CdiRepositoryClient {
public void setRepository(CdiProductRepository repository) {
this.repository = repository;
}
public SamplePersonRepository getSamplePersonRepository() {
return samplePersonRepository;
}
@Inject
public void setSamplePersonRepository(SamplePersonRepository samplePersonRepository) {
this.samplePersonRepository = samplePersonRepository;
}
}

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.elasticsearch.repositories.cdi;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import org.apache.webbeans.cditest.CdiTestContainer;
@@ -33,6 +34,7 @@ public class CdiRepositoryTests {
private static CdiTestContainer cdiContainer;
private CdiProductRepository repository;
private SamplePersonRepository personRepository;
@BeforeClass
public static void init() throws Exception {
@@ -51,6 +53,7 @@ public class CdiRepositoryTests {
public void setUp() {
CdiRepositoryClient client = cdiContainer.getInstance(CdiRepositoryClient.class);
repository = client.getRepository();
personRepository = client.getSamplePersonRepository();
}
@Test
@@ -80,4 +83,13 @@ public class CdiRepositoryTests {
retrieved = repository.findOne(bean.getId());
assertNull(retrieved);
}
/**
* @see DATAES-113
*/
@Test
public void returnOneFromCustomImpl() {
assertThat(personRepository.returnOne(), is(1));
}
}

View File

@@ -0,0 +1,27 @@
/*
* Copyright 2014 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.cdi;
import org.springframework.data.elasticsearch.entities.Person;
import org.springframework.data.repository.Repository;
/**
* @author Mark Paluch
* @see DATAES-113
*/
public interface SamplePersonRepository extends Repository<Person, Long>, SamplePersonRepositoryCustom {
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2014 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.cdi;
/**
* @see DATAES-113
* @author Mark Paluch
*/
interface SamplePersonRepositoryCustom {
int returnOne();
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2014 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.cdi;
/**
* @see DATAES-113
* @author Mark Paluch
*/
class SamplePersonRepositoryImpl implements SamplePersonRepositoryCustom {
@Override
public int returnOne() {
return 1;
}
}