lazy_load_no_trans init commit (#8736)
* lazy_load_no_trans init commit * refactoring * methods naming * Update persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOnIntegrationTest.java Co-Authored-By: KevinGilmore <kpg102@gmail.com> * Update persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOnIntegrationTest.java Co-Authored-By: KevinGilmore <kpg102@gmail.com> * Update persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOffIntegrationTest.java Co-Authored-By: KevinGilmore <kpg102@gmail.com> * naming * code readability Co-authored-by: admin <git-commit-id-plugin> Co-authored-by: KevinGilmore <kpg102@gmail.com>
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
package com.baeldung.lazy_load_no_trans;
|
||||
|
||||
import com.baeldung.h2db.lazy_load_no_trans.LazyLoadNoTransSpringBootApplication;
|
||||
import com.baeldung.h2db.lazy_load_no_trans.service.ServiceLayer;
|
||||
import com.vladmihalcea.sql.SQLStatementCountValidator;
|
||||
import org.hibernate.LazyInitializationException;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = LazyLoadNoTransSpringBootApplication.class)
|
||||
@ActiveProfiles("lazy-load-no-trans-off")
|
||||
public class LazyLoadNoTransPropertyOffIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ServiceLayer serviceLayer;
|
||||
|
||||
private static final long EXPECTED_DOCS_COLLECTION_SIZE = 6;
|
||||
|
||||
@Test(expected = LazyInitializationException.class)
|
||||
public void whenCallNonTransactionalMethodWithPropertyOff_thenThrowException() {
|
||||
serviceLayer.countAllDocsNonTransactional();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallTransactionalMethodWithPropertyOff_thenTestPass() {
|
||||
SQLStatementCountValidator.reset();
|
||||
|
||||
long docsCount = serviceLayer.countAllDocsTransactional();
|
||||
|
||||
assertEquals(EXPECTED_DOCS_COLLECTION_SIZE, docsCount);
|
||||
|
||||
SQLStatementCountValidator.assertSelectCount(2);
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.baeldung.lazy_load_no_trans;
|
||||
|
||||
import com.baeldung.h2db.lazy_load_no_trans.LazyLoadNoTransSpringBootApplication;
|
||||
import com.baeldung.h2db.lazy_load_no_trans.service.ServiceLayer;
|
||||
import com.vladmihalcea.sql.SQLStatementCountValidator;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = LazyLoadNoTransSpringBootApplication.class)
|
||||
@ActiveProfiles("lazy-load-no-trans-on")
|
||||
public class LazyLoadNoTransPropertyOnIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ServiceLayer serviceLayer;
|
||||
|
||||
private static final long EXPECTED_DOCS_COLLECTION_SIZE = 6;
|
||||
private static final long EXPECTED_USERS_COUNT = 5;
|
||||
|
||||
@Test
|
||||
public void whenCallNonTransactionalMethodWithPropertyOn_thenGetNplusOne() {
|
||||
SQLStatementCountValidator.reset();
|
||||
|
||||
long docsCount = serviceLayer.countAllDocsNonTransactional();
|
||||
|
||||
assertEquals(EXPECTED_DOCS_COLLECTION_SIZE, docsCount);
|
||||
|
||||
SQLStatementCountValidator.assertSelectCount(EXPECTED_USERS_COUNT + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallTransactionalMethodWithPropertyOn_thenTestPass() {
|
||||
SQLStatementCountValidator.reset();
|
||||
|
||||
long docsCount = serviceLayer.countAllDocsTransactional();
|
||||
|
||||
assertEquals(EXPECTED_DOCS_COLLECTION_SIZE, docsCount);
|
||||
|
||||
SQLStatementCountValidator.assertSelectCount(2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user