diff --git a/src/main/java/org/springframework/data/jpa/domain/support/Jsr310JpaConverters.java b/src/main/java/org/springframework/data/jpa/convert/threeten/Jsr310JpaConverters.java similarity index 97% rename from src/main/java/org/springframework/data/jpa/domain/support/Jsr310JpaConverters.java rename to src/main/java/org/springframework/data/jpa/convert/threeten/Jsr310JpaConverters.java index 696e919ae..20960ac91 100644 --- a/src/main/java/org/springframework/data/jpa/domain/support/Jsr310JpaConverters.java +++ b/src/main/java/org/springframework/data/jpa/convert/threeten/Jsr310JpaConverters.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.jpa.domain.support; +package org.springframework.data.jpa.convert.threeten; import java.time.Instant; import java.time.LocalDate; diff --git a/src/main/java/org/springframework/data/jpa/domain/support/ThreeTenBackPortJpaConverters.java b/src/main/java/org/springframework/data/jpa/convert/threetenbp/ThreeTenBackPortJpaConverters.java similarity index 98% rename from src/main/java/org/springframework/data/jpa/domain/support/ThreeTenBackPortJpaConverters.java rename to src/main/java/org/springframework/data/jpa/convert/threetenbp/ThreeTenBackPortJpaConverters.java index 456a3bd37..efb4333a6 100644 --- a/src/main/java/org/springframework/data/jpa/domain/support/ThreeTenBackPortJpaConverters.java +++ b/src/main/java/org/springframework/data/jpa/convert/threetenbp/ThreeTenBackPortJpaConverters.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.jpa.domain.support; +package org.springframework.data.jpa.convert.threetenbp; import java.util.Date; diff --git a/src/test/java/org/springframework/data/jpa/domain/support/DateTimeSample.java b/src/test/java/org/springframework/data/jpa/convert/threeten/DateTimeSample.java similarity index 78% rename from src/test/java/org/springframework/data/jpa/domain/support/DateTimeSample.java rename to src/test/java/org/springframework/data/jpa/convert/threeten/DateTimeSample.java index 32c695c42..30cfd78bd 100644 --- a/src/test/java/org/springframework/data/jpa/domain/support/DateTimeSample.java +++ b/src/test/java/org/springframework/data/jpa/convert/threeten/DateTimeSample.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.jpa.domain.support; +package org.springframework.data.jpa.convert.threeten; import java.time.Instant; import java.time.LocalDate; @@ -35,9 +35,4 @@ public class DateTimeSample { LocalDate localDate; LocalTime localTime; LocalDateTime localDateTime; - - org.threeten.bp.Instant bpInstant; - org.threeten.bp.LocalDate bpLocalDate; - org.threeten.bp.LocalTime bpLocalTime; - org.threeten.bp.LocalDateTime bpLocalDateTime; } diff --git a/src/test/java/org/springframework/data/jpa/domain/support/Jsr310JpaConvertersIntegrationTests.java b/src/test/java/org/springframework/data/jpa/convert/threeten/Jsr310JpaConvertersIntegrationTests.java similarity index 76% rename from src/test/java/org/springframework/data/jpa/domain/support/Jsr310JpaConvertersIntegrationTests.java rename to src/test/java/org/springframework/data/jpa/convert/threeten/Jsr310JpaConvertersIntegrationTests.java index 1982a4e97..5c851df49 100644 --- a/src/test/java/org/springframework/data/jpa/domain/support/Jsr310JpaConvertersIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/convert/threeten/Jsr310JpaConvertersIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.jpa.domain.support; +package org.springframework.data.jpa.convert.threeten; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; @@ -29,14 +29,29 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.junit.Test; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.domain.support.AbstractAttributeConverterIntegrationTests; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.transaction.annotation.Transactional; /** * Integration tests for {@link Jsr310JpaConverters}. * * @author Oliver Gierke */ +@ContextConfiguration +@Transactional public class Jsr310JpaConvertersIntegrationTests extends AbstractAttributeConverterIntegrationTests { + @Configuration + static class Config extends InfrastructureConfig { + + @Override + protected String getPackageName() { + return getClass().getPackage().getName(); + } + } + @PersistenceContext EntityManager em; /** diff --git a/src/test/java/org/springframework/data/jpa/convert/threetenbp/DateTimeSample.java b/src/test/java/org/springframework/data/jpa/convert/threetenbp/DateTimeSample.java new file mode 100644 index 000000000..0628cecab --- /dev/null +++ b/src/test/java/org/springframework/data/jpa/convert/threetenbp/DateTimeSample.java @@ -0,0 +1,39 @@ +/* + * Copyright 2014-2015 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.jpa.convert.threetenbp; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.threeten.bp.Instant; +import org.threeten.bp.LocalDate; +import org.threeten.bp.LocalDateTime; +import org.threeten.bp.LocalTime; + +/** + * @author Oliver Gierke + */ +@Entity +public class DateTimeSample { + + @Id @GeneratedValue Long id; + + Instant instant; + LocalDate localDate; + LocalTime localTime; + LocalDateTime localDateTime; +} diff --git a/src/test/java/org/springframework/data/jpa/domain/support/ThreeTenBackPortJpaConvertersIntegrationTests.java b/src/test/java/org/springframework/data/jpa/convert/threetenbp/ThreeTenBackPortJpaConvertersIntegrationTests.java similarity index 64% rename from src/test/java/org/springframework/data/jpa/domain/support/ThreeTenBackPortJpaConvertersIntegrationTests.java rename to src/test/java/org/springframework/data/jpa/convert/threetenbp/ThreeTenBackPortJpaConvertersIntegrationTests.java index 2b355b36a..32d79f622 100644 --- a/src/test/java/org/springframework/data/jpa/domain/support/ThreeTenBackPortJpaConvertersIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/convert/threetenbp/ThreeTenBackPortJpaConvertersIntegrationTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.jpa.domain.support; +package org.springframework.data.jpa.convert.threetenbp; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; @@ -24,6 +24,10 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.junit.Test; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.domain.support.AbstractAttributeConverterIntegrationTests; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.transaction.annotation.Transactional; import org.threeten.bp.Instant; import org.threeten.bp.LocalDate; import org.threeten.bp.LocalDateTime; @@ -35,8 +39,19 @@ import org.threeten.bp.LocalTime; * @author Oliver Gierke * @since 1.8 */ +@ContextConfiguration +@Transactional public class ThreeTenBackPortJpaConvertersIntegrationTests extends AbstractAttributeConverterIntegrationTests { + @Configuration + static class Config extends InfrastructureConfig { + + @Override + protected String getPackageName() { + return getClass().getPackage().getName(); + } + } + @PersistenceContext EntityManager em; /** @@ -49,10 +64,10 @@ public class ThreeTenBackPortJpaConvertersIntegrationTests extends AbstractAttri DateTimeSample sample = new DateTimeSample(); - sample.bpInstant = Instant.now(); - sample.bpLocalDate = LocalDate.now(); - sample.bpLocalTime = LocalTime.now(); - sample.bpLocalDateTime = LocalDateTime.now(); + sample.instant = Instant.now(); + sample.localDate = LocalDate.now(); + sample.localTime = LocalTime.now(); + sample.localDateTime = LocalDateTime.now(); em.persist(sample); em.clear(); @@ -60,9 +75,9 @@ public class ThreeTenBackPortJpaConvertersIntegrationTests extends AbstractAttri DateTimeSample result = em.find(DateTimeSample.class, sample.id); assertThat(result, is(notNullValue())); - assertThat(result.bpInstant, is(sample.bpInstant)); - assertThat(result.bpLocalDate, is(sample.bpLocalDate)); - assertThat(result.bpLocalTime, is(sample.bpLocalTime)); - assertThat(result.bpLocalDateTime, is(sample.bpLocalDateTime)); + assertThat(result.instant, is(sample.instant)); + assertThat(result.localDate, is(sample.localDate)); + assertThat(result.localTime, is(sample.localTime)); + assertThat(result.localDateTime, is(sample.localDateTime)); } } diff --git a/src/test/java/org/springframework/data/jpa/domain/support/AbstractAttributeConverterIntegrationTests.java b/src/test/java/org/springframework/data/jpa/domain/support/AbstractAttributeConverterIntegrationTests.java index b0be657a3..2073bc803 100644 --- a/src/test/java/org/springframework/data/jpa/domain/support/AbstractAttributeConverterIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/domain/support/AbstractAttributeConverterIntegrationTests.java @@ -20,7 +20,6 @@ import javax.sql.DataSource; import org.junit.runner.RunWith; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.domain.sample.User; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; @@ -29,10 +28,8 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter; import org.springframework.orm.jpa.vendor.Database; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.annotation.Transactional; /** * Base class for integration tests for JPA 2.1 {@link AttributeConverter} integration. @@ -40,15 +37,12 @@ import org.springframework.transaction.annotation.Transactional; * @author Oliver Gierke */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@Transactional public abstract class AbstractAttributeConverterIntegrationTests { - @Configuration - static class Config { + protected abstract static class InfrastructureConfig { @Bean - public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + LocalContainerEntityManagerFactoryBean entityManagerFactory() { AbstractJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); vendorAdapter.setDatabase(Database.HSQL); @@ -56,18 +50,22 @@ public abstract class AbstractAttributeConverterIntegrationTests { LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setDataSource(dataSource()); - factory.setPackagesToScan(getClass().getPackage().getName(), User.class.getPackage().getName()); + factory.setPackagesToScan(getPackageName(), User.class.getPackage().getName()); factory.setJpaVendorAdapter(vendorAdapter); return factory; } - public @Bean PlatformTransactionManager transactionManager() { + @Bean + PlatformTransactionManager transactionManager() { return new JpaTransactionManager(); } - public @Bean DataSource dataSource() { + @Bean + DataSource dataSource() { return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL).build(); } + + protected abstract String getPackageName(); } }