diff --git a/src/test/java/org/springframework/data/redis/repository/cdi/CdiExtensionIntegrationTests.java b/src/test/java/org/springframework/data/redis/repository/cdi/CdiExtensionIntegrationTests.java index c5ac3cfb3..2eb5cff47 100644 --- a/src/test/java/org/springframework/data/redis/repository/cdi/CdiExtensionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/repository/cdi/CdiExtensionIntegrationTests.java @@ -1,102 +1,102 @@ -/* - * Copyright 2016-2017 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.redis.repository.cdi; - -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -import java.util.List; -import java.util.Set; - -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.inject.spi.Bean; - -import org.apache.webbeans.cditest.CdiTestContainer; -import org.apache.webbeans.cditest.CdiTestContainerLoader; -import org.junit.BeforeClass; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Integration tests for Spring Data Redis CDI extension. - * - * @author Mark Paluch - */ -public class CdiExtensionIntegrationTests { - - private static Logger LOGGER = LoggerFactory.getLogger(CdiExtensionIntegrationTests.class); - - static CdiTestContainer container; - - @BeforeClass - public static void setUp() throws Exception { - - container = CdiTestContainerLoader.getCdiContainer(); - container.bootContainer(); - - LOGGER.debug("CDI container bootstrapped!"); - } - - @Test // DATAREDIS-425 - @SuppressWarnings("rawtypes") - public void beanShouldBeRegistered() { - - Set> beans = container.getBeanManager().getBeans(PersonRepository.class); - - assertThat(beans, hasSize(1)); - assertThat(beans.iterator().next().getScope(), is(equalTo((Class) ApplicationScoped.class))); - } - - @Test // DATAREDIS-425 - public void saveAndFindUnqualified() { - - RepositoryConsumer repositoryConsumer = container.getInstance(RepositoryConsumer.class); - repositoryConsumer.deleteAll(); - - Person person = new Person(); - person.setName("foo"); - repositoryConsumer.getUnqualifiedRepo().save(person); - List result = repositoryConsumer.getUnqualifiedRepo().findByName("foo"); - - assertThat(result, contains(person)); - } - - @Test // DATAREDIS-425 - public void saveAndFindQualified() { - - RepositoryConsumer repositoryConsumer = container.getInstance(RepositoryConsumer.class); - repositoryConsumer.deleteAll(); - - Person person = new Person(); - person.setName("foo"); - repositoryConsumer.getUnqualifiedRepo().save(person); - List result = repositoryConsumer.getQualifiedRepo().findByName("foo"); - - assertThat(result, contains(person)); - } - - - @Test // DATAREDIS-425 - public void callMethodOnCustomRepositoryShouldSuceed() { - - RepositoryConsumer repositoryConsumer = container.getInstance(RepositoryConsumer.class); - - int result = repositoryConsumer.getUnqualifiedRepo().returnOne(); - assertThat(result, is(1)); - } - -} +/* + * Copyright 2016-2017 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.redis.repository.cdi; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import java.util.List; +import java.util.Set; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.spi.Bean; + +import org.apache.webbeans.cditest.CdiTestContainer; +import org.apache.webbeans.cditest.CdiTestContainerLoader; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Integration tests for Spring Data Redis CDI extension. + * + * @author Mark Paluch + */ +public class CdiExtensionIntegrationTests { + + private static Logger LOGGER = LoggerFactory.getLogger(CdiExtensionIntegrationTests.class); + + static CdiTestContainer container; + + @BeforeClass + public static void setUp() throws Exception { + + container = CdiTestContainerLoader.getCdiContainer(); + container.bootContainer(); + + LOGGER.debug("CDI container bootstrapped!"); + } + + @Test // DATAREDIS-425 + @SuppressWarnings("rawtypes") + public void beanShouldBeRegistered() { + + Set> beans = container.getBeanManager().getBeans(PersonRepository.class); + + assertThat(beans, hasSize(1)); + assertThat(beans.iterator().next().getScope(), is(equalTo((Class) ApplicationScoped.class))); + } + + @Test // DATAREDIS-425 + public void saveAndFindUnqualified() { + + RepositoryConsumer repositoryConsumer = container.getInstance(RepositoryConsumer.class); + repositoryConsumer.deleteAll(); + + Person person = new Person(); + person.setName("foo"); + repositoryConsumer.getUnqualifiedRepo().save(person); + List result = repositoryConsumer.getUnqualifiedRepo().findByName("foo"); + + assertThat(result, contains(person)); + } + + @Test // DATAREDIS-425 + public void saveAndFindQualified() { + + RepositoryConsumer repositoryConsumer = container.getInstance(RepositoryConsumer.class); + repositoryConsumer.deleteAll(); + + Person person = new Person(); + person.setName("foo"); + repositoryConsumer.getUnqualifiedRepo().save(person); + List result = repositoryConsumer.getQualifiedRepo().findByName("foo"); + + assertThat(result, contains(person)); + } + + + @Test // DATAREDIS-425 + public void callMethodOnCustomRepositoryShouldSuceed() { + + RepositoryConsumer repositoryConsumer = container.getInstance(RepositoryConsumer.class); + + int result = repositoryConsumer.getUnqualifiedRepo().returnOne(); + assertThat(result, is(1)); + } + +} diff --git a/src/test/java/org/springframework/data/redis/repository/cdi/Person.java b/src/test/java/org/springframework/data/redis/repository/cdi/Person.java index 324ae3cb5..945a54c4f 100644 --- a/src/test/java/org/springframework/data/redis/repository/cdi/Person.java +++ b/src/test/java/org/springframework/data/redis/repository/cdi/Person.java @@ -1,68 +1,68 @@ -/* - * Copyright 2016 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.redis.repository.cdi; - -import org.springframework.data.annotation.Id; -import org.springframework.data.redis.core.RedisHash; -import org.springframework.data.redis.core.index.Indexed; - -/** - * @author Mark Paluch - */ -@RedisHash -class Person { - - @Id private String id; - - @Indexed private String name; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof Person)) - return false; - - Person person = (Person) o; - - if (id != null ? !id.equals(person.id) : person.id != null) - return false; - return name != null ? name.equals(person.name) : person.name == null; - } - - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } -} +/* + * Copyright 2016 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.redis.repository.cdi; + +import org.springframework.data.annotation.Id; +import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; + +/** + * @author Mark Paluch + */ +@RedisHash +class Person { + + @Id private String id; + + @Indexed private String name; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof Person)) + return false; + + Person person = (Person) o; + + if (id != null ? !id.equals(person.id) : person.id != null) + return false; + return name != null ? name.equals(person.name) : person.name == null; + } + + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } +} diff --git a/src/test/java/org/springframework/data/redis/repository/cdi/PersonDB.java b/src/test/java/org/springframework/data/redis/repository/cdi/PersonDB.java index 34aee2c29..da7e42a30 100644 --- a/src/test/java/org/springframework/data/redis/repository/cdi/PersonDB.java +++ b/src/test/java/org/springframework/data/redis/repository/cdi/PersonDB.java @@ -1,33 +1,33 @@ -/* - * Copyright 2016 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.redis.repository.cdi; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.inject.Qualifier; - -/** - * @author Mark Paluch - */ -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER }) -@interface PersonDB { - -} +/* + * Copyright 2016 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.redis.repository.cdi; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * @author Mark Paluch + */ +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER }) +@interface PersonDB { + +} diff --git a/src/test/java/org/springframework/data/redis/repository/cdi/PersonRepository.java b/src/test/java/org/springframework/data/redis/repository/cdi/PersonRepository.java index 287d66c2a..5d50339dd 100644 --- a/src/test/java/org/springframework/data/redis/repository/cdi/PersonRepository.java +++ b/src/test/java/org/springframework/data/redis/repository/cdi/PersonRepository.java @@ -1,33 +1,33 @@ -/* - * Copyright 2016 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.redis.repository.cdi; - -import java.util.List; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.cdi.Eager; - -/** - * @author Mark Paluch - */ -@Eager -public interface PersonRepository extends CrudRepository, PersonRepositoryCustom { - - List findAll(); - - List findByName(String name); - -} +/* + * Copyright 2016 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.redis.repository.cdi; + +import java.util.List; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.cdi.Eager; + +/** + * @author Mark Paluch + */ +@Eager +public interface PersonRepository extends CrudRepository, PersonRepositoryCustom { + + List findAll(); + + List findByName(String name); + +} diff --git a/src/test/java/org/springframework/data/redis/repository/cdi/RepositoryConsumer.java b/src/test/java/org/springframework/data/redis/repository/cdi/RepositoryConsumer.java index d12edd465..d7125bb78 100644 --- a/src/test/java/org/springframework/data/redis/repository/cdi/RepositoryConsumer.java +++ b/src/test/java/org/springframework/data/redis/repository/cdi/RepositoryConsumer.java @@ -1,42 +1,42 @@ -/* - * Copyright 2016 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.redis.repository.cdi; - -import javax.inject.Inject; - -/** - * @author Mark Paluch - */ -class RepositoryConsumer { - - @Inject PersonRepository unqualifiedRepo; - @Inject @PersonDB PersonRepository qualifiedRepo; - - public PersonRepository getUnqualifiedRepo() { - return unqualifiedRepo; - } - - public PersonRepository getQualifiedRepo() { - return qualifiedRepo; - } - - public void deleteAll() { - - unqualifiedRepo.deleteAll(); - qualifiedRepo.deleteAll(); - } - -} +/* + * Copyright 2016 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.redis.repository.cdi; + +import javax.inject.Inject; + +/** + * @author Mark Paluch + */ +class RepositoryConsumer { + + @Inject PersonRepository unqualifiedRepo; + @Inject @PersonDB PersonRepository qualifiedRepo; + + public PersonRepository getUnqualifiedRepo() { + return unqualifiedRepo; + } + + public PersonRepository getQualifiedRepo() { + return qualifiedRepo; + } + + public void deleteAll() { + + unqualifiedRepo.deleteAll(); + qualifiedRepo.deleteAll(); + } + +} diff --git a/src/test/resources/META-INF/beans.xml b/src/test/resources/META-INF/beans.xml index 73ae3a251..71dc6db1f 100644 --- a/src/test/resources/META-INF/beans.xml +++ b/src/test/resources/META-INF/beans.xml @@ -1,6 +1,6 @@ - - - - + + + +