JAVA-8435: reducing logging for tutorials-integration job
This commit is contained in:
parent
ee70035562
commit
686857c251
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="15 seconds" debug="false">
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="15 seconds" debug="false">
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -1,10 +1,7 @@
|
||||||
package com.baeldung.h2db.lazy_load_no_trans.config;
|
package com.baeldung.h2db.lazy_load_no_trans.config;
|
||||||
|
|
||||||
import net.ttddyy.dsproxy.listener.DataSourceQueryCountListener;
|
import net.ttddyy.dsproxy.listener.DataSourceQueryCountListener;
|
||||||
import net.ttddyy.dsproxy.listener.logging.CommonsQueryLoggingListener;
|
|
||||||
import net.ttddyy.dsproxy.listener.logging.DefaultQueryLogEntryCreator;
|
|
||||||
import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel;
|
import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel;
|
||||||
import net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener;
|
|
||||||
import net.ttddyy.dsproxy.support.ProxyDataSource;
|
import net.ttddyy.dsproxy.support.ProxyDataSource;
|
||||||
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder;
|
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder;
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
|
@ -49,7 +46,7 @@ public class DatasourceProxyBeanPostProcessor implements BeanPostProcessor {
|
||||||
this.dataSource = ProxyDataSourceBuilder.create(dataSource)
|
this.dataSource = ProxyDataSourceBuilder.create(dataSource)
|
||||||
.name("MyDS")
|
.name("MyDS")
|
||||||
.multiline()
|
.multiline()
|
||||||
.logQueryBySlf4j(SLF4JLogLevel.INFO)
|
.logQueryBySlf4j(SLF4JLogLevel.DEBUG)
|
||||||
.listener(new DataSourceQueryCountListener())
|
.listener(new DataSourceQueryCountListener())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ spring.datasource.username=sa
|
||||||
spring.datasource.password=
|
spring.datasource.password=
|
||||||
spring.jpa.defer-datasource-initialization=true
|
spring.jpa.defer-datasource-initialization=true
|
||||||
spring.jpa.hibernate.ddl-auto=create-drop
|
spring.jpa.hibernate.ddl-auto=create-drop
|
||||||
spring.jpa.show-sql=true
|
spring.jpa.show-sql=false
|
||||||
spring.jpa.properties.hibernate.format_sql=true
|
spring.jpa.properties.hibernate.format_sql=true
|
||||||
spring.jpa.properties.hibernate.validator.apply_to_ddl=false
|
spring.jpa.properties.hibernate.validator.apply_to_ddl=false
|
||||||
#spring.jpa.properties.hibernate.check_nullability=true
|
#spring.jpa.properties.hibernate.check_nullability=true
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="15 seconds" debug="false">
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="15 seconds" debug="false">
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -123,24 +123,39 @@ public class EnversFooBarAuditIntegrationTest {
|
||||||
assertNotNull(barRevisionList);
|
assertNotNull(barRevisionList);
|
||||||
assertEquals(4, barRevisionList.size());
|
assertEquals(4, barRevisionList.size());
|
||||||
|
|
||||||
assertEquals("BAR", barRevisionList.get(0).getName());
|
assertEquals("BAR", barRevisionList.get(0)
|
||||||
assertEquals("BAR", barRevisionList.get(1).getName());
|
.getName());
|
||||||
assertEquals("BAR1", barRevisionList.get(2).getName());
|
assertEquals("BAR", barRevisionList.get(1)
|
||||||
assertEquals("BAR1", barRevisionList.get(3).getName());
|
.getName());
|
||||||
|
assertEquals("BAR1", barRevisionList.get(2)
|
||||||
|
.getName());
|
||||||
|
assertEquals("BAR1", barRevisionList.get(3)
|
||||||
|
.getName());
|
||||||
|
|
||||||
assertEquals(1, barRevisionList.get(0).getFooSet().size());
|
assertEquals(1, barRevisionList.get(0)
|
||||||
assertEquals(2, barRevisionList.get(1).getFooSet().size());
|
.getFooSet()
|
||||||
assertEquals(2, barRevisionList.get(2).getFooSet().size());
|
.size());
|
||||||
assertEquals(3, barRevisionList.get(3).getFooSet().size());
|
assertEquals(2, barRevisionList.get(1)
|
||||||
|
.getFooSet()
|
||||||
|
.size());
|
||||||
|
assertEquals(2, barRevisionList.get(2)
|
||||||
|
.getFooSet()
|
||||||
|
.size());
|
||||||
|
assertEquals(3, barRevisionList.get(3)
|
||||||
|
.getFooSet()
|
||||||
|
.size());
|
||||||
|
|
||||||
// test Foo revisions
|
// test Foo revisions
|
||||||
|
|
||||||
fooRevisionList = fooService.getRevisions();
|
fooRevisionList = fooService.getRevisions();
|
||||||
assertNotNull(fooRevisionList);
|
assertNotNull(fooRevisionList);
|
||||||
assertEquals(3, fooRevisionList.size());
|
assertEquals(3, fooRevisionList.size());
|
||||||
assertEquals("FOO1", fooRevisionList.get(0).getName());
|
assertEquals("FOO1", fooRevisionList.get(0)
|
||||||
assertEquals("FOO2", fooRevisionList.get(1).getName());
|
.getName());
|
||||||
assertEquals("FOO3", fooRevisionList.get(2).getName());
|
assertEquals("FOO2", fooRevisionList.get(1)
|
||||||
|
.getName());
|
||||||
|
assertEquals("FOO3", fooRevisionList.get(2)
|
||||||
|
.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,13 @@ import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class FooFixtures {
|
public class FooFixtures {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(FooFixtures.class);
|
||||||
|
|
||||||
private SessionFactory sessionFactory;
|
private SessionFactory sessionFactory;
|
||||||
|
|
||||||
public FooFixtures(final SessionFactory sessionFactory) {
|
public FooFixtures(final SessionFactory sessionFactory) {
|
||||||
|
@ -36,26 +41,30 @@ public class FooFixtures {
|
||||||
foo.setBar(bar);
|
foo.setBar(bar);
|
||||||
session.save(foo);
|
session.save(foo);
|
||||||
final Foo foo2 = new Foo(null);
|
final Foo foo2 = new Foo(null);
|
||||||
if (i % 2 == 0)
|
if (i % 2 == 0) {
|
||||||
foo2.setName("LuckyFoo" + (i + 120));
|
foo2.setName("LuckyFoo" + (i + 120));
|
||||||
|
}
|
||||||
foo2.setBar(bar);
|
foo2.setBar(bar);
|
||||||
session.save(foo2);
|
session.save(foo2);
|
||||||
bar.getFooSet().add(foo);
|
bar.getFooSet()
|
||||||
bar.getFooSet().add(foo2);
|
.add(foo);
|
||||||
|
bar.getFooSet()
|
||||||
|
.add(foo2);
|
||||||
session.merge(bar);
|
session.merge(bar);
|
||||||
}
|
}
|
||||||
tx.commit();
|
tx.commit();
|
||||||
session.flush();
|
session.flush();
|
||||||
} catch (final HibernateException he) {
|
} catch (final HibernateException he) {
|
||||||
if (tx != null)
|
if (tx != null) {
|
||||||
tx.rollback();
|
tx.rollback();
|
||||||
System.out.println("Not able to open session");
|
}
|
||||||
he.printStackTrace();
|
LOGGER.error("Not able to open session", he);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
LOGGER.error(e.getLocalizedMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
if (session != null)
|
if (session != null) {
|
||||||
session.close();
|
session.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -71,7 +80,8 @@ public class FooFixtures {
|
||||||
final Foo foo = new Foo();
|
final Foo foo = new Foo();
|
||||||
foo.setName("Foo_" + (i + 120));
|
foo.setName("Foo_" + (i + 120));
|
||||||
final Bar bar = new Bar("bar_" + i);
|
final Bar bar = new Bar("bar_" + i);
|
||||||
bar.getFooSet().add(foo);
|
bar.getFooSet()
|
||||||
|
.add(foo);
|
||||||
foo.setBar(bar);
|
foo.setBar(bar);
|
||||||
fooList.add(foo);
|
fooList.add(foo);
|
||||||
|
|
||||||
|
@ -86,15 +96,16 @@ public class FooFixtures {
|
||||||
tx.commit();
|
tx.commit();
|
||||||
session.flush();
|
session.flush();
|
||||||
} catch (final HibernateException he) {
|
} catch (final HibernateException he) {
|
||||||
if (tx != null)
|
if (tx != null) {
|
||||||
tx.rollback();
|
tx.rollback();
|
||||||
System.out.println("Not able to open session");
|
}
|
||||||
he.printStackTrace();
|
LOGGER.error("Not able to open session", he);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
LOGGER.error(e.getLocalizedMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
if (session != null)
|
if (session != null) {
|
||||||
session.close();
|
session.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
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;
|
||||||
|
@ -29,6 +31,8 @@ import com.baeldung.spring.config.PersistenceTestConfig;
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class FooSortingPersistenceIntegrationTest {
|
public class FooSortingPersistenceIntegrationTest {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(FooSortingPersistenceIntegrationTest.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SessionFactory sessionFactory;
|
private SessionFactory sessionFactory;
|
||||||
|
|
||||||
|
@ -46,7 +50,8 @@ public class FooSortingPersistenceIntegrationTest {
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void after() {
|
public void after() {
|
||||||
session.getTransaction().commit();
|
session.getTransaction()
|
||||||
|
.commit();
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +61,7 @@ public class FooSortingPersistenceIntegrationTest {
|
||||||
final Query query = session.createQuery(hql);
|
final Query query = session.createQuery(hql);
|
||||||
final List<Foo> fooList = query.list();
|
final List<Foo> fooList = query.list();
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
LOGGER.debug("Name: {} , Id: {}", foo.getName(), foo.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,9 +71,10 @@ public class FooSortingPersistenceIntegrationTest {
|
||||||
final Query query = session.createQuery(hql);
|
final Query query = session.createQuery(hql);
|
||||||
final List<Foo> fooList = query.list();
|
final List<Foo> fooList = query.list();
|
||||||
|
|
||||||
assertNull(fooList.get(fooList.toArray().length - 1).getName());
|
assertNull(fooList.get(fooList.toArray().length - 1)
|
||||||
|
.getName());
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
LOGGER.debug("Name: {}, Id: {}", foo.getName(), foo.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,9 +83,10 @@ public class FooSortingPersistenceIntegrationTest {
|
||||||
final String hql = "FROM Foo f ORDER BY f.name NULLS FIRST";
|
final String hql = "FROM Foo f ORDER BY f.name NULLS FIRST";
|
||||||
final Query query = session.createQuery(hql);
|
final Query query = session.createQuery(hql);
|
||||||
final List<Foo> fooList = query.list();
|
final List<Foo> fooList = query.list();
|
||||||
assertNull(fooList.get(0).getName());
|
assertNull(fooList.get(0)
|
||||||
|
.getName());
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name:" + foo.getName());
|
LOGGER.debug("Name: {}", foo.getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +97,7 @@ public class FooSortingPersistenceIntegrationTest {
|
||||||
final Query query = session.createQuery(hql);
|
final Query query = session.createQuery(hql);
|
||||||
final List<Foo> fooList = query.list();
|
final List<Foo> fooList = query.list();
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
LOGGER.debug("Name: {}, Id: {}", foo.getName(), foo.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +107,7 @@ public class FooSortingPersistenceIntegrationTest {
|
||||||
final Query query = session.createQuery(hql);
|
final Query query = session.createQuery(hql);
|
||||||
final List<Foo> fooList = query.list();
|
final List<Foo> fooList = query.list();
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
LOGGER.debug("Name: {}, Id: {}", foo.getName(), foo.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +117,7 @@ public class FooSortingPersistenceIntegrationTest {
|
||||||
final Query query = session.createQuery(hql);
|
final Query query = session.createQuery(hql);
|
||||||
final List<Foo> fooList = query.list();
|
final List<Foo> fooList = query.list();
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
LOGGER.debug("Name: {}, Id: {}", foo.getName(), foo.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +127,7 @@ public class FooSortingPersistenceIntegrationTest {
|
||||||
criteria.addOrder(Order.asc("id"));
|
criteria.addOrder(Order.asc("id"));
|
||||||
final List<Foo> fooList = criteria.list();
|
final List<Foo> fooList = criteria.list();
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Id: " + foo.getId() + ", FirstName: " + foo.getName());
|
LOGGER.debug("Id: {}, FirstName: {}", foo.getId(), foo.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,29 +138,33 @@ public class FooSortingPersistenceIntegrationTest {
|
||||||
criteria.addOrder(Order.asc("id"));
|
criteria.addOrder(Order.asc("id"));
|
||||||
final List<Foo> fooList = criteria.list();
|
final List<Foo> fooList = criteria.list();
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Id: " + foo.getId() + ", FirstName: " + foo.getName());
|
LOGGER.debug("Id: {}, FirstName: {}", foo.getId(), foo.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void whenCriteriaSortingStringNullsLastAsc_thenNullsLast() {
|
public final void whenCriteriaSortingStringNullsLastAsc_thenNullsLast() {
|
||||||
final Criteria criteria = session.createCriteria(Foo.class, "FOO");
|
final Criteria criteria = session.createCriteria(Foo.class, "FOO");
|
||||||
criteria.addOrder(Order.asc("name").nulls(NullPrecedence.LAST));
|
criteria.addOrder(Order.asc("name")
|
||||||
|
.nulls(NullPrecedence.LAST));
|
||||||
final List<Foo> fooList = criteria.list();
|
final List<Foo> fooList = criteria.list();
|
||||||
assertNull(fooList.get(fooList.toArray().length - 1).getName());
|
assertNull(fooList.get(fooList.toArray().length - 1)
|
||||||
|
.getName());
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Id: " + foo.getId() + ", FirstName: " + foo.getName());
|
LOGGER.debug("Id: {}, FirstName: {}", foo.getId(), foo.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void whenCriteriaSortingStringNullsFirstDesc_thenNullsFirst() {
|
public final void whenCriteriaSortingStringNullsFirstDesc_thenNullsFirst() {
|
||||||
final Criteria criteria = session.createCriteria(Foo.class, "FOO");
|
final Criteria criteria = session.createCriteria(Foo.class, "FOO");
|
||||||
criteria.addOrder(Order.desc("name").nulls(NullPrecedence.FIRST));
|
criteria.addOrder(Order.desc("name")
|
||||||
|
.nulls(NullPrecedence.FIRST));
|
||||||
final List<Foo> fooList = criteria.list();
|
final List<Foo> fooList = criteria.list();
|
||||||
assertNull(fooList.get(0).getName());
|
assertNull(fooList.get(0)
|
||||||
|
.getName());
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Id: " + foo.getId() + ", FirstName: " + foo.getName());
|
LOGGER.debug("Id: {}, FirstName: {}", foo.getId(), foo.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,9 +175,9 @@ public class FooSortingPersistenceIntegrationTest {
|
||||||
final List<Bar> barList = query.list();
|
final List<Bar> barList = query.list();
|
||||||
for (final Bar bar : barList) {
|
for (final Bar bar : barList) {
|
||||||
final Set<Foo> fooSet = bar.getFooSet();
|
final Set<Foo> fooSet = bar.getFooSet();
|
||||||
System.out.println("Bar Id:" + bar.getId());
|
LOGGER.debug("Bar Id:{}", bar.getId());
|
||||||
for (final Foo foo : fooSet) {
|
for (final Foo foo : fooSet) {
|
||||||
System.out.println("FooName:" + foo.getName());
|
LOGGER.debug("FooName:{}", foo.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package com.baeldung.persistence.service;
|
package com.baeldung.persistence.service;
|
||||||
|
|
||||||
|
import com.baeldung.persistence.hibernate.FooSortingPersistenceIntegrationTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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;
|
||||||
|
@ -16,6 +19,8 @@ import com.baeldung.spring.config.PersistenceTestConfig;
|
||||||
@ContextConfiguration(classes = { PersistenceTestConfig.class }, loader = AnnotationConfigContextLoader.class)
|
@ContextConfiguration(classes = { PersistenceTestConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||||
public class ParentServicePersistenceIntegrationTest {
|
public class ParentServicePersistenceIntegrationTest {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ParentServicePersistenceIntegrationTest.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IParentService service;
|
private IParentService service;
|
||||||
|
|
||||||
|
@ -37,11 +42,11 @@ public class ParentServicePersistenceIntegrationTest {
|
||||||
final Parent parentEntity = new Parent(childEntity);
|
final Parent parentEntity = new Parent(childEntity);
|
||||||
service.create(parentEntity);
|
service.create(parentEntity);
|
||||||
|
|
||||||
System.out.println("Child = " + childService.findOne(childEntity.getId()));
|
LOGGER.debug("Child = {}", childService.findOne(childEntity.getId()));
|
||||||
System.out.println("Child - parent = " + childService.findOne(childEntity.getId()).getParent());
|
LOGGER.debug("Child - parent = {}", childService.findOne(childEntity.getId()).getParent());
|
||||||
|
|
||||||
System.out.println("Parent = " + service.findOne(parentEntity.getId()));
|
LOGGER.debug("Parent = {}", service.findOne(parentEntity.getId()));
|
||||||
System.out.println("Parent - child = " + service.findOne(parentEntity.getId()).getChild());
|
LOGGER.debug("Parent - child = {}", service.findOne(parentEntity.getId()).getChild());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DataIntegrityViolationException.class)
|
@Test(expected = DataIntegrityViolationException.class)
|
||||||
|
|
|
@ -166,7 +166,7 @@ public class PersistenceTestConfig {
|
||||||
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
||||||
hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
||||||
|
|
||||||
hibernateProperties.setProperty("hibernate.show_sql", "true");
|
hibernateProperties.setProperty("hibernate.show_sql", "false");
|
||||||
// hibernateProperties.setProperty("hibernate.format_sql", "true");
|
// hibernateProperties.setProperty("hibernate.format_sql", "true");
|
||||||
// hibernateProperties.setProperty("hibernate.globally_quoted_identifiers", "true");
|
// hibernateProperties.setProperty("hibernate.globally_quoted_identifiers", "true");
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@DataJpaTest(properties = "spring.sql.init.data-locations=classpath:insert_users.sql")
|
@DataJpaTest(properties = "spring.sql.init.data-locations=classpath:insert_users.sql", showSql = false)
|
||||||
public class UserRepositoryIntegrationTest {
|
public class UserRepositoryIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -40,46 +40,42 @@ public class UserRepositoryIntegrationTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenFindAllSortedByNameThenAllSorted() {
|
public void whenFindAllSortedByNameThenAllSorted() {
|
||||||
List<User> allUsersSortedByName = userRepository.findAll(Sort.by(Sort.Direction.ASC, "name"));
|
List<User> allUsersSortedByName = userRepository.findAll(Sort.by(Sort.Direction.ASC, "name"));
|
||||||
assertThat(allUsersSortedByName)
|
assertThat(allUsersSortedByName).extracting("name")
|
||||||
.extracting("name")
|
|
||||||
.containsSequence("Bob", "Cindy", "John");
|
.containsSequence("Bob", "Cindy", "John");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenFindAllSortedByNameLengthThenException() {
|
public void whenFindAllSortedByNameLengthThenException() {
|
||||||
assertThatThrownBy(() -> userRepository.findAll(Sort.by("LENGTH(name)")))
|
assertThatThrownBy(() -> userRepository.findAll(Sort.by("LENGTH(name)"))).isInstanceOf(PropertyReferenceException.class);
|
||||||
.isInstanceOf(PropertyReferenceException.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenFindAllUsersSortedByNameThenAllSorted() {
|
public void whenFindAllUsersSortedByNameThenAllSorted() {
|
||||||
List<User> allUsersSortedByName = userRepository.findAllUsers(Sort.by(Sort.Direction.ASC, "name"));
|
List<User> allUsersSortedByName = userRepository.findAllUsers(Sort.by(Sort.Direction.ASC, "name"));
|
||||||
assertThat(allUsersSortedByName)
|
assertThat(allUsersSortedByName).extracting("name")
|
||||||
.extracting("name")
|
|
||||||
.containsSequence("Bob", "Cindy", "John");
|
.containsSequence("Bob", "Cindy", "John");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenFindAllUsersSortedByNameLengthThenAllSorted() {
|
public void whenFindAllUsersSortedByNameLengthThenAllSorted() {
|
||||||
List<User> allUsersSortedByName = userRepository.findAllUsers(JpaSort.unsafe("LENGTH(name)"));
|
List<User> allUsersSortedByName = userRepository.findAllUsers(JpaSort.unsafe("LENGTH(name)"));
|
||||||
assertThat(allUsersSortedByName)
|
assertThat(allUsersSortedByName).extracting("name")
|
||||||
.extracting("name")
|
|
||||||
.containsSequence("Bob", "John", "Cindy");
|
.containsSequence("Bob", "John", "Cindy");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenFindAllUsersWithPaginationThenPaginated() {
|
public void whenFindAllUsersWithPaginationThenPaginated() {
|
||||||
Page<User> page = userRepository.findAllUsersWithPagination(PageRequest.of(0, 1));
|
Page<User> page = userRepository.findAllUsersWithPagination(PageRequest.of(0, 1));
|
||||||
assertThat(page.stream().map(User::getId))
|
assertThat(page.stream()
|
||||||
.hasSize(1)
|
.map(User::getId)).hasSize(1)
|
||||||
.containsOnly(1);
|
.containsOnly(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenFindAllUsersWithPaginationNativeThenPaginated() {
|
public void whenFindAllUsersWithPaginationNativeThenPaginated() {
|
||||||
Page<User> page = userRepository.findAllUsersWithPaginationNative(PageRequest.of(1, 1));
|
Page<User> page = userRepository.findAllUsersWithPaginationNative(PageRequest.of(1, 1));
|
||||||
assertThat(page.stream().map(User::getId))
|
assertThat(page.stream()
|
||||||
.hasSize(1)
|
.map(User::getId)).hasSize(1)
|
||||||
.containsOnly(2);
|
.containsOnly(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,8 +122,7 @@ public class UserRepositoryIntegrationTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenFindUserByNameListThenAllFound() {
|
public void whenFindUserByNameListThenAllFound() {
|
||||||
List<User> users = userRepository.findUserByNameList(Arrays.asList("Bob", "Cindy"));
|
List<User> users = userRepository.findUserByNameList(Arrays.asList("Bob", "Cindy"));
|
||||||
assertThat(users)
|
assertThat(users).extracting("name")
|
||||||
.extracting("name")
|
|
||||||
.containsOnly("Bob", "Cindy");
|
.containsOnly("Bob", "Cindy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@DataJpaTest(properties="spring.sql.init.data-locations=classpath:import_entities.sql")
|
@DataJpaTest(properties="spring.sql.init.data-locations=classpath:import_entities.sql", showSql = false)
|
||||||
public class ArticleRepositoryIntegrationTest {
|
public class ArticleRepositoryIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<property name="hibernate.connection.password"></property>
|
<property name="hibernate.connection.password"></property>
|
||||||
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
|
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
|
||||||
<property name="hibernate.hbm2ddl.auto">update</property>
|
<property name="hibernate.hbm2ddl.auto">update</property>
|
||||||
<property name="show_sql">true</property>
|
<property name="show_sql">false</property>
|
||||||
|
|
||||||
<mapping class="com.baeldung.hibernate.fetching.model.UserEager" />
|
<mapping class="com.baeldung.hibernate.fetching.model.UserEager" />
|
||||||
<mapping class="com.baeldung.hibernate.fetching.model.OrderDetail" />
|
<mapping class="com.baeldung.hibernate.fetching.model.OrderDetail" />
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<property name="hibernate.connection.password"></property>
|
<property name="hibernate.connection.password"></property>
|
||||||
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
|
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
|
||||||
<property name="hibernate.hbm2ddl.auto">update</property>
|
<property name="hibernate.hbm2ddl.auto">update</property>
|
||||||
<property name="show_sql">true</property>
|
<property name="show_sql">false</property>
|
||||||
<mapping class="com.baeldung.hibernate.fetching.model.UserLazy" />
|
<mapping class="com.baeldung.hibernate.fetching.model.UserLazy" />
|
||||||
<mapping class="com.baeldung.hibernate.fetching.model.OrderDetail" />
|
<mapping class="com.baeldung.hibernate.fetching.model.OrderDetail" />
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@ import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@DataJpaTest
|
@DataJpaTest(showSql = false)
|
||||||
|
|
||||||
@Sql(scripts = "/test-aggregation-data.sql")
|
@Sql(scripts = "/test-aggregation-data.sql")
|
||||||
public class SpringDataAggregateIntegrationTest {
|
public class SpringDataAggregateIntegrationTest {
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,7 @@ import static org.hamcrest.core.IsNot.not;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@DataJpaTest(showSql = false)
|
||||||
@DataJpaTest
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
public class PassengerRepositoryIntegrationTest {
|
public class PassengerRepositoryIntegrationTest {
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import com.baeldung.entitygraph.model.Item;
|
||||||
import com.baeldung.entitygraph.repository.CharacteristicsRepository;
|
import com.baeldung.entitygraph.repository.CharacteristicsRepository;
|
||||||
import com.baeldung.entitygraph.repository.ItemRepository;
|
import com.baeldung.entitygraph.repository.ItemRepository;
|
||||||
|
|
||||||
@DataJpaTest
|
@DataJpaTest(showSql = false)
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@Sql(scripts = "/entitygraph-data.sql")
|
@Sql(scripts = "/entitygraph-data.sql")
|
||||||
public class EntityGraphIntegrationTest {
|
public class EntityGraphIntegrationTest {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.data.domain.Example;
|
import org.springframework.data.domain.Example;
|
||||||
import org.springframework.data.domain.ExampleMatcher;
|
import org.springframework.data.domain.ExampleMatcher;
|
||||||
|
import org.springframework.test.context.TestPropertySource;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -19,6 +20,7 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = {Application.class})
|
@SpringBootTest(classes = {Application.class})
|
||||||
|
@TestPropertySource(properties = {"spring.jpa.show-sql=false"})
|
||||||
public class CarRepositoryIntegrationTest {
|
public class CarRepositoryIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -13,10 +13,11 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.TestPropertySource;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@DataJpaTest
|
@DataJpaTest(showSql = false)
|
||||||
@ActiveProfiles("joins")
|
@ActiveProfiles("joins")
|
||||||
public class JpaJoinsIntegrationTest {
|
public class JpaJoinsIntegrationTest {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="15 seconds" debug="false">
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -1,5 +1,7 @@
|
||||||
package com.baeldung.spring.data.persistence.saveperformance;
|
package com.baeldung.spring.data.persistence.saveperformance;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
@ -12,6 +14,8 @@ import java.util.List;
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class BookApplication {
|
public class BookApplication {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(BookApplication.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private BookRepository bookRepository;
|
private BookRepository bookRepository;
|
||||||
|
|
||||||
|
@ -25,13 +29,13 @@ public class BookApplication {
|
||||||
int bookCount = 10000;
|
int bookCount = 10000;
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
for(int i = 0; i < bookCount; i++) {
|
for (int i = 0; i < bookCount; i++) {
|
||||||
bookRepository.save(new Book("Book " + i, "Author " + i));
|
bookRepository.save(new Book("Book " + i, "Author " + i));
|
||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
bookRepository.deleteAll();
|
bookRepository.deleteAll();
|
||||||
|
|
||||||
System.out.println("It took " + (end - start) + "ms to execute save() for " + bookCount + " books");
|
LOGGER.debug("It took {}ms to execute save() for {} books.", (end - start), bookCount);
|
||||||
|
|
||||||
List<Book> bookList = new ArrayList<>();
|
List<Book> bookList = new ArrayList<>();
|
||||||
for (int i = 0; i < bookCount; i++) {
|
for (int i = 0; i < bookCount; i++) {
|
||||||
|
@ -42,7 +46,7 @@ public class BookApplication {
|
||||||
bookRepository.saveAll(bookList);
|
bookRepository.saveAll(bookList);
|
||||||
end = System.currentTimeMillis();
|
end = System.currentTimeMillis();
|
||||||
|
|
||||||
System.out.println("It took " + (end - start) + "ms to execute saveAll() with " + bookCount + " books\n");
|
LOGGER.debug("It took {}ms to execute saveAll() with {}} books.", (end - start), bookCount);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="15 seconds" debug="false">
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -19,7 +19,7 @@ import com.baeldung.Application;
|
||||||
import com.baeldung.boot.domain.MerchandiseEntity;
|
import com.baeldung.boot.domain.MerchandiseEntity;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = Application.class)
|
@SpringBootTest(classes = Application.class, properties = {"spring.jpa.show-sql=false"})
|
||||||
public class InventoryRepositoryIntegrationTest {
|
public class InventoryRepositoryIntegrationTest {
|
||||||
|
|
||||||
private static final String ORIGINAL_TITLE = "Pair of Pants";
|
private static final String ORIGINAL_TITLE = "Pair of Pants";
|
||||||
|
|
|
@ -21,7 +21,7 @@ import com.baeldung.boot.domain.Location;
|
||||||
import com.baeldung.boot.domain.Store;
|
import com.baeldung.boot.domain.Store;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@DataJpaTest(properties="spring.sql.init.data-locations=classpath:import_entities.sql")
|
@DataJpaTest(properties="spring.sql.init.data-locations=classpath:import_entities.sql", showSql = false)
|
||||||
public class JpaRepositoriesIntegrationTest {
|
public class JpaRepositoriesIntegrationTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
private LocationRepository locationRepository;
|
private LocationRepository locationRepository;
|
||||||
|
|
|
@ -17,7 +17,7 @@ import java.util.List;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = QueryApplication.class)
|
@SpringBootTest(classes = QueryApplication.class, properties = {"spring.jpa.show-sql=false"})
|
||||||
public class UserRepositoryIntegrationTest {
|
public class UserRepositoryIntegrationTest {
|
||||||
|
|
||||||
private static final String USER_NAME_ADAM = "Adam";
|
private static final String USER_NAME_ADAM = "Adam";
|
||||||
|
|
|
@ -16,7 +16,7 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TES
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@Sql(scripts = { "/test-movie-data.sql" })
|
@Sql(scripts = { "/test-movie-data.sql" })
|
||||||
@SpringBootTest(classes = LikeApplication.class)
|
@SpringBootTest(classes = LikeApplication.class, properties = {"spring.jpa.show-sql=false"})
|
||||||
@Sql(scripts = "/test-movie-cleanup.sql", executionPhase = AFTER_TEST_METHOD)
|
@Sql(scripts = "/test-movie-cleanup.sql", executionPhase = AFTER_TEST_METHOD)
|
||||||
public class MovieRepositoryIntegrationTest {
|
public class MovieRepositoryIntegrationTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import com.baeldung.entity.Fruit;
|
import com.baeldung.entity.Fruit;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest(properties = {"spring.jpa.show-sql=false"})
|
||||||
public class FruitPopulatorIntegrationTest {
|
public class FruitPopulatorIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import com.baeldung.entity.Passenger;
|
import com.baeldung.entity.Passenger;
|
||||||
|
|
||||||
@DataJpaTest
|
@DataJpaTest(showSql = false)
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
public class PassengerRepositoryIntegrationTest {
|
public class PassengerRepositoryIntegrationTest {
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ import com.baeldung.entity.Song;
|
||||||
import com.baeldung.repository.SongRepository;
|
import com.baeldung.repository.SongRepository;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest(properties = {"spring.jpa.show-sql=false"})
|
||||||
@Sql(scripts = { "/test-song-data.sql" })
|
@Sql(scripts = { "/test-song-data.sql" })
|
||||||
public class SongRepositoryIntegrationTest {
|
public class SongRepositoryIntegrationTest {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="15 seconds" debug="false">
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -74,7 +74,7 @@ public class DynamicUpdateConfig {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.setProperty("hibernate.hbm2ddl.auto", Preconditions.checkNotNull(env.getProperty("hibernate.hbm2ddl.auto")));
|
properties.setProperty("hibernate.hbm2ddl.auto", Preconditions.checkNotNull(env.getProperty("hibernate.hbm2ddl.auto")));
|
||||||
properties.setProperty("hibernate.dialect", Preconditions.checkNotNull(env.getProperty("hibernate.dialect")));
|
properties.setProperty("hibernate.dialect", Preconditions.checkNotNull(env.getProperty("hibernate.dialect")));
|
||||||
properties.setProperty("hibernate.show_sql", "true");
|
properties.setProperty("hibernate.show_sql", "false");
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,8 +6,12 @@ import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class HibernateUtil {
|
public class HibernateUtil {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(HibernateUtil.class);
|
||||||
private static final SessionFactory sessionFactory = buildSessionFactory();
|
private static final SessionFactory sessionFactory = buildSessionFactory();
|
||||||
|
|
||||||
private static SessionFactory buildSessionFactory() {
|
private static SessionFactory buildSessionFactory() {
|
||||||
|
@ -17,10 +21,11 @@ public class HibernateUtil {
|
||||||
configuration.addAnnotatedClass(Event.class);
|
configuration.addAnnotatedClass(Event.class);
|
||||||
configuration.addAnnotatedClass(EventGeneratedId.class);
|
configuration.addAnnotatedClass(EventGeneratedId.class);
|
||||||
configuration.configure("immutable.cfg.xml");
|
configuration.configure("immutable.cfg.xml");
|
||||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
|
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties())
|
||||||
|
.build();
|
||||||
return configuration.buildSessionFactory(serviceRegistry);
|
return configuration.buildSessionFactory(serviceRegistry);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
System.out.println("Initial SessionFactory creation failed." + ex);
|
LOGGER.debug("Initial SessionFactory creation failed.", ex);
|
||||||
throw new ExceptionInInitializerError(ex);
|
throw new ExceptionInInitializerError(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,12 @@ import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import com.baeldung.hibernate.manytomany.model.Employee;
|
import com.baeldung.hibernate.manytomany.model.Employee;
|
||||||
import com.baeldung.hibernate.manytomany.model.Project;
|
import com.baeldung.hibernate.manytomany.model.Project;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class HibernateUtil {
|
public class HibernateUtil {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(HibernateUtil.class);
|
||||||
private static SessionFactory sessionFactory;
|
private static SessionFactory sessionFactory;
|
||||||
|
|
||||||
private static SessionFactory buildSessionFactory() {
|
private static SessionFactory buildSessionFactory() {
|
||||||
|
@ -17,25 +21,25 @@ public class HibernateUtil {
|
||||||
configuration.addAnnotatedClass(Employee.class);
|
configuration.addAnnotatedClass(Employee.class);
|
||||||
configuration.addAnnotatedClass(Project.class);
|
configuration.addAnnotatedClass(Project.class);
|
||||||
configuration.configure("manytomany.cfg.xml");
|
configuration.configure("manytomany.cfg.xml");
|
||||||
System.out.println("Hibernate Annotation Configuration loaded");
|
LOGGER.debug("Hibernate Annotation Configuration loaded");
|
||||||
|
|
||||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties())
|
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties())
|
||||||
.build();
|
.build();
|
||||||
System.out.println("Hibernate Annotation serviceRegistry created");
|
LOGGER.debug("Hibernate Annotation serviceRegistry created");
|
||||||
|
|
||||||
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
|
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
|
||||||
|
|
||||||
return sessionFactory;
|
return sessionFactory;
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
System.err.println("Initial SessionFactory creation failed." + ex);
|
LOGGER.error("Initial SessionFactory creation failed.", ex);
|
||||||
ex.printStackTrace();
|
|
||||||
throw new ExceptionInInitializerError(ex);
|
throw new ExceptionInInitializerError(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SessionFactory getSessionFactory() {
|
public static SessionFactory getSessionFactory() {
|
||||||
if (sessionFactory == null)
|
if (sessionFactory == null) {
|
||||||
sessionFactory = buildSessionFactory();
|
sessionFactory = buildSessionFactory();
|
||||||
|
}
|
||||||
return sessionFactory;
|
return sessionFactory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class PersistenceConfig {
|
||||||
final Properties hibernateProperties = new Properties();
|
final Properties hibernateProperties = new Properties();
|
||||||
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
||||||
hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
||||||
hibernateProperties.setProperty("hibernate.show_sql", "true");
|
hibernateProperties.setProperty("hibernate.show_sql", "false");
|
||||||
|
|
||||||
return hibernateProperties;
|
return hibernateProperties;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class PersistenceConfig {
|
||||||
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
||||||
hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
||||||
|
|
||||||
hibernateProperties.setProperty("hibernate.show_sql", "true");
|
hibernateProperties.setProperty("hibernate.show_sql", "false");
|
||||||
|
|
||||||
// Envers properties
|
// Envers properties
|
||||||
hibernateProperties.setProperty("org.hibernate.envers.audit_table_suffix", env.getProperty("envers.audit_table_suffix"));
|
hibernateProperties.setProperty("org.hibernate.envers.audit_table_suffix", env.getProperty("envers.audit_table_suffix"));
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<property name="current_session_context_class">thread</property>
|
<property name="current_session_context_class">thread</property>
|
||||||
|
|
||||||
<!-- Echo all executed SQL to stdout -->
|
<!-- Echo all executed SQL to stdout -->
|
||||||
<property name="show_sql">true</property>
|
<property name="show_sql">false</property>
|
||||||
|
|
||||||
<!-- Drop and re-create the database schema on startup -->
|
<!-- Drop and re-create the database schema on startup -->
|
||||||
<property name="hbm2ddl.auto">update</property>
|
<property name="hbm2ddl.auto">update</property>
|
||||||
|
|
|
@ -10,6 +10,6 @@
|
||||||
<property name="hibernate.connection.username">tutorialuser</property>
|
<property name="hibernate.connection.username">tutorialuser</property>
|
||||||
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
|
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||||
<property name="hibernate.current_session_context_class">thread</property>
|
<property name="hibernate.current_session_context_class">thread</property>
|
||||||
<property name="hibernate.show_sql">true</property>
|
<property name="hibernate.show_sql">false</property>
|
||||||
</session-factory>
|
</session-factory>
|
||||||
</hibernate-configuration>
|
</hibernate-configuration>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<property name="hibernate.connection.username">sa</property>
|
<property name="hibernate.connection.username">sa</property>
|
||||||
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
|
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
|
||||||
<property name="hibernate.current_session_context_class">thread</property>
|
<property name="hibernate.current_session_context_class">thread</property>
|
||||||
<property name="hibernate.show_sql">true</property>
|
<property name="hibernate.show_sql">false</property>
|
||||||
<property name="hibernate.hbm2ddl.auto">create-drop</property>
|
<property name="hibernate.hbm2ddl.auto">create-drop</property>
|
||||||
</session-factory>
|
</session-factory>
|
||||||
</hibernate-configuration>
|
</hibernate-configuration>
|
||||||
|
|
|
@ -9,6 +9,8 @@ import com.baeldung.spring.jdbc.template.guide.config.SpringJdbcConfig;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
@ -19,6 +21,8 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
@ContextConfiguration(classes = { SpringJdbcConfig.class }, loader = AnnotationConfigContextLoader.class)
|
@ContextConfiguration(classes = { SpringJdbcConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||||
public class EmployeeDAOIntegrationTest {
|
public class EmployeeDAOIntegrationTest {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(EmployeeDAOIntegrationTest.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmployeeDAO employeeDao;
|
private EmployeeDAO employeeDao;
|
||||||
|
|
||||||
|
@ -70,7 +74,7 @@ public class EmployeeDAOIntegrationTest {
|
||||||
try {
|
try {
|
||||||
employeeDao.addEmplyee(7);
|
employeeDao.addEmplyee(7);
|
||||||
} catch (final DuplicateKeyException e) {
|
} catch (final DuplicateKeyException e) {
|
||||||
System.out.println(e.getMessage());
|
LOGGER.error(e.getMessage(), e);
|
||||||
Assert.assertTrue(e.getMessage().contains("Custome Exception translator - Integrity contraint voilation."));
|
Assert.assertTrue(e.getMessage().contains("Custome Exception translator - Integrity contraint voilation."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="15 seconds" debug="false">
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -6,7 +6,7 @@ jdbc.pass=
|
||||||
|
|
||||||
# hibernate.X
|
# hibernate.X
|
||||||
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
||||||
hibernate.show_sql=true
|
hibernate.show_sql=false
|
||||||
hibernate.hbm2ddl.auto=create-drop
|
hibernate.hbm2ddl.auto=create-drop
|
||||||
hibernate.cache.use_second_level_cache=true
|
hibernate.cache.use_second_level_cache=true
|
||||||
hibernate.cache.use_query_cache=true
|
hibernate.cache.use_query_cache=true
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="15 seconds" debug="false">
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -2,5 +2,5 @@ jdbc.driverClassName=org.h2.Driver
|
||||||
jdbc.url=jdbc:h2:mem:myDb;DB_CLOSE_DELAY=-1
|
jdbc.url=jdbc:h2:mem:myDb;DB_CLOSE_DELAY=-1
|
||||||
|
|
||||||
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
||||||
hibernate.show_sql=true
|
hibernate.show_sql=false
|
||||||
hibernate.hbm2ddl.auto=validate
|
hibernate.hbm2ddl.auto=validate
|
||||||
|
|
|
@ -6,5 +6,5 @@ jdbc.pass=
|
||||||
|
|
||||||
# hibernate.X
|
# hibernate.X
|
||||||
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
||||||
hibernate.show_sql=true
|
hibernate.show_sql=false
|
||||||
hibernate.hbm2ddl.auto=create-drop
|
hibernate.hbm2ddl.auto=create-drop
|
|
@ -6,7 +6,7 @@ jdbc.pass=
|
||||||
|
|
||||||
# hibernate.X
|
# hibernate.X
|
||||||
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
||||||
hibernate.show_sql=true
|
hibernate.show_sql=false
|
||||||
hibernate.hbm2ddl.auto=create-drop
|
hibernate.hbm2ddl.auto=create-drop
|
||||||
hibernate.cache.use_second_level_cache=false
|
hibernate.cache.use_second_level_cache=false
|
||||||
hibernate.cache.use_query_cache=false
|
hibernate.cache.use_query_cache=false
|
|
@ -4,7 +4,7 @@ jdbc.user=tutorialuser
|
||||||
jdbc.pass=tutorialpass
|
jdbc.pass=tutorialpass
|
||||||
|
|
||||||
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
|
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
|
||||||
hibernate.show_sql=true
|
hibernate.show_sql=false
|
||||||
hibernate.hbm2ddl.auto=create-drop
|
hibernate.hbm2ddl.auto=create-drop
|
||||||
|
|
||||||
hibernate.cache.use_second_level_cache=false
|
hibernate.cache.use_second_level_cache=false
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/HIBERTEST"/>
|
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/HIBERTEST"/>
|
||||||
<property name="javax.persistence.ddl-generation" value="drop-and-create-tables"/>
|
<property name="javax.persistence.ddl-generation" value="drop-and-create-tables"/>
|
||||||
<property name="javax.persistence.logging.level" value="INFO"/>
|
<property name="javax.persistence.logging.level" value="INFO"/>
|
||||||
<property name="hibernate.show_sql" value="true"/>
|
<property name="hibernate.show_sql" value="false"/>
|
||||||
<property name="hibernate.cache.use_second_level_cache" value="false"/>
|
<property name="hibernate.cache.use_second_level_cache" value="false"/>
|
||||||
<property name="hibernate.cache.use_query_cache" value="false"/>
|
<property name="hibernate.cache.use_query_cache" value="false"/>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -20,6 +20,8 @@ import com.baeldung.persistence.model.Foo;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
@ -31,6 +33,8 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class FooPaginationPersistenceIntegrationTest {
|
public class FooPaginationPersistenceIntegrationTest {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(FooPaginationPersistenceIntegrationTest.class);
|
||||||
|
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@ -137,7 +141,7 @@ public class FooPaginationPersistenceIntegrationTest {
|
||||||
typedQuery = entityManager.createQuery(select);
|
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());
|
LOGGER.debug("Current page: {}", typedQuery.getResultList());
|
||||||
pageNumber += pageSize;
|
pageNumber += pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ import com.baeldung.persistence.model.Bar;
|
||||||
import com.baeldung.persistence.model.Foo;
|
import com.baeldung.persistence.model.Foo;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
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;
|
||||||
|
@ -26,6 +28,8 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class FooServiceSortingIntegrationTest {
|
public class FooServiceSortingIntegrationTest {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(FooServiceSortingIntegrationTest.class);
|
||||||
|
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@ -37,7 +41,7 @@ public class FooServiceSortingIntegrationTest {
|
||||||
final Query sortQuery = entityManager.createQuery(jql);
|
final Query sortQuery = entityManager.createQuery(jql);
|
||||||
final List<Foo> fooList = sortQuery.getResultList();
|
final List<Foo> fooList = sortQuery.getResultList();
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name:" + foo.getName() + "-------Id:" + foo.getId());
|
LOGGER.debug("Name:{}-------Id:{}", foo.getName(), foo.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +51,7 @@ public class FooServiceSortingIntegrationTest {
|
||||||
final Query sortQuery = entityManager.createQuery(jql);
|
final Query sortQuery = entityManager.createQuery(jql);
|
||||||
final List<Foo> fooList = sortQuery.getResultList();
|
final List<Foo> fooList = sortQuery.getResultList();
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name:" + foo.getName() + "-------Id:" + foo.getId());
|
LOGGER.debug("Name:{}-------Id:{}", foo.getName(), foo.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +61,7 @@ public class FooServiceSortingIntegrationTest {
|
||||||
final Query sortQuery = entityManager.createQuery(jql);
|
final Query sortQuery = entityManager.createQuery(jql);
|
||||||
final List<Foo> fooList = sortQuery.getResultList();
|
final List<Foo> fooList = sortQuery.getResultList();
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name:" + foo.getName() + "-------Id:" + foo.getId());
|
LOGGER.debug("Name:{}-------Id:{}", foo.getName(), foo.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,9 +71,9 @@ public class FooServiceSortingIntegrationTest {
|
||||||
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());
|
LOGGER.debug("Name:{}", foo.getName());
|
||||||
if (foo.getBar() != null) {
|
if (foo.getBar() != null) {
|
||||||
System.out.print("-------BarId:" + foo.getBar().getId());
|
LOGGER.debug("-------BarId:{}", foo.getBar().getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,9 +84,9 @@ public class FooServiceSortingIntegrationTest {
|
||||||
final Query barQuery = entityManager.createQuery(jql);
|
final Query barQuery = entityManager.createQuery(jql);
|
||||||
final List<Bar> barList = barQuery.getResultList();
|
final List<Bar> barList = barQuery.getResultList();
|
||||||
for (final Bar bar : barList) {
|
for (final Bar bar : barList) {
|
||||||
System.out.println("Bar Id:" + bar.getId());
|
LOGGER.debug("Bar Id:{}", bar.getId());
|
||||||
for (final Foo foo : bar.getFooList()) {
|
for (final Foo foo : bar.getFooList()) {
|
||||||
System.out.println("FooName:" + foo.getName());
|
LOGGER.debug("FooName:{}", foo.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +101,7 @@ public class FooServiceSortingIntegrationTest {
|
||||||
final TypedQuery<Foo> typedQuery = entityManager.createQuery(select);
|
final TypedQuery<Foo> typedQuery = entityManager.createQuery(select);
|
||||||
final List<Foo> fooList = typedQuery.getResultList();
|
final List<Foo> fooList = typedQuery.getResultList();
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name:" + foo.getName() + "--------Id:" + foo.getId());
|
LOGGER.debug("Name:{}-------Id:{}", foo.getName(), foo.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +115,7 @@ public class FooServiceSortingIntegrationTest {
|
||||||
final TypedQuery<Foo> typedQuery = entityManager.createQuery(select);
|
final TypedQuery<Foo> typedQuery = entityManager.createQuery(select);
|
||||||
final List<Foo> fooList = typedQuery.getResultList();
|
final List<Foo> fooList = typedQuery.getResultList();
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name:" + foo.getName() + "-------Id:" + foo.getId());
|
LOGGER.debug("Name:{}-------Id:{}", foo.getName(), foo.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ import com.baeldung.config.PersistenceJPAConfig;
|
||||||
import com.baeldung.persistence.model.Foo;
|
import com.baeldung.persistence.model.Foo;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
@ -24,6 +26,8 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class FooServiceSortingWitNullsManualIntegrationTest {
|
public class FooServiceSortingWitNullsManualIntegrationTest {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(FooServiceSortingWitNullsManualIntegrationTest.class);
|
||||||
|
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@ -43,7 +47,7 @@ public class FooServiceSortingWitNullsManualIntegrationTest {
|
||||||
final List<Foo> fooList = sortQuery.getResultList();
|
final List<Foo> fooList = sortQuery.getResultList();
|
||||||
assertNull(fooList.get(fooList.toArray().length - 1).getName());
|
assertNull(fooList.get(fooList.toArray().length - 1).getName());
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name:" + foo.getName());
|
LOGGER.debug("Name:{}", foo.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +61,7 @@ public class FooServiceSortingWitNullsManualIntegrationTest {
|
||||||
final List<Foo> fooList = sortQuery.getResultList();
|
final List<Foo> fooList = sortQuery.getResultList();
|
||||||
assertNull(fooList.get(0).getName());
|
assertNull(fooList.get(0).getName());
|
||||||
for (final Foo foo : fooList) {
|
for (final Foo foo : fooList) {
|
||||||
System.out.println("Name:" + foo.getName());
|
LOGGER.debug("Name:{}", foo.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ jdbc.driverClassName=org.h2.Driver
|
||||||
jdbc.url=jdbc:h2:mem:myDb;DB_CLOSE_DELAY=-1
|
jdbc.url=jdbc:h2:mem:myDb;DB_CLOSE_DELAY=-1
|
||||||
|
|
||||||
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
||||||
hibernate.show_sql=true
|
hibernate.show_sql=false
|
||||||
hibernate.hbm2ddl.auto=create
|
hibernate.hbm2ddl.auto=create
|
||||||
|
|
||||||
hibernate.cache.use_second_level_cache=false
|
hibernate.cache.use_second_level_cache=false
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -790,6 +790,9 @@
|
||||||
<include>**/*IntegrationTest.java</include>
|
<include>**/*IntegrationTest.java</include>
|
||||||
<include>**/*IntTest.java</include>
|
<include>**/*IntTest.java</include>
|
||||||
</includes>
|
</includes>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<logback.configurationFile>${tutorialsproject.basedir}/logback-config.xml</logback.configurationFile>
|
||||||
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
@ -1047,6 +1050,9 @@
|
||||||
<include>**/*IntegrationTest.java</include>
|
<include>**/*IntegrationTest.java</include>
|
||||||
<include>**/*IntTest.java</include>
|
<include>**/*IntTest.java</include>
|
||||||
</includes>
|
</includes>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<logback.configurationFile>${tutorialsproject.basedir}/logback-config.xml</logback.configurationFile>
|
||||||
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
Loading…
Reference in New Issue