From a6768e6a9dc6c31fcd4121824c1b9847c924a106 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sat, 9 Apr 2016 18:32:49 +0200 Subject: [PATCH] minor fix --- .../persistence/IntegrationTestSuite.java | 18 +++++++++++------- ... FooSortingPersistenceIntegrationTest.java} | 2 +- ...ooPaginationPersistenceIntegrationTest.java | 9 ++++++--- .../FooServicePersistenceIntegrationTest.java | 4 ++-- ...a => FooServiceSortingIntegrationTest.java} | 7 +++++-- ...eSortingWitNullsManualIntegrationTest.java} | 4 +++- ....java => JpaMultipleDBIntegrationTest.java} | 4 +--- .../service/PersistenceTestSuite.java | 7 +++---- 8 files changed, 32 insertions(+), 23 deletions(-) rename spring-hibernate4/src/test/java/com/baeldung/persistence/hibernate/{FooSortingPersistenceServiceTest.java => FooSortingPersistenceIntegrationTest.java} (99%) rename spring-jpa/src/test/java/org/baeldung/persistence/service/{FooServiceSortingTests.java => FooServiceSortingIntegrationTest.java} (95%) rename spring-jpa/src/test/java/org/baeldung/persistence/service/{FooServiceSortingWitNullsManualTest.java => FooServiceSortingWitNullsManualIntegrationTest.java} (93%) rename spring-jpa/src/test/java/org/baeldung/persistence/service/{JpaMultipleDBTest.java => JpaMultipleDBIntegrationTest.java} (94%) diff --git a/spring-hibernate4/src/test/java/com/baeldung/persistence/IntegrationTestSuite.java b/spring-hibernate4/src/test/java/com/baeldung/persistence/IntegrationTestSuite.java index c107a221d6..f5c45a5d6f 100644 --- a/spring-hibernate4/src/test/java/com/baeldung/persistence/IntegrationTestSuite.java +++ b/spring-hibernate4/src/test/java/com/baeldung/persistence/IntegrationTestSuite.java @@ -1,20 +1,24 @@ package com.baeldung.persistence; -import com.baeldung.persistence.hibernate.FooPaginationPersistenceIntegrationTest; -import com.baeldung.persistence.hibernate.FooSortingPersistenceServiceTest; -import com.baeldung.persistence.service.FooServicePersistenceIntegrationTest; -import com.baeldung.persistence.service.FooServiceBasicPersistenceIntegrationTest; -import com.baeldung.persistence.service.ParentServicePersistenceIntegrationTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; +import com.baeldung.persistence.audit.AuditTestSuite; +import com.baeldung.persistence.hibernate.FooPaginationPersistenceIntegrationTest; +import com.baeldung.persistence.hibernate.FooSortingPersistenceIntegrationTest; +import com.baeldung.persistence.service.FooServiceBasicPersistenceIntegrationTest; +import com.baeldung.persistence.service.FooServicePersistenceIntegrationTest; +import com.baeldung.persistence.service.ParentServicePersistenceIntegrationTest; + @RunWith(Suite.class) @Suite.SuiteClasses({ // @formatter:off - FooServiceBasicPersistenceIntegrationTest.class + AuditTestSuite.class + ,FooServiceBasicPersistenceIntegrationTest.class ,FooPaginationPersistenceIntegrationTest.class ,FooServicePersistenceIntegrationTest.class ,ParentServicePersistenceIntegrationTest.class - ,FooSortingPersistenceServiceTest.class + ,FooSortingPersistenceIntegrationTest.class + }) // @formatter:on public class IntegrationTestSuite { // diff --git a/spring-hibernate4/src/test/java/com/baeldung/persistence/hibernate/FooSortingPersistenceServiceTest.java b/spring-hibernate4/src/test/java/com/baeldung/persistence/hibernate/FooSortingPersistenceIntegrationTest.java similarity index 99% rename from spring-hibernate4/src/test/java/com/baeldung/persistence/hibernate/FooSortingPersistenceServiceTest.java rename to spring-hibernate4/src/test/java/com/baeldung/persistence/hibernate/FooSortingPersistenceIntegrationTest.java index c890e08d15..0f76526960 100644 --- a/spring-hibernate4/src/test/java/com/baeldung/persistence/hibernate/FooSortingPersistenceServiceTest.java +++ b/spring-hibernate4/src/test/java/com/baeldung/persistence/hibernate/FooSortingPersistenceIntegrationTest.java @@ -26,7 +26,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) @SuppressWarnings("unchecked") -public class FooSortingPersistenceServiceTest { +public class FooSortingPersistenceIntegrationTest { @Autowired private SessionFactory sessionFactory; diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/FooPaginationPersistenceIntegrationTest.java b/spring-jpa/src/test/java/org/baeldung/persistence/service/FooPaginationPersistenceIntegrationTest.java index 73c36190f9..091bec0ba0 100644 --- a/spring-jpa/src/test/java/org/baeldung/persistence/service/FooPaginationPersistenceIntegrationTest.java +++ b/spring-jpa/src/test/java/org/baeldung/persistence/service/FooPaginationPersistenceIntegrationTest.java @@ -88,11 +88,12 @@ public class FooPaginationPersistenceIntegrationTest { public final void givenEntitiesExist_whenRetrievingPage_thenCorrect() { final int pageSize = 10; - final Query queryIds = entityManager.createQuery("Select f.id from Foo f order by f.lastName"); + final Query queryIds = entityManager.createQuery("Select f.id from Foo f order by f.name"); final List fooIds = queryIds.getResultList(); - final Query query = entityManager.createQuery("Select f from Foo e whet f.id in :ids"); + final Query query = entityManager.createQuery("Select f from Foo as f where f.id in :ids"); query.setParameter("ids", fooIds.subList(0, pageSize)); + final List fooList = query.getResultList(); // Then @@ -129,13 +130,15 @@ public class FooPaginationPersistenceIntegrationTest { final Root from = criteriaQuery.from(Foo.class); final CriteriaQuery select = criteriaQuery.select(from); - final TypedQuery typedQuery = entityManager.createQuery(select); + TypedQuery typedQuery; while (pageNumber < count.intValue()) { + typedQuery = entityManager.createQuery(select); typedQuery.setFirstResult(pageNumber - 1); typedQuery.setMaxResults(pageSize); System.out.println("Current page: " + typedQuery.getResultList()); pageNumber += pageSize; } + } // UTIL diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java b/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java index 96b3235f64..4c57865f74 100644 --- a/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java +++ b/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java @@ -36,7 +36,7 @@ public class FooServicePersistenceIntegrationTest { @Test(expected = DataIntegrityViolationException.class) public final void whenInvalidEntityIsCreated_thenDataException() { - service.create(new Foo()); + service.create(new Foo(randomAlphabetic(2048))); } @Test(expected = DataIntegrityViolationException.class) @@ -53,7 +53,7 @@ public class FooServicePersistenceIntegrationTest { @Test(expected = DataAccessException.class) public final void temp_whenInvalidEntityIsCreated_thenDataException() { - service.create(new Foo()); + service.create(new Foo(randomAlphabetic(2048))); } @Test diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingTests.java b/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingIntegrationTest.java similarity index 95% rename from spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingTests.java rename to spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingIntegrationTest.java index 319d36151e..3c9f509da5 100644 --- a/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingTests.java +++ b/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingIntegrationTest.java @@ -22,7 +22,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { PersistenceJPAConfig.class }, loader = AnnotationConfigContextLoader.class) @SuppressWarnings("unchecked") -public class FooServiceSortingTests { +public class FooServiceSortingIntegrationTest { @PersistenceContext private EntityManager entityManager; @@ -65,7 +65,10 @@ public class FooServiceSortingTests { final Query barJoinQuery = entityManager.createQuery(jql); final List fooList = barJoinQuery.getResultList(); for (final Foo foo : fooList) { - System.out.println("Name:" + foo.getName() + "-------BarId:" + foo.getBar().getId()); + System.out.println("Name:" + foo.getName()); + if (foo.getBar() != null) { + System.out.print("-------BarId:" + foo.getBar().getId()); + } } } diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingWitNullsManualTest.java b/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingWitNullsManualIntegrationTest.java similarity index 93% rename from spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingWitNullsManualTest.java rename to spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingWitNullsManualIntegrationTest.java index 986e4e4a7d..040eee1c73 100644 --- a/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingWitNullsManualTest.java +++ b/spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingWitNullsManualIntegrationTest.java @@ -20,7 +20,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { PersistenceJPAConfig.class }, loader = AnnotationConfigContextLoader.class) -public class FooServiceSortingWitNullsManualTest { +public class FooServiceSortingWitNullsManualIntegrationTest { @PersistenceContext private EntityManager entityManager; @@ -30,6 +30,7 @@ public class FooServiceSortingWitNullsManualTest { // tests + @SuppressWarnings("unchecked") @Test public final void whenSortingByStringNullLast_thenLastNull() { service.create(new Foo()); @@ -44,6 +45,7 @@ public class FooServiceSortingWitNullsManualTest { } } + @SuppressWarnings("unchecked") @Test public final void whenSortingByStringNullFirst_thenFirstNull() { service.create(new Foo()); diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/JpaMultipleDBTest.java b/spring-jpa/src/test/java/org/baeldung/persistence/service/JpaMultipleDBIntegrationTest.java similarity index 94% rename from spring-jpa/src/test/java/org/baeldung/persistence/service/JpaMultipleDBTest.java rename to spring-jpa/src/test/java/org/baeldung/persistence/service/JpaMultipleDBIntegrationTest.java index 427e182d9e..e036a4f3c1 100644 --- a/spring-jpa/src/test/java/org/baeldung/persistence/service/JpaMultipleDBTest.java +++ b/spring-jpa/src/test/java/org/baeldung/persistence/service/JpaMultipleDBIntegrationTest.java @@ -15,13 +15,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.transaction.annotation.Transactional; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { UserConfig.class, ProductConfig.class }) -@TransactionConfiguration -public class JpaMultipleDBTest { +public class JpaMultipleDBIntegrationTest { @Autowired private UserRepository userRepository; diff --git a/spring-jpa/src/test/java/org/baeldung/persistence/service/PersistenceTestSuite.java b/spring-jpa/src/test/java/org/baeldung/persistence/service/PersistenceTestSuite.java index 919171de9f..aa2dfb5293 100644 --- a/spring-jpa/src/test/java/org/baeldung/persistence/service/PersistenceTestSuite.java +++ b/spring-jpa/src/test/java/org/baeldung/persistence/service/PersistenceTestSuite.java @@ -7,10 +7,9 @@ import org.junit.runners.Suite; @Suite.SuiteClasses({ // @formatter:off FooPaginationPersistenceIntegrationTest.class ,FooServicePersistenceIntegrationTest.class - ,FooServiceSortingTests.class - ,JpaMultipleDBTest.class - // manual only - // ,FooServiceSortingWitNullsManualTest.class + ,FooServiceSortingIntegrationTest.class + ,JpaMultipleDBIntegrationTest.class + ,FooServiceSortingWitNullsManualIntegrationTest.class }) // @formatter:on public class PersistenceTestSuite { //