From 237a438e0793cb658d963d1a2fd88990743df964 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Sat, 9 Apr 2016 15:41:20 +0200 Subject: [PATCH] DATAJPA-885 - Polishing. Some cleanups in some test cases. --- .../query/PartTreeJpaQueryIntegrationTests.java | 15 +++++++++++---- .../repository/query/StringQueryUnitTests.java | 12 ++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/springframework/data/jpa/repository/query/PartTreeJpaQueryIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/query/PartTreeJpaQueryIntegrationTests.java index 697259712..4bec37c30 100644 --- a/src/test/java/org/springframework/data/jpa/repository/query/PartTreeJpaQueryIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/query/PartTreeJpaQueryIntegrationTests.java @@ -34,10 +34,12 @@ import javax.persistence.TemporalType; import org.hibernate.Version; import org.hibernate.ejb.HibernateQuery; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; +import org.springframework.data.annotation.PersistenceConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -66,6 +68,13 @@ public class PartTreeJpaQueryIntegrationTests { @PersistenceContext EntityManager entityManager; + PersistenceProvider provider; + + @Before + public void setUp() { + this.provider = PersistenceProvider.fromEntityManager(entityManager); + } + /** * @see DATADOC-90 * @throws Exception @@ -74,8 +83,7 @@ public class PartTreeJpaQueryIntegrationTests { public void test() throws Exception { JpaQueryMethod queryMethod = getQueryMethod("findByFirstname", String.class, Pageable.class); - PartTreeJpaQuery jpaQuery = new PartTreeJpaQuery(queryMethod, entityManager, - PersistenceProvider.fromEntityManager(entityManager)); + PartTreeJpaQuery jpaQuery = new PartTreeJpaQuery(queryMethod, entityManager, provider); jpaQuery.createQuery(new Object[] { "Matthews", new PageRequest(0, 1) }); jpaQuery.createQuery(new Object[] { "Matthews", new PageRequest(0, 1) }); @@ -102,8 +110,7 @@ public class PartTreeJpaQueryIntegrationTests { public void recreatesQueryIfNullValueIsGiven() throws Exception { JpaQueryMethod queryMethod = getQueryMethod("findByFirstname", String.class, Pageable.class); - PartTreeJpaQuery jpaQuery = new PartTreeJpaQuery(queryMethod, entityManager, - PersistenceProvider.fromEntityManager(entityManager)); + PartTreeJpaQuery jpaQuery = new PartTreeJpaQuery(queryMethod, entityManager, provider); Query query = jpaQuery.createQuery(new Object[] { "Matthews", new PageRequest(0, 1) }); diff --git a/src/test/java/org/springframework/data/jpa/repository/query/StringQueryUnitTests.java b/src/test/java/org/springframework/data/jpa/repository/query/StringQueryUnitTests.java index c1dd919f9..f5e52ac9e 100644 --- a/src/test/java/org/springframework/data/jpa/repository/query/StringQueryUnitTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/query/StringQueryUnitTests.java @@ -348,6 +348,18 @@ public class StringQueryUnitTests { assertThat(new StringQuery("select a from A a").hasConstructorExpression(), is(false)); } + /** + * @see DATAJPA-886 + * @see JPA 2.1 specification, section 4.8 + */ + @Test + public void detectsConstructorExpressionForDefaultConstructor() { + + // Parentheses required + assertThat(new StringQuery("select new Dto() from A a").hasConstructorExpression(), is(true)); + assertThat(new StringQuery("select new Dto from A a").hasConstructorExpression(), is(false)); + } + private void assertPositionalBinding(Class bindingType, Integer position, ParameterBinding expectedBinding) {