diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a7bb8d..0a8a313 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,9 +13,7 @@ jobs: strategy: matrix: jdk-version: - - 8 - - 11 - - 14 + - 17 steps: - name: Checkout repository @@ -29,7 +27,7 @@ jobs: cache: maven - name: Test with Maven - run: mvn test + run: mvn -B test test-postgres: runs-on: ubuntu-latest @@ -51,10 +49,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up JDK 14 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: 14 + java-version: 17 distribution: adopt cache: maven @@ -84,10 +82,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up JDK 14 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: 14 + java-version: 17 distribution: adopt cache: maven diff --git a/pom.xml b/pom.xml index 4b876b1..7d2ecd8 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.darrachequesne spring-data-jpa-datatables - 5.2.0 + 6.0.0-SNAPSHOT Spring Data JPA for DataTables Spring Data JPA extension to work with the great jQuery plug-in DataTables (http://datatables.net/) @@ -48,12 +48,12 @@ - 2.5.2 - 1.6.5 - 1.6 + 3.0.0-M7 + 1.6.13 + 3.0.1 - 1.8 + 17 ${java.version} ${java.version} UTF-8 @@ -64,7 +64,14 @@ org.springframework.boot spring-boot-dependencies - 2.6.7 + 3.0.0 + pom + import + + + org.junit + junit-bom + 5.9.1 pom import @@ -89,36 +96,40 @@ - javax.validation - validation-api + jakarta.validation + jakarta.validation-api - org.hibernate - hibernate-entitymanager + org.hibernate.orm + hibernate-core + 6.1.4.Final - com.querydsl querydsl-apt + 5.0.0 + jakarta com.querydsl querydsl-jpa + 5.0.0 + jakarta - javax.annotation - javax.annotation-api + jakarta.annotation + jakarta.annotation-api compile - junit - junit + org.junit.jupiter + junit-jupiter-engine test @@ -141,8 +152,8 @@ - mysql - mysql-connector-java + com.mysql + mysql-connector-j test @@ -154,7 +165,7 @@ org.slf4j - slf4j-log4j12 + slf4j-reload4j test @@ -164,12 +175,12 @@ com.mysema.maven - maven-apt-plugin - 1.0 + apt-maven-plugin + 1.1.3 - test-process + process target/generated-sources/java @@ -181,7 +192,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.10.1 ${maven.compiler.source} ${maven.compiler.target} @@ -191,7 +202,7 @@ org.apache.maven.plugins maven-resources-plugin - 3.1.0 + 3.3.0 ${source.encoding} @@ -215,7 +226,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.2.0 + 3.4.1 @@ -230,6 +241,12 @@ true + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + diff --git a/src/main/java/org/springframework/data/jpa/datatables/ColumnFilter.java b/src/main/java/org/springframework/data/jpa/datatables/ColumnFilter.java index 9eb1b2f..2b61f4c 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/ColumnFilter.java +++ b/src/main/java/org/springframework/data/jpa/datatables/ColumnFilter.java @@ -4,9 +4,9 @@ import com.querydsl.core.types.Predicate; import com.querydsl.core.types.dsl.*; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.Expression; -import javax.persistence.criteria.From; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.Expression; +import jakarta.persistence.criteria.From; import java.util.HashSet; import java.util.Set; @@ -72,7 +72,7 @@ public Predicate createPredicate(PathBuilder pathBuilder, String attributeNam } @Override - public javax.persistence.criteria.Predicate createPredicate(From from, CriteriaBuilder criteriaBuilder, String attributeName) { + public jakarta.persistence.criteria.Predicate createPredicate(From from, CriteriaBuilder criteriaBuilder, String attributeName) { Expression expression = from.get(attributeName); if (values.isEmpty()) { @@ -81,7 +81,7 @@ public javax.persistence.criteria.Predicate createPredicate(From from, Cri return super.createPredicate(from, criteriaBuilder, attributeName); } - javax.persistence.criteria.Predicate predicate; + jakarta.persistence.criteria.Predicate predicate; if (isBooleanComparison) { predicate = expression.in(booleanValues); } else { diff --git a/src/main/java/org/springframework/data/jpa/datatables/Filter.java b/src/main/java/org/springframework/data/jpa/datatables/Filter.java index 35a1db2..a69de00 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/Filter.java +++ b/src/main/java/org/springframework/data/jpa/datatables/Filter.java @@ -2,9 +2,9 @@ import com.querydsl.core.types.dsl.PathBuilder; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.From; -import javax.persistence.criteria.Predicate; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.From; +import jakarta.persistence.criteria.Predicate; interface Filter { diff --git a/src/main/java/org/springframework/data/jpa/datatables/GlobalFilter.java b/src/main/java/org/springframework/data/jpa/datatables/GlobalFilter.java index 8857fe6..264aa00 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/GlobalFilter.java +++ b/src/main/java/org/springframework/data/jpa/datatables/GlobalFilter.java @@ -5,10 +5,10 @@ import com.querydsl.core.types.dsl.PathBuilder; import com.querydsl.core.types.dsl.StringOperation; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.Expression; -import javax.persistence.criteria.From; -import javax.persistence.criteria.Predicate; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.Expression; +import jakarta.persistence.criteria.From; +import jakarta.persistence.criteria.Predicate; /** * Filter which creates a basic "WHERE ... LIKE ..." clause diff --git a/src/main/java/org/springframework/data/jpa/datatables/SpecificationBuilder.java b/src/main/java/org/springframework/data/jpa/datatables/SpecificationBuilder.java index ea40fe3..c80aff6 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/SpecificationBuilder.java +++ b/src/main/java/org/springframework/data/jpa/datatables/SpecificationBuilder.java @@ -1,11 +1,11 @@ package org.springframework.data.jpa.datatables; -import org.hibernate.query.criteria.internal.path.AbstractPathImpl; +import jakarta.persistence.metamodel.Bindable.BindableType; import org.springframework.data.jpa.datatables.mapping.DataTablesInput; import org.springframework.data.jpa.domain.Specification; import org.springframework.lang.NonNull; -import javax.persistence.criteria.*; +import jakarta.persistence.criteria.*; import java.util.ArrayList; import java.util.List; @@ -20,12 +20,12 @@ public Specification build() { } private class DataTablesSpecification implements Specification { - private List columnPredicates = new ArrayList<>(); - private List globalPredicates = new ArrayList<>(); + protected List columnPredicates = new ArrayList<>(); + protected List globalPredicates = new ArrayList<>(); @Override public Predicate toPredicate(@NonNull Root root, @NonNull CriteriaQuery query, @NonNull CriteriaBuilder criteriaBuilder) { - initPredicatesRecursively(tree, root, root, criteriaBuilder); + initPredicatesRecursively(query, tree, root, root, criteriaBuilder); if (input.getSearchPanes() != null) { input.getSearchPanes().forEach((attribute, values) -> { @@ -35,15 +35,16 @@ public Predicate toPredicate(@NonNull Root root, @NonNull CriteriaQuery qu }); } - boolean isCountQuery = query.getResultType() == Long.class; - if (isCountQuery) { - root.getFetches().clear(); - } + final Predicate predicate = createFinalPredicate(criteriaBuilder); + columnPredicates.clear(); + return predicate; + } - return createFinalPredicate(criteriaBuilder); + private boolean isCountQuery(CriteriaQuery query) { + return query.getResultType() == Long.class; } - private void initPredicatesRecursively(Node node, From from, FetchParent fetch, CriteriaBuilder criteriaBuilder) { + protected void initPredicatesRecursively(CriteriaQuery query, Node node, From from, FetchParent fetch, CriteriaBuilder criteriaBuilder) { if (node.isLeaf()) { boolean hasColumnFilter = node.getData() != null; if (hasColumnFilter) { @@ -56,23 +57,26 @@ private void initPredicatesRecursively(Node node, From from, Fetch } for (Node child : node.getChildren()) { Path path = from.get(child.getName()); - if (path instanceof AbstractPathImpl) { - if (((AbstractPathImpl) path).getAttribute().isCollection()) { - // ignore OneToMany and ManyToMany relationships - continue; - } + if (path.getModel().getBindableType() == BindableType.PLURAL_ATTRIBUTE) { + // ignore OneToMany and ManyToMany relationships + continue; } if (child.isLeaf()) { - initPredicatesRecursively(child, from, fetch, criteriaBuilder); + initPredicatesRecursively(query, child, from, fetch, criteriaBuilder); } else { Join join = from.join(child.getName(), JoinType.LEFT); - Fetch childFetch = fetch.fetch(child.getName(), JoinType.LEFT); - initPredicatesRecursively(child, join, childFetch, criteriaBuilder); + + if (isCountQuery(query)) { + initPredicatesRecursively(query, child, join, join, criteriaBuilder); + } else { + Fetch childFetch = fetch.fetch(child.getName(), JoinType.LEFT); + initPredicatesRecursively(query, child, join, childFetch, criteriaBuilder); + } } } } - private Predicate createFinalPredicate(CriteriaBuilder criteriaBuilder) { + protected Predicate createFinalPredicate(CriteriaBuilder criteriaBuilder) { List allPredicates = new ArrayList<>(columnPredicates); if (!globalPredicates.isEmpty()) { @@ -83,4 +87,38 @@ private Predicate createFinalPredicate(CriteriaBuilder criteriaBuilder) { } } + private class DataTablesSearchPaneSpecification extends DataTablesSpecification { + + @Override + protected void initPredicatesRecursively(CriteriaQuery query, Node node, From from, + FetchParent fetch, CriteriaBuilder criteriaBuilder) { + if (node.isLeaf()) { + boolean hasColumnFilter = node.getData() != null; + if (hasColumnFilter) { + Filter columnFilter = node.getData(); + columnPredicates.add(columnFilter.createPredicate(from, criteriaBuilder, node.getName())); + } else if (hasGlobalFilter) { + Filter globalFilter = tree.getData(); + globalPredicates.add(globalFilter.createPredicate(from, criteriaBuilder, node.getName())); + } + } + for (Node child : node.getChildren()) { + Path path = from.get(child.getName()); + if (path.getModel().getBindableType() == BindableType.PLURAL_ATTRIBUTE) { + // ignore OneToMany and ManyToMany relationships + continue; + } + if (child.isLeaf()) { + initPredicatesRecursively(query, child, from, fetch, criteriaBuilder); + } else { + Join join = from.join(child.getName(), JoinType.LEFT); + initPredicatesRecursively(query, child, join, fetch, criteriaBuilder); + } + } + } + } + + public Specification buildSearchPane() { + return new DataTablesSearchPaneSpecification<>(); + } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/jpa/datatables/mapping/Column.java b/src/main/java/org/springframework/data/jpa/datatables/mapping/Column.java index 6607ecd..8ee2955 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/mapping/Column.java +++ b/src/main/java/org/springframework/data/jpa/datatables/mapping/Column.java @@ -4,8 +4,8 @@ import lombok.Data; import lombok.NoArgsConstructor; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; @Data @NoArgsConstructor diff --git a/src/main/java/org/springframework/data/jpa/datatables/mapping/DataTablesInput.java b/src/main/java/org/springframework/data/jpa/datatables/mapping/DataTablesInput.java index 92e421f..cbe1878 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/mapping/DataTablesInput.java +++ b/src/main/java/org/springframework/data/jpa/datatables/mapping/DataTablesInput.java @@ -2,9 +2,9 @@ import lombok.Data; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/main/java/org/springframework/data/jpa/datatables/mapping/Order.java b/src/main/java/org/springframework/data/jpa/datatables/mapping/Order.java index 0c8f649..10e62dd 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/mapping/Order.java +++ b/src/main/java/org/springframework/data/jpa/datatables/mapping/Order.java @@ -4,9 +4,9 @@ import lombok.Data; import lombok.NoArgsConstructor; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; @Data @NoArgsConstructor diff --git a/src/main/java/org/springframework/data/jpa/datatables/mapping/Search.java b/src/main/java/org/springframework/data/jpa/datatables/mapping/Search.java index 25b14ac..703d5a7 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/mapping/Search.java +++ b/src/main/java/org/springframework/data/jpa/datatables/mapping/Search.java @@ -4,7 +4,7 @@ import lombok.Data; import lombok.NoArgsConstructor; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; @Data @NoArgsConstructor diff --git a/src/main/java/org/springframework/data/jpa/datatables/qrepository/QDataTablesRepositoryFactoryBean.java b/src/main/java/org/springframework/data/jpa/datatables/qrepository/QDataTablesRepositoryFactoryBean.java index cfba343..11bb010 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/qrepository/QDataTablesRepositoryFactoryBean.java +++ b/src/main/java/org/springframework/data/jpa/datatables/qrepository/QDataTablesRepositoryFactoryBean.java @@ -7,7 +7,7 @@ import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.core.support.RepositoryFactorySupport; -import javax.persistence.EntityManager; +import jakarta.persistence.EntityManager; import java.io.Serializable; /** @@ -22,6 +22,7 @@ public QDataTablesRepositoryFactoryBean(Class repositoryInterface) super(repositoryInterface); } + @Override protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) { return new DataTablesRepositoryFactory(entityManager); } diff --git a/src/main/java/org/springframework/data/jpa/datatables/qrepository/QDataTablesRepositoryImpl.java b/src/main/java/org/springframework/data/jpa/datatables/qrepository/QDataTablesRepositoryImpl.java index 52ac1de..12a8320 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/qrepository/QDataTablesRepositoryImpl.java +++ b/src/main/java/org/springframework/data/jpa/datatables/qrepository/QDataTablesRepositoryImpl.java @@ -16,7 +16,7 @@ import org.springframework.data.querydsl.EntityPathResolver; import org.springframework.data.querydsl.SimpleEntityPathResolver; -import javax.persistence.EntityManager; +import jakarta.persistence.EntityManager; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepository.java b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepository.java index 832a585..974ec9a 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepository.java +++ b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepository.java @@ -3,6 +3,7 @@ import org.springframework.data.jpa.datatables.mapping.DataTablesInput; import org.springframework.data.jpa.datatables.mapping.DataTablesOutput; import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.repository.NoRepositoryBean; import org.springframework.data.repository.PagingAndSortingRepository; @@ -18,7 +19,7 @@ */ @NoRepositoryBean public interface DataTablesRepository - extends PagingAndSortingRepository, JpaSpecificationExecutor { + extends PagingAndSortingRepository, JpaSpecificationExecutor, JpaRepository { /** * Returns the filtered list for the given {@link DataTablesInput}. diff --git a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryFactoryBean.java b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryFactoryBean.java index 867e19b..c6d93e5 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryFactoryBean.java +++ b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryFactoryBean.java @@ -7,7 +7,7 @@ import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.core.support.RepositoryFactorySupport; -import javax.persistence.EntityManager; +import jakarta.persistence.EntityManager; import java.io.Serializable; /** diff --git a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryImpl.java b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryImpl.java index dc8da77..add5301 100644 --- a/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryImpl.java +++ b/src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryImpl.java @@ -1,6 +1,13 @@ package org.springframework.data.jpa.datatables.repository; +import jakarta.persistence.EntityManager; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Root; import lombok.extern.slf4j.Slf4j; +import org.hibernate.query.sqm.tree.domain.AbstractSqmFrom; +import org.hibernate.query.sqm.tree.domain.SqmPath; +import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; import org.springframework.data.domain.Page; import org.springframework.data.jpa.datatables.SpecificationBuilder; import org.springframework.data.jpa.datatables.mapping.DataTablesInput; @@ -10,10 +17,6 @@ import org.springframework.data.jpa.repository.support.JpaEntityInformation; import org.springframework.data.jpa.repository.support.SimpleJpaRepository; -import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; @@ -88,7 +91,8 @@ public DataTablesOutput findAll(DataTablesInput input, output.setRecordsFiltered(data.getTotalElements()); if (input.getSearchPanes() != null) { - output.setSearchPanes(computeSearchPanes(input, specification)); + SpecificationBuilder specificationSearchPaneBuilder = new SpecificationBuilder<>(input); + output.setSearchPanes(computeSearchPanes(input, specificationSearchPaneBuilder.buildSearchPane())); } } catch (Exception e) { log.warn("error while fetching records", e); @@ -100,16 +104,15 @@ public DataTablesOutput findAll(DataTablesInput input, } private SearchPanes computeSearchPanes(DataTablesInput input, Specification specification) { - CriteriaBuilder criteriaBuilder = this.entityManager.getCriteriaBuilder(); Map> options = new HashMap<>(); input.getSearchPanes().forEach((attribute, values) -> { + CriteriaBuilder criteriaBuilder = this.entityManager.getCriteriaBuilder(); CriteriaQuery query = criteriaBuilder.createQuery(Object[].class); Root root = query.from(getDomainClass()); query.multiselect(root.get(attribute), criteriaBuilder.count(root)); query.groupBy(root.get(attribute)); query.where(specification.toPredicate(root, query, criteriaBuilder)); - root.getFetches().clear(); List items = new ArrayList<>(); diff --git a/src/test/java/org/springframework/data/jpa/datatables/Config.java b/src/test/java/org/springframework/data/jpa/datatables/Config.java index 24ee1c3..fbf1c3e 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/Config.java +++ b/src/test/java/org/springframework/data/jpa/datatables/Config.java @@ -1,5 +1,8 @@ package org.springframework.data.jpa.datatables; +import java.sql.SQLException; +import java.util.Properties; +import javax.sql.DataSource; import lombok.extern.slf4j.Slf4j; import org.hibernate.SessionFactory; import org.springframework.context.annotation.Bean; @@ -11,14 +14,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.orm.hibernate5.LocalSessionFactoryBean; -import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; - -import javax.sql.DataSource; -import java.sql.SQLException; -import java.util.Properties; /** * Spring JavaConfig configuration for general infrastructure. @@ -26,54 +22,55 @@ @Slf4j @Configuration @EnableJpaRepositories(repositoryFactoryBeanClass = DataTablesRepositoryFactoryBean.class, - basePackages = { "org.springframework.data.jpa.datatables.model", "org.springframework.data.jpa.datatables.repository" }) + basePackages = {"org.springframework.data.jpa.datatables.model", + "org.springframework.data.jpa.datatables.repository"}) public class Config { - @Bean - @Profile({"default", "h2"}) - public DataSource dataSource_H2() throws SQLException { - return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build(); - } + @Bean + @Profile({"default", "h2"}) + public DataSource dataSource_H2() throws SQLException { + return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build(); + } - @Bean - @Profile("mysql") - public DataSource dataSource_MySQL() throws SQLException { - DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName("com.mysql.jdbc.Driver"); - dataSource.setUrl("jdbc:mysql://127.0.0.1/test"); - dataSource.setUsername("root"); - dataSource.setPassword("changeit"); - return dataSource; - } + @Bean + @Profile("mysql") + public DataSource dataSource_MySQL() throws SQLException { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("com.mysql.jdbc.Driver"); + dataSource.setUrl("jdbc:mysql://127.0.0.1/test"); + dataSource.setUsername("root"); + dataSource.setPassword("changeit"); + return dataSource; + } - @Bean - @Profile("pgsql") - public DataSource dataSource_PostgreSQL() throws SQLException { - DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName("org.postgresql.Driver"); - dataSource.setUrl("jdbc:postgresql://127.0.0.1/postgres"); - dataSource.setUsername("postgres"); - dataSource.setPassword("postgres"); - return dataSource; - } + @Bean + @Profile("pgsql") + public DataSource dataSource_PostgreSQL() throws SQLException { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("org.postgresql.Driver"); + dataSource.setUrl("jdbc:postgresql://127.0.0.1/postgres"); + dataSource.setUsername("postgres"); + dataSource.setPassword("postgres"); + return dataSource; + } - @Bean - public SessionFactory entityManagerFactory(DataSource dataSource) throws Exception { - LocalSessionFactoryBean factory = new LocalSessionFactoryBean(); - factory.setPackagesToScan(Config.class.getPackage().getName()); - factory.setDataSource(dataSource); + @Bean + public SessionFactory entityManagerFactory(DataSource dataSource) throws Exception { + LocalSessionFactoryBean factory = new LocalSessionFactoryBean(); + factory.setPackagesToScan(Config.class.getPackage().getName()); + factory.setDataSource(dataSource); - Properties properties = new Properties(); - properties.setProperty("hibernate.hbm2ddl.auto", "create"); - factory.setHibernateProperties(properties); + Properties properties = new Properties(); + properties.setProperty("hibernate.hbm2ddl.auto", "create"); + factory.setHibernateProperties(properties); - factory.afterPropertiesSet(); - return factory.getObject(); - } + factory.afterPropertiesSet(); + return factory.getObject(); + } - @Bean - public JpaTransactionManager transactionManager(SessionFactory sessionFactory) throws Exception { - return new JpaTransactionManager(sessionFactory); - } + @Bean + public JpaTransactionManager transactionManager(SessionFactory sessionFactory) throws Exception { + return new JpaTransactionManager(sessionFactory); + } } diff --git a/src/test/java/org/springframework/data/jpa/datatables/mapping/DataTablesInputTest.java b/src/test/java/org/springframework/data/jpa/datatables/mapping/DataTablesInputTest.java index c96ce32..07951ab 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/mapping/DataTablesInputTest.java +++ b/src/test/java/org/springframework/data/jpa/datatables/mapping/DataTablesInputTest.java @@ -1,6 +1,6 @@ package org.springframework.data.jpa.datatables.mapping; -import org.junit.Test; +import org.junit.jupiter.api.Test;; import java.util.*; diff --git a/src/test/java/org/springframework/data/jpa/datatables/model/A.java b/src/test/java/org/springframework/data/jpa/datatables/model/A.java index 65740a5..1959afc 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/model/A.java +++ b/src/test/java/org/springframework/data/jpa/datatables/model/A.java @@ -2,7 +2,7 @@ import lombok.*; -import javax.persistence.*; +import jakarta.persistence.*; import java.util.Collections; import java.util.List; diff --git a/src/test/java/org/springframework/data/jpa/datatables/model/B.java b/src/test/java/org/springframework/data/jpa/datatables/model/B.java index eda00a6..f3bd78d 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/model/B.java +++ b/src/test/java/org/springframework/data/jpa/datatables/model/B.java @@ -5,9 +5,9 @@ import lombok.Data; import lombok.NoArgsConstructor; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; @Data @AllArgsConstructor @@ -16,5 +16,5 @@ @Table(name = "b") class B { private @Id String name; - private String value; + private String someValue; } \ No newline at end of file diff --git a/src/test/java/org/springframework/data/jpa/datatables/model/C.java b/src/test/java/org/springframework/data/jpa/datatables/model/C.java index 78084a5..28d3b94 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/model/C.java +++ b/src/test/java/org/springframework/data/jpa/datatables/model/C.java @@ -5,7 +5,7 @@ import lombok.Data; import lombok.NoArgsConstructor; -import javax.persistence.*; +import jakarta.persistence.*; @Data @AllArgsConstructor @@ -16,7 +16,7 @@ class C { private @Id String name; - private String value; + private String someValue; @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "parent_id") diff --git a/src/test/java/org/springframework/data/jpa/datatables/model/D.java b/src/test/java/org/springframework/data/jpa/datatables/model/D.java index 84f949a..7ab21f1 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/model/D.java +++ b/src/test/java/org/springframework/data/jpa/datatables/model/D.java @@ -5,12 +5,12 @@ import lombok.Data; import lombok.NoArgsConstructor; -import javax.persistence.Embeddable; +import jakarta.persistence.Embeddable; @Data @AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PRIVATE) @Embeddable class D { - private String value; + private String someValue; } \ No newline at end of file diff --git a/src/test/java/org/springframework/data/jpa/datatables/model/Employee.java b/src/test/java/org/springframework/data/jpa/datatables/model/Employee.java index dcaac17..8003d90 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/model/Employee.java +++ b/src/test/java/org/springframework/data/jpa/datatables/model/Employee.java @@ -1,21 +1,23 @@ package org.springframework.data.jpa.datatables.model; +import static java.util.Arrays.asList; +import static java.util.Comparator.comparingInt; +import static java.util.stream.Collectors.toList; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.persistence.Transient; +import java.util.List; import lombok.AccessLevel; import lombok.Builder; import lombok.Data; import lombok.Setter; import lombok.experimental.Tolerate; -import javax.persistence.*; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; - -import static java.util.Arrays.asList; -import static java.util.Comparator.comparingInt; -import static java.util.Comparator.reverseOrder; -import static java.util.stream.Collectors.toList; - @Data @Setter(AccessLevel.NONE) @Builder @@ -37,6 +39,7 @@ public class Employee { @Tolerate private Employee() {} + @Transient public static Employee AIRI_SATOU = Employee.builder() .id(5407) .firstName("Airi") @@ -47,6 +50,7 @@ private Employee() {} .comment(null) .build(); + @Transient public static Employee ANGELICA_RAMOS = Employee.builder() .id(5797) .firstName("Angelica") @@ -57,6 +61,7 @@ private Employee() {} .comment("\\NULL") .build(); + @Transient public static Employee ASHTON_COX = Employee.builder() .id(1562) .firstName("Ashton") @@ -68,6 +73,7 @@ private Employee() {} .comment("~foo~~") .build(); + @Transient public static Employee BRADLEY_GREER = Employee.builder() .id(2558) .firstName("Bradley") @@ -78,6 +84,7 @@ private Employee() {} .comment("%foo%%") .build(); + @Transient public static Employee BRENDEN_WAGNER = Employee.builder() .id(1314) .firstName("Brenden") @@ -88,6 +95,7 @@ private Employee() {} .comment("_foo__") .build(); + @Transient public static Employee BRIELLE_WILLIAMSON = Employee.builder() .id(4804) .firstName("Brielle") @@ -98,6 +106,7 @@ private Employee() {} .comment("@foo@@") .build(); + @Transient public static List ALL = asList( AIRI_SATOU, ANGELICA_RAMOS, diff --git a/src/test/java/org/springframework/data/jpa/datatables/model/Office.java b/src/test/java/org/springframework/data/jpa/datatables/model/Office.java index 622f07e..c3104f6 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/model/Office.java +++ b/src/test/java/org/springframework/data/jpa/datatables/model/Office.java @@ -1,14 +1,17 @@ package org.springframework.data.jpa.datatables.model; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Transient; import lombok.AccessLevel; import lombok.Builder; import lombok.Data; import lombok.Setter; import lombok.experimental.Tolerate; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; @Data @Setter(AccessLevel.NONE) @@ -23,24 +26,28 @@ public class Office { @Tolerate private Office() {} + @Transient public static Office TOKYO = Office.builder() .id(1) .city("Tokyo") .country("Japan") .build(); + @Transient public static Office LONDON = Office.builder() .id(2) .city("London") .country("UK") .build(); + @Transient public static Office SAN_FRANCISCO = Office.builder() .id(3) .city("San Francisco") .country("USA") .build(); + @Transient public static Office NEW_YORK = Office.builder() .id(4) .city("New York") diff --git a/src/test/java/org/springframework/data/jpa/datatables/qrepository/QEmployeeRepositoryTest.java b/src/test/java/org/springframework/data/jpa/datatables/qrepository/QEmployeeRepositoryTest.java index 476f523..0a2950c 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/qrepository/QEmployeeRepositoryTest.java +++ b/src/test/java/org/springframework/data/jpa/datatables/qrepository/QEmployeeRepositoryTest.java @@ -1,8 +1,11 @@ package org.springframework.data.jpa.datatables.qrepository; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.function.Function; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.datatables.Config; import org.springframework.data.jpa.datatables.QConfig; @@ -13,13 +16,9 @@ import org.springframework.data.jpa.datatables.model.QEmployee; import org.springframework.data.jpa.datatables.repository.EmployeeRepositoryTest; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.function.Function; - -import static org.assertj.core.api.Assertions.assertThat; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {Config.class, QConfig.class}) public class QEmployeeRepositoryTest extends EmployeeRepositoryTest { @Autowired @@ -52,7 +51,7 @@ public void withAPreFilteringSpecification() { } @Test - @Ignore + @Disabled @Override public void unknownColumn() { // the findAll() method throws "Transaction silently rolled back because it has been marked as rollback-only", needs investigation diff --git a/src/test/java/org/springframework/data/jpa/datatables/qrepository/QRelationshipsRepositoryTest.java b/src/test/java/org/springframework/data/jpa/datatables/qrepository/QRelationshipsRepositoryTest.java index 2c029fa..a560c6f 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/qrepository/QRelationshipsRepositoryTest.java +++ b/src/test/java/org/springframework/data/jpa/datatables/qrepository/QRelationshipsRepositoryTest.java @@ -1,8 +1,8 @@ package org.springframework.data.jpa.datatables.qrepository; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.datatables.Config; import org.springframework.data.jpa.datatables.QConfig; @@ -11,23 +11,24 @@ import org.springframework.data.jpa.datatables.model.A; import org.springframework.data.jpa.datatables.repository.RelationshipsRepositoryTest; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {Config.class, QConfig.class}) public class QRelationshipsRepositoryTest extends RelationshipsRepositoryTest { - @Autowired - private QRelationshipsRepository repository; - @Override - protected DataTablesOutput getOutput(DataTablesInput input) { - return repository.findAll(input); - } + @Autowired + private QRelationshipsRepository repository; - @Test - @Ignore - @Override - public void checkFetchJoin() { - // see https://github.com/darrachequesne/spring-data-jpa-datatables/issues/7 - } + @Override + protected DataTablesOutput getOutput(DataTablesInput input) { + return repository.findAll(input); + } + + @Test + @Disabled + @Override + public void checkFetchJoin() { + // see https://github.com/darrachequesne/spring-data-jpa-datatables/issues/7 + } } \ No newline at end of file diff --git a/src/test/java/org/springframework/data/jpa/datatables/repository/EmployeeRepositoryTest.java b/src/test/java/org/springframework/data/jpa/datatables/repository/EmployeeRepositoryTest.java index 89c5a9c..0ae54b7 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/repository/EmployeeRepositoryTest.java +++ b/src/test/java/org/springframework/data/jpa/datatables/repository/EmployeeRepositoryTest.java @@ -1,8 +1,21 @@ package org.springframework.data.jpa.datatables.repository; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import static java.util.Arrays.asList; +import static java.util.Collections.emptySet; +import static org.assertj.core.api.Assertions.assertThat; + +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Root; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.datatables.Config; import org.springframework.data.jpa.datatables.mapping.DataTablesInput; @@ -12,23 +25,9 @@ import org.springframework.data.jpa.datatables.model.EmployeeDto; import org.springframework.data.jpa.domain.Specification; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.function.Function; - -import static java.util.Arrays.asList; -import static java.util.Collections.emptySet; -import static org.assertj.core.api.Assertions.assertThat; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = Config.class) public class EmployeeRepositoryTest { protected DataTablesInput input; @@ -44,7 +43,7 @@ protected DataTablesOutput getOutput(DataTablesInput input, Functio return employeeRepository.findAll(input, converter); } - @Before + @BeforeEach public void init() { employeeRepository.deleteAll(); employeeRepository.saveAll(Employee.ALL); @@ -52,7 +51,7 @@ public void init() { } @Test - public void basic() { + void basic() { DataTablesOutput output = getOutput(input); assertThat(output.getDraw()).isEqualTo(1); assertThat(output.getError()).isNull(); @@ -62,7 +61,7 @@ public void basic() { } @Test - public void paginated() { + void paginated() { input.setDraw(2); input.setLength(5); input.setStart(5); @@ -75,7 +74,7 @@ public void paginated() { } @Test - public void sortAscending() { + void sortAscending() { input.addOrder("age", true); DataTablesOutput output = getOutput(input); @@ -83,7 +82,7 @@ public void sortAscending() { } @Test - public void sortDescending() { + void sortDescending() { input.addOrder("age", false); DataTablesOutput output = getOutput(input); @@ -91,7 +90,7 @@ public void sortDescending() { } @Test - public void globalFilter() { + void globalFilter() { input.getSearch().setValue("William"); DataTablesOutput output = getOutput(input); @@ -99,7 +98,7 @@ public void globalFilter() { } @Test - public void globalFilterIgnoreCaseIgnoreSpace() { + void globalFilterIgnoreCaseIgnoreSpace() { input.getSearch().setValue(" aMoS "); DataTablesOutput output = getOutput(input); @@ -107,7 +106,7 @@ public void globalFilterIgnoreCaseIgnoreSpace() { } @Test - public void columnFilter() { + void columnFilter() { input.getColumn("lastName").setSearchValue(" AmOs "); DataTablesOutput output = getOutput(input); @@ -115,7 +114,7 @@ public void columnFilter() { } @Test - public void multipleColumnFilters() { + void multipleColumnFilters() { input.getColumn("age").setSearchValue("28"); input.getColumn("position").setSearchValue("Software"); @@ -124,7 +123,7 @@ public void multipleColumnFilters() { } @Test - public void columnFilterWithMultipleCases() { + void columnFilterWithMultipleCases() { input.getColumn("position").setSearchValue("Accountant+Junior Technical Author"); DataTablesOutput output = getOutput(input); @@ -133,7 +132,7 @@ public void columnFilterWithMultipleCases() { } @Test - public void columnFilterWithNoCase() { + void columnFilterWithNoCase() { input.getColumn("position").setSearchValue("+"); DataTablesOutput output = getOutput(input); @@ -141,16 +140,16 @@ public void columnFilterWithNoCase() { } @Test - public void zeroLength() { + void zeroLength() { input.setLength(0); DataTablesOutput output = getOutput(input); - assertThat(output.getRecordsFiltered()).isEqualTo(0); - assertThat(output.getData()).hasSize(0); + assertThat(output.getRecordsFiltered()).isZero(); + assertThat(output.getData()).isEmpty(); } @Test - public void negativeLength() { + void negativeLength() { input.setLength(-1); DataTablesOutput output = getOutput(input); @@ -159,7 +158,7 @@ public void negativeLength() { } @Test - public void multipleColumnFiltersOnManyToOneRelationship() { + void multipleColumnFiltersOnManyToOneRelationship() { input.getColumn("office.city").setSearchValue("new york"); input.getColumn("office.country").setSearchValue("USA"); @@ -169,7 +168,7 @@ public void multipleColumnFiltersOnManyToOneRelationship() { } @Test - public void withConverter() { + void withConverter() { input.getColumn("firstName").setSearchValue("airi"); DataTablesOutput output = getOutput(input, employee -> @@ -178,20 +177,20 @@ public void withConverter() { } @Test - public void withAnAdditionalSpecification() { + protected void withAnAdditionalSpecification() { DataTablesOutput output = employeeRepository.findAll(input, new SoftwareEngineersOnly<>()); assertThat(output.getRecordsFiltered()).isEqualTo(2); assertThat(output.getRecordsTotal()).isEqualTo(Employee.ALL.size()); } @Test - public void withAPreFilteringSpecification() { + protected void withAPreFilteringSpecification() { DataTablesOutput output = employeeRepository.findAll(input, null, new SoftwareEngineersOnly<>()); assertThat(output.getRecordsFiltered()).isEqualTo(2); assertThat(output.getRecordsTotal()).isEqualTo(2); } - private class SoftwareEngineersOnly implements Specification { + private static class SoftwareEngineersOnly implements Specification { @Override public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) { return criteriaBuilder.equal(root.get("position"), "Software Engineer"); @@ -199,7 +198,7 @@ public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuild } @Test - public void columnFilterWithNull() { + void columnFilterWithNull() { input.getColumn("comment").setSearchValue("NULL"); DataTablesOutput output = getOutput(input); @@ -207,7 +206,7 @@ public void columnFilterWithNull() { } @Test - public void columnFilterWithNullEscaped() { + void columnFilterWithNullEscaped() { input.getColumn("comment").setSearchValue("\\NULL"); DataTablesOutput output = getOutput(input); @@ -215,7 +214,7 @@ public void columnFilterWithNullEscaped() { } @Test - public void columnFilterWithEscapeCharacters() { + void columnFilterWithEscapeCharacters() { input.getColumn("comment").setSearchValue("foo~"); DataTablesOutput output = getOutput(input); assertThat(output.getData()).containsOnly(Employee.ASHTON_COX); @@ -230,7 +229,7 @@ public void columnFilterWithEscapeCharacters() { } @Test - public void columnFilterWithValueOrNull() { + void columnFilterWithValueOrNull() { input.getColumn("comment").setSearchValue("@foo@@+NULL"); DataTablesOutput output = getOutput(input); @@ -238,7 +237,7 @@ public void columnFilterWithValueOrNull() { } @Test - public void columnFilterBoolean() { + void columnFilterBoolean() { input.getColumn("isWorkingRemotely").setSearchValue("true"); DataTablesOutput output = getOutput(input); @@ -246,7 +245,7 @@ public void columnFilterBoolean() { } @Test - public void columnFilterBooleanBothCases() { + void columnFilterBooleanBothCases() { input.getColumn("isWorkingRemotely").setSearchValue("true+false"); DataTablesOutput output = getOutput(input); @@ -254,7 +253,7 @@ public void columnFilterBooleanBothCases() { } @Test - public void unknownColumn() { + protected void unknownColumn() { input.addColumn("unknown", true, true, "test"); DataTablesOutput output = getOutput(input); @@ -262,7 +261,7 @@ public void unknownColumn() { } @Test - public void withSearchPanes() { + void withSearchPanes() { Map> searchPanes = new HashMap<>(); searchPanes.put("position", new HashSet<>(asList("Software Engineer", "Integration Specialist"))); searchPanes.put("age", emptySet()); diff --git a/src/test/java/org/springframework/data/jpa/datatables/repository/RelationshipsRepositoryTest.java b/src/test/java/org/springframework/data/jpa/datatables/repository/RelationshipsRepositoryTest.java index 7fbdf13..77b5c23 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/repository/RelationshipsRepositoryTest.java +++ b/src/test/java/org/springframework/data/jpa/datatables/repository/RelationshipsRepositoryTest.java @@ -1,21 +1,21 @@ package org.springframework.data.jpa.datatables.repository; +import static org.assertj.core.api.Assertions.assertThat; + import org.hibernate.SessionFactory; import org.hibernate.stat.Statistics; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.datatables.Config; import org.springframework.data.jpa.datatables.mapping.DataTablesInput; import org.springframework.data.jpa.datatables.mapping.DataTablesOutput; import org.springframework.data.jpa.datatables.model.A; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.assertj.core.api.Assertions.assertThat; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = Config.class) public class RelationshipsRepositoryTest { protected DataTablesInput input; @@ -30,7 +30,7 @@ protected DataTablesOutput getOutput(DataTablesInput input) { return repository.findAll(input); } - @Before + @BeforeEach public void init() { repository.deleteAll(); repository.saveAll(A.ALL); @@ -38,28 +38,28 @@ public void init() { } @Test - public void manyToOne() { - input.getColumn("c.value").setSearchValue("VAL2"); + void manyToOne() { + input.getColumn("c.someValue").setSearchValue("VAL2"); DataTablesOutput output = getOutput(input); assertThat(output.getData()).containsOnly(A.A2, A.A3); } @Test - public void twoLevels() { - input.getColumn("c.parent.value").setSearchValue("VAL3"); + void twoLevels() { + input.getColumn("c.parent.someValue").setSearchValue("VAL3"); DataTablesOutput output = getOutput(input); assertThat(output.getData()).containsOnly(A.A1); } @Test - public void embedded() { - input.getColumn("d.value").setSearchValue("D1"); + void embedded() { + input.getColumn("d.someValue").setSearchValue("D1"); DataTablesOutput output = getOutput(input); assertThat(output.getData()).containsOnly(A.A1); } @Test - public void checkFetchJoin() { + protected void checkFetchJoin() { Statistics statistics = sessionFactory.getStatistics(); statistics.setStatisticsEnabled(true); @@ -74,12 +74,12 @@ private static DataTablesInput getBasicInput() { DataTablesInput input = new DataTablesInput(); input.addColumn("name", true, true, ""); input.addColumn("b.name", true, true, ""); - input.addColumn("b.value", true, true, ""); + input.addColumn("b.someValue", true, true, ""); input.addColumn("c.name", true, true, ""); - input.addColumn("c.value", true, true, ""); + input.addColumn("c.someValue", true, true, ""); input.addColumn("c.parent.name", true, true, ""); - input.addColumn("c.parent.value", true, true, ""); - input.addColumn("d.value", true, true, ""); + input.addColumn("c.parent.someValue", true, true, ""); + input.addColumn("d.someValue", true, true, ""); return input; } } \ No newline at end of file diff --git a/src/test/java/org/springframework/data/jpa/datatables/repository/RepositoryTest.java b/src/test/java/org/springframework/data/jpa/datatables/repository/RepositoryTest.java index 438ba79..9095a8f 100644 --- a/src/test/java/org/springframework/data/jpa/datatables/repository/RepositoryTest.java +++ b/src/test/java/org/springframework/data/jpa/datatables/repository/RepositoryTest.java @@ -1,7 +1,9 @@ package org.springframework.data.jpa.datatables.repository; -import org.junit.Test; -import org.junit.runner.RunWith; +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.aop.framework.Advised; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.datatables.Config; @@ -10,27 +12,25 @@ import org.springframework.data.jpa.datatables.qrepository.QEmployeeRepository; import org.springframework.data.jpa.repository.support.SimpleJpaRepository; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.assertj.core.api.Assertions.assertThat; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {Config.class, QConfig.class}) -public class RepositoryTest { +class RepositoryTest { private @Autowired EmployeeRepository employeeRepository; private @Autowired QEmployeeRepository qEmployeeRepository; private @Autowired OfficeRepository officeRepository; @Test - public void checkGeneratedRepositories() { + void checkGeneratedRepositories() { assertThat(getTargetObject(employeeRepository)).isEqualTo(DataTablesRepositoryImpl.class); assertThat(getTargetObject(officeRepository)).isEqualTo(SimpleJpaRepository.class); assertThat(getTargetObject(qEmployeeRepository)).isEqualTo(QDataTablesRepositoryImpl.class); } // returns the class of the proxied object - private Class getTargetObject(Object proxy) { + private Class getTargetObject(Object proxy) { return ((Advised) proxy).getTargetSource().getTargetClass(); }