minor fix

This commit is contained in:
DOHA 2016-04-09 18:32:49 +02:00
parent d575f443bc
commit a6768e6a9d
8 changed files with 32 additions and 23 deletions

View File

@ -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 {
//

View File

@ -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;

View File

@ -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<Integer> 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<Foo> fooList = query.getResultList();
// Then
@ -129,13 +130,15 @@ public class FooPaginationPersistenceIntegrationTest {
final Root<Foo> from = criteriaQuery.from(Foo.class);
final CriteriaQuery<Foo> select = criteriaQuery.select(from);
final TypedQuery<Foo> typedQuery = entityManager.createQuery(select);
TypedQuery<Foo> 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

View File

@ -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

View File

@ -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<Foo> 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());
}
}
}

View File

@ -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());

View File

@ -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;

View File

@ -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 {
//