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; 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.runner.RunWith;
import org.junit.runners.Suite; 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) @RunWith(Suite.class)
@Suite.SuiteClasses({ // @formatter:off @Suite.SuiteClasses({ // @formatter:off
FooServiceBasicPersistenceIntegrationTest.class AuditTestSuite.class
,FooServiceBasicPersistenceIntegrationTest.class
,FooPaginationPersistenceIntegrationTest.class ,FooPaginationPersistenceIntegrationTest.class
,FooServicePersistenceIntegrationTest.class ,FooServicePersistenceIntegrationTest.class
,ParentServicePersistenceIntegrationTest.class ,ParentServicePersistenceIntegrationTest.class
,FooSortingPersistenceServiceTest.class ,FooSortingPersistenceIntegrationTest.class
}) // @formatter:on }) // @formatter:on
public class IntegrationTestSuite { public class IntegrationTestSuite {
// //

View File

@ -26,7 +26,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class)
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class FooSortingPersistenceServiceTest { public class FooSortingPersistenceIntegrationTest {
@Autowired @Autowired
private SessionFactory sessionFactory; private SessionFactory sessionFactory;

View File

@ -88,11 +88,12 @@ public class FooPaginationPersistenceIntegrationTest {
public final void givenEntitiesExist_whenRetrievingPage_thenCorrect() { public final void givenEntitiesExist_whenRetrievingPage_thenCorrect() {
final int pageSize = 10; 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 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)); query.setParameter("ids", fooIds.subList(0, pageSize));
final List<Foo> fooList = query.getResultList(); final List<Foo> fooList = query.getResultList();
// Then // Then
@ -129,13 +130,15 @@ public class FooPaginationPersistenceIntegrationTest {
final Root<Foo> from = criteriaQuery.from(Foo.class); final Root<Foo> from = criteriaQuery.from(Foo.class);
final CriteriaQuery<Foo> select = criteriaQuery.select(from); final CriteriaQuery<Foo> select = criteriaQuery.select(from);
final TypedQuery<Foo> typedQuery = entityManager.createQuery(select); TypedQuery<Foo> typedQuery;
while (pageNumber < count.intValue()) { while (pageNumber < count.intValue()) {
typedQuery = entityManager.createQuery(select);
typedQuery.setFirstResult(pageNumber - 1); typedQuery.setFirstResult(pageNumber - 1);
typedQuery.setMaxResults(pageSize); typedQuery.setMaxResults(pageSize);
System.out.println("Current page: " + typedQuery.getResultList()); System.out.println("Current page: " + typedQuery.getResultList());
pageNumber += pageSize; pageNumber += pageSize;
} }
} }
// UTIL // UTIL

View File

@ -36,7 +36,7 @@ public class FooServicePersistenceIntegrationTest {
@Test(expected = DataIntegrityViolationException.class) @Test(expected = DataIntegrityViolationException.class)
public final void whenInvalidEntityIsCreated_thenDataException() { public final void whenInvalidEntityIsCreated_thenDataException() {
service.create(new Foo()); service.create(new Foo(randomAlphabetic(2048)));
} }
@Test(expected = DataIntegrityViolationException.class) @Test(expected = DataIntegrityViolationException.class)
@ -53,7 +53,7 @@ public class FooServicePersistenceIntegrationTest {
@Test(expected = DataAccessException.class) @Test(expected = DataAccessException.class)
public final void temp_whenInvalidEntityIsCreated_thenDataException() { public final void temp_whenInvalidEntityIsCreated_thenDataException() {
service.create(new Foo()); service.create(new Foo(randomAlphabetic(2048)));
} }
@Test @Test

View File

@ -22,7 +22,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { PersistenceJPAConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = { PersistenceJPAConfig.class }, loader = AnnotationConfigContextLoader.class)
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class FooServiceSortingTests { public class FooServiceSortingIntegrationTest {
@PersistenceContext @PersistenceContext
private EntityManager entityManager; private EntityManager entityManager;
@ -65,7 +65,10 @@ public class FooServiceSortingTests {
final Query barJoinQuery = entityManager.createQuery(jql); final Query barJoinQuery = entityManager.createQuery(jql);
final List<Foo> fooList = barJoinQuery.getResultList(); final List<Foo> fooList = barJoinQuery.getResultList();
for (final Foo foo : fooList) { 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) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { PersistenceJPAConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = { PersistenceJPAConfig.class }, loader = AnnotationConfigContextLoader.class)
public class FooServiceSortingWitNullsManualTest { public class FooServiceSortingWitNullsManualIntegrationTest {
@PersistenceContext @PersistenceContext
private EntityManager entityManager; private EntityManager entityManager;
@ -30,6 +30,7 @@ public class FooServiceSortingWitNullsManualTest {
// tests // tests
@SuppressWarnings("unchecked")
@Test @Test
public final void whenSortingByStringNullLast_thenLastNull() { public final void whenSortingByStringNullLast_thenLastNull() {
service.create(new Foo()); service.create(new Foo());
@ -44,6 +45,7 @@ public class FooServiceSortingWitNullsManualTest {
} }
} }
@SuppressWarnings("unchecked")
@Test @Test
public final void whenSortingByStringNullFirst_thenFirstNull() { public final void whenSortingByStringNullFirst_thenFirstNull() {
service.create(new Foo()); 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.dao.DataIntegrityViolationException;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { UserConfig.class, ProductConfig.class }) @ContextConfiguration(classes = { UserConfig.class, ProductConfig.class })
@TransactionConfiguration public class JpaMultipleDBIntegrationTest {
public class JpaMultipleDBTest {
@Autowired @Autowired
private UserRepository userRepository; private UserRepository userRepository;

View File

@ -7,10 +7,9 @@ import org.junit.runners.Suite;
@Suite.SuiteClasses({ // @formatter:off @Suite.SuiteClasses({ // @formatter:off
FooPaginationPersistenceIntegrationTest.class FooPaginationPersistenceIntegrationTest.class
,FooServicePersistenceIntegrationTest.class ,FooServicePersistenceIntegrationTest.class
,FooServiceSortingTests.class ,FooServiceSortingIntegrationTest.class
,JpaMultipleDBTest.class ,JpaMultipleDBIntegrationTest.class
// manual only ,FooServiceSortingWitNullsManualIntegrationTest.class
// ,FooServiceSortingWitNullsManualTest.class
}) // @formatter:on }) // @formatter:on
public class PersistenceTestSuite { public class PersistenceTestSuite {
// //