-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#152 - Made Interval usable as a JPA embeddable.
Added a no-arg constructor required by JPA to Interval to allow the usage of the class as embeddable.
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/test/java/org/salespointframework/time/IntervalIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.salespointframework.time; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import lombok.Data; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import javax.persistence.Embedded; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
import org.junit.Test; | ||
import org.salespointframework.AbstractIntegrationTests; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* Integration tests for {@link Interval} | ||
* | ||
* @author Oliver Gierke | ||
*/ | ||
public class IntervalIntegrationTests extends AbstractIntegrationTests { | ||
|
||
@Autowired SomeEntityRepository repository; | ||
@Autowired EntityManager em; | ||
|
||
/** | ||
* @see #152 | ||
*/ | ||
@Test | ||
public void intervalCanBePersistedAsEmbeddable() { | ||
|
||
LocalDateTime now = LocalDateTime.now(); | ||
|
||
SomeEntity entity = new SomeEntity(); | ||
entity.interval = Interval.from(now).to(now.plusDays(1)); | ||
|
||
repository.save(entity); | ||
em.flush(); | ||
em.clear(); | ||
|
||
SomeEntity result = repository.findOne(entity.id); | ||
assertThat(result.interval).isEqualTo(entity.interval); | ||
} | ||
|
||
@Data | ||
@Entity | ||
static class SomeEntity { | ||
|
||
@Id @GeneratedValue Long id; | ||
@Embedded Interval interval; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/java/org/salespointframework/time/SomeEntityRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.salespointframework.time; | ||
|
||
import org.salespointframework.time.IntervalIntegrationTests.SomeEntity; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
/** | ||
* Repository interface for {@link SomeEntity}. | ||
* | ||
* @author Oliver Gierke | ||
*/ | ||
public interface SomeEntityRepository extends CrudRepository<SomeEntity, Long> {} |