Skip to content

Instantly share code, notes, and snippets.

@csokol
Last active May 3, 2018 09:40
Show Gist options
  • Save csokol/a37356da3400d57edc1e460e9674efdc to your computer and use it in GitHub Desktop.
Save csokol/a37356da3400d57edc1e460e9674efdc to your computer and use it in GitHub Desktop.
@RunWith(SpringRunner.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace = Replace.NONE)
public class FooTest {
@Autowired
private EntityManager em;
@AfterTransaction
public void showCountAfterTransaction() {
Long count = (Long) em.createQuery("select count(f.id) from Foo f").getSingleResult();
System.err.println("after tx: " + count);
}
@Before
public void before() {
Long count = (Long) em.createQuery("select count(f.id) from Foo f").getSingleResult();
System.err.println("before: " + count);
}
@Test
public void persist() throws Exception {
em.persist(new Foo());
Long count = (Long) em.createQuery("select count(f.id) from Foo f").getSingleResult();
System.err.println("after persist: " + count);
}
}
Hibernate: select count(foo0_.id) as col_0_0_ from foo foo0_
before: 10
Hibernate: insert into foo values ( )
Hibernate: select count(foo0_.id) as col_0_0_ from foo foo0_
after persist: 11
2018-05-03 11:39:44.825 INFO 98890 --- [ main] o.s.t.c.transaction.TransactionContext : Rolled back transaction for test context [DefaultTestContext@35adf623 testClass = FooTest, testInstance = com.acma.FooTest@456f7d9e, testMethod = persist@FooTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@75d366c2 testClass = FooTest, locations = '{}', classes = '{class com.acma.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[[ImportsContextCustomizer@8f40022 key = [org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration, org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration, org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration, org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration, org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration, org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManagerAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@4386f16, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@3eb7fc54, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@49d904ec, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@351584c0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@88e30a3c, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@6a400542], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]].
Hibernate: select count(foo0_.id) as col_0_0_ from foo foo0_
2018-05-03 11:39:44.860 INFO 98890 --- [ Thread-4] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@51768776: startup date [Thu May 03 11:39:41 CEST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@4fce136b
after tx: 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment