-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to latests version for Spring dependencies
- Loading branch information
1 parent
77bbe3a
commit abb475d
Showing
34 changed files
with
1,383 additions
and
690 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
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
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
6 changes: 6 additions & 0 deletions
6
...pa/deployment/src/test/java/io/quarkus/spring/data/deployment/BookListCrudRepository.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,6 @@ | ||
package io.quarkus.spring.data.deployment; | ||
|
||
import org.springframework.data.repository.ListCrudRepository; | ||
|
||
public interface BookListCrudRepository extends ListCrudRepository<Book, Integer> { | ||
} |
79 changes: 79 additions & 0 deletions
79
...eployment/src/test/java/io/quarkus/spring/data/deployment/BookListCrudRepositoryTest.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,79 @@ | ||
package io.quarkus.spring.data.deployment; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
public class BookListCrudRepositoryTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsResource("import_books.sql", "import.sql") | ||
.addClasses(Book.class, BookListCrudRepository.class)) | ||
.withConfigurationResource("application.properties"); | ||
|
||
@Inject | ||
BookListCrudRepository repo; | ||
|
||
@Test | ||
@Order(1) | ||
@Transactional | ||
public void shouldListAllBooks() { | ||
List<Book> all = repo.findAll(); | ||
assertThat(all).isNotEmpty(); | ||
assertThat(all).hasSize(3); | ||
assertThat(all.stream().map(Book::getName)).containsExactlyInAnyOrder("Talking to Strangers", "The Ascent of Money", | ||
"A Short History of Everything"); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
@Transactional | ||
public void shouldListBooksWithIds() { | ||
List<Integer> ids = Arrays.asList(1, 2); | ||
List<Book> all = repo.findAllById(ids); | ||
assertThat(all).isNotEmpty(); | ||
assertThat(all).hasSize(2); | ||
assertThat(all.stream().map(Book::getName)).containsExactlyInAnyOrder("Talking to Strangers", "The Ascent of Money"); | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
@Transactional | ||
public void shouldSaveBooks() { | ||
Book harryPotterAndTheChamberOfSecrets = populateBook(4, "Harry Potter and the Chamber of Secrets"); | ||
Book harryPotterAndThePrisonerOfAzkaban = populateBook(5, "Harry Potter and the Prisoner of Azkaban"); | ||
Book harryPotterAndTheGlobetOfFire = populateBook(6, "Harry Potter and the Globet of Fire"); | ||
List<Book> books = Arrays.asList(harryPotterAndTheChamberOfSecrets, harryPotterAndThePrisonerOfAzkaban, | ||
harryPotterAndTheGlobetOfFire); | ||
List<Book> all = repo.saveAll(books); | ||
assertThat(all).isNotEmpty(); | ||
assertThat(all).hasSize(3); | ||
assertThat(all.stream().map(Book::getName)).containsExactlyInAnyOrder("Harry Potter and the Chamber of Secrets", | ||
"Harry Potter and the Prisoner of Azkaban", "Harry Potter and the Globet of Fire"); | ||
} | ||
|
||
private Book populateBook(Integer id, String title) { | ||
Book book = new Book(); | ||
book.setBid(id); | ||
book.setName(title); | ||
return book; | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...t/src/test/java/io/quarkus/spring/data/deployment/BookListPagingAndSortingRepository.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,6 @@ | ||
package io.quarkus.spring.data.deployment; | ||
|
||
import org.springframework.data.repository.ListPagingAndSortingRepository; | ||
|
||
public interface BookListPagingAndSortingRepository extends ListPagingAndSortingRepository<Book, Integer> { | ||
} |
111 changes: 111 additions & 0 deletions
111
...t/src/test/java/io/quarkus/spring/data/deployment/BookPagingAndSortingRepositoryTest.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,111 @@ | ||
package io.quarkus.spring.data.deployment; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class BookPagingAndSortingRepositoryTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsResource("import_hp_books.sql", "import.sql") | ||
.addClasses(Book.class, BookListPagingAndSortingRepository.class)) | ||
.withConfigurationResource("application.properties"); | ||
|
||
@Inject | ||
BookListPagingAndSortingRepository repo; | ||
|
||
@Test | ||
// @Order(1) | ||
@Transactional | ||
public void shouldReturnFirstPageOfTwoBooks() { | ||
Pageable pageRequest = PageRequest.of(0, 2); | ||
Page<Book> result = repo.findAll(pageRequest); | ||
|
||
assertThat(result).isNotEmpty(); | ||
assertThat(result).hasSize(2); | ||
assertThat(result.stream().map(Book::getBid)).containsExactly(1, 2); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void shouldReturnSecondPageOfSizeTwoBooks() { | ||
Pageable pageRequest = PageRequest.of(1, 2); | ||
Page<Book> result = repo.findAll(pageRequest); | ||
|
||
assertThat(result).isNotEmpty(); | ||
assertThat(result).hasSize(2); | ||
assertThat(result.stream().map(Book::getBid)).containsExactly(3, 4); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void shouldReturnLastPage() { | ||
Pageable pageRequest = PageRequest.of(2, 2); | ||
Page<Book> result = repo.findAll(pageRequest); | ||
|
||
assertThat(result).isNotEmpty(); | ||
assertThat(result).hasSize(2); | ||
assertThat(result.stream().map(Book::getBid)).containsExactly(5, 6); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
void shouldReturnSortedByNameAscAndPagedResult() { | ||
Pageable pageRequest = PageRequest.of(0, 3, Sort.by("name")); | ||
|
||
Page<Book> result = repo.findAll(pageRequest); | ||
assertThat(result).isNotEmpty(); | ||
assertThat(result).hasSize(3); | ||
assertThat(result.stream().map(Book::getBid)).containsExactly(2, 7, 4); | ||
|
||
} | ||
|
||
@Test | ||
@Transactional | ||
void shouldReturnSortedByNameDescAndPagedResult() { | ||
Pageable pageRequest = PageRequest.of(0, 5, Sort.by("name").descending()); | ||
|
||
Page<Book> result = repo.findAll(pageRequest); | ||
assertThat(result).isNotEmpty(); | ||
assertThat(result).hasSize(5); | ||
assertThat(result.stream().map(Book::getBid)).containsExactly(3, 1, 5, 6, 4); | ||
|
||
} | ||
|
||
@Test | ||
@Transactional | ||
void shouldReturnAllBooksSortedByNameDescResult() { | ||
List<Book> result = repo.findAll(Sort.by("name").descending()); | ||
assertThat(result).isNotEmpty(); | ||
assertThat(result).hasSize(7); | ||
assertThat(result.stream().map(Book::getBid)).containsExactly(3, 1, 5, 6, 4, 7, 2); | ||
|
||
} | ||
|
||
@Test | ||
@Transactional | ||
void shouldReturnAllBooksSortedByNameAscResult() { | ||
List<Book> result = repo.findAll(Sort.by("name")); | ||
assertThat(result).isNotEmpty(); | ||
assertThat(result).hasSize(7); | ||
assertThat(result.stream().map(Book::getBid)).containsExactly(2, 7, 4, 6, 5, 1, 3); | ||
|
||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
extensions/spring-data-jpa/deployment/src/test/resources/import_hp_books.sql
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,7 @@ | ||
INSERT INTO book(bid, name) VALUES (1, 'Harry Potter and the Philosophers Stone'); | ||
INSERT INTO book(bid, name) VALUES (2, 'Harry Potter and the Chamber of Secrets'); | ||
INSERT INTO book(bid, name) VALUES (3, 'Harry Potter and the Prisoner of Azkaban'); | ||
INSERT INTO book(bid, name) VALUES (4, 'Harry Potter and the Goblet of Fire'); | ||
INSERT INTO book(bid, name) VALUES (5, 'Harry Potter and the Order of the Phoenix'); | ||
INSERT INTO book(bid, name) VALUES (6, 'Harry Potter and the Half-Blood Prince'); | ||
INSERT INTO book(bid, name) VALUES (7, 'Harry Potter and the Deathly Hallows'); |
114 changes: 114 additions & 0 deletions
114
...st/deployment/src/main/java/io/quarkus/spring/data/rest/deployment/EntityClassHelper.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,114 @@ | ||
package io.quarkus.spring.data.rest.deployment; | ||
|
||
import static io.quarkus.spring.data.rest.deployment.RepositoryMethodsImplementor.CRUD_REPOSITORY_INTERFACE; | ||
import static io.quarkus.spring.data.rest.deployment.RepositoryMethodsImplementor.JPA_REPOSITORY_INTERFACE; | ||
import static io.quarkus.spring.data.rest.deployment.RepositoryMethodsImplementor.LIST_CRUD_REPOSITORY_INTERFACE; | ||
import static io.quarkus.spring.data.rest.deployment.RepositoryMethodsImplementor.LIST_PAGING_AND_SORTING_REPOSITORY_INTERFACE; | ||
import static io.quarkus.spring.data.rest.deployment.RepositoryMethodsImplementor.PAGING_AND_SORTING_REPOSITORY_INTERFACE; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.persistence.Id; | ||
|
||
import org.hibernate.bytecode.enhance.spi.EnhancerConstants; | ||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.FieldInfo; | ||
import org.jboss.jandex.IndexView; | ||
import org.jboss.jandex.MethodInfo; | ||
import org.jboss.jandex.Type; | ||
|
||
import io.quarkus.deployment.bean.JavaBeanUtil; | ||
import io.quarkus.gizmo.MethodDescriptor; | ||
|
||
public class EntityClassHelper { | ||
|
||
private final IndexView index; | ||
|
||
public EntityClassHelper(IndexView index) { | ||
this.index = index; | ||
} | ||
|
||
public FieldInfo getIdField(String className) { | ||
return getIdField(index.getClassByName(DotName.createSimple(className))); | ||
} | ||
|
||
public FieldInfo getIdField(ClassInfo classInfo) { | ||
ClassInfo tmpClassInfo = classInfo; | ||
while (tmpClassInfo != null) { | ||
for (FieldInfo field : tmpClassInfo.fields()) { | ||
if (field.hasAnnotation(DotName.createSimple(Id.class.getName()))) { | ||
return field; | ||
} | ||
} | ||
if (tmpClassInfo.superName() != null) { | ||
tmpClassInfo = index.getClassByName(tmpClassInfo.superName()); | ||
} else { | ||
tmpClassInfo = null; | ||
} | ||
} | ||
throw new IllegalArgumentException("Couldn't find id field of " + classInfo); | ||
} | ||
|
||
public MethodDescriptor getSetter(String className, FieldInfo field) { | ||
return getSetter(index.getClassByName(DotName.createSimple(className)), field); | ||
} | ||
|
||
public MethodDescriptor getSetter(ClassInfo entityClass, FieldInfo field) { | ||
MethodDescriptor setter = getMethod(entityClass, JavaBeanUtil.getSetterName(field.name()), field.type()); | ||
if (setter != null) { | ||
return setter; | ||
} | ||
return MethodDescriptor.ofMethod(entityClass.toString(), | ||
EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + field.name(), void.class, field.type().name().toString()); | ||
} | ||
|
||
public MethodDescriptor getMethod(ClassInfo entityClass, String name, Type... parameters) { | ||
if (entityClass == null) { | ||
return null; | ||
} | ||
MethodInfo methodInfo = entityClass.method(name, parameters); | ||
if (methodInfo != null) { | ||
return MethodDescriptor.of(methodInfo); | ||
} else if (entityClass.superName() != null) { | ||
return getMethod(index.getClassByName(entityClass.superName()), name, parameters); | ||
} | ||
return null; | ||
} | ||
|
||
public boolean isRepositoryInstanceOf(DotName target, String repositoryName) { | ||
ClassInfo classByName = index.getClassByName(repositoryName); | ||
List<Type> types = classByName.interfaceTypes(); | ||
return types.stream().anyMatch(type -> type.name().equals(target)); | ||
} | ||
|
||
public boolean isCrudRepository(String repositoryName) { | ||
return isRepositoryInstanceOf(CRUD_REPOSITORY_INTERFACE, repositoryName) | ||
|| isRepositoryInstanceOf(LIST_CRUD_REPOSITORY_INTERFACE, repositoryName) | ||
|| isRepositoryInstanceOf(JPA_REPOSITORY_INTERFACE, repositoryName); | ||
} | ||
|
||
public boolean isListCrudRepository(String repositoryName) { | ||
return isRepositoryInstanceOf(LIST_CRUD_REPOSITORY_INTERFACE, repositoryName) | ||
|| isRepositoryInstanceOf(JPA_REPOSITORY_INTERFACE, repositoryName); | ||
} | ||
|
||
public boolean isJpaRepository(String repositoryName) { | ||
return isRepositoryInstanceOf(JPA_REPOSITORY_INTERFACE, repositoryName); | ||
} | ||
|
||
public boolean isPagingAndSortingRepository(String repositoryName) { | ||
return isRepositoryInstanceOf(PAGING_AND_SORTING_REPOSITORY_INTERFACE, repositoryName) | ||
|| isRepositoryInstanceOf(LIST_PAGING_AND_SORTING_REPOSITORY_INTERFACE, repositoryName) | ||
|| isRepositoryInstanceOf(JPA_REPOSITORY_INTERFACE, repositoryName); | ||
} | ||
|
||
public boolean isListPagingAndSortingRepository(String repositoryName) { | ||
return isRepositoryInstanceOf(LIST_PAGING_AND_SORTING_REPOSITORY_INTERFACE, repositoryName) | ||
|| isRepositoryInstanceOf(JPA_REPOSITORY_INTERFACE, repositoryName); | ||
} | ||
|
||
public boolean containsPagedRepository(List<ClassInfo> repositories) { | ||
return repositories.stream().anyMatch(r -> isPagingAndSortingRepository(r.name().toString())); | ||
} | ||
} |
Oops, something went wrong.