mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-26 13:25:19 +00:00
HHH-9658 Refactor some of the existing logging tests
This commit is contained in:
parent
c067fc2b42
commit
6eb6f38721
@ -23,37 +23,36 @@
|
||||
*/
|
||||
package org.hibernate.test.annotations.xml.ejb3;
|
||||
|
||||
import org.jboss.byteman.contrib.bmunit.BMRule;
|
||||
import org.jboss.byteman.contrib.bmunit.BMRules;
|
||||
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.xml.ErrorLogger;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.byteman.BytemanHelper;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.logger.LoggerInspectionRule;
|
||||
import org.hibernate.testing.logger.Triggerable;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-6271")
|
||||
@RunWith(BMUnitRunner.class)
|
||||
public class OrmVersion1SupportedTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Rule
|
||||
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
|
||||
Logger.getMessageLogger(
|
||||
CoreMessageLogger.class,
|
||||
ErrorLogger.class.getName()
|
||||
)
|
||||
);
|
||||
|
||||
@Test
|
||||
@BMRules(rules = {
|
||||
@BMRule(targetClass = "org.hibernate.internal.CoreMessageLogger_$logger",
|
||||
targetMethod = "parsingXmlError",
|
||||
helper = "org.hibernate.testing.byteman.BytemanHelper",
|
||||
action = "countInvocation()",
|
||||
name = "testOrm1Support"),
|
||||
@BMRule(targetClass = "org.hibernate.internal.CoreMessageLogger_$logger",
|
||||
targetMethod = "parsingXmlErrorForFile",
|
||||
helper = "org.hibernate.testing.byteman.BytemanHelper",
|
||||
action = "countInvocation()",
|
||||
name = "testOrm1Support")
|
||||
})
|
||||
public void testOrm1Support() {
|
||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH00196" );
|
||||
|
||||
// need to call buildSessionFactory, because this test is not using org.hibernate.testing.junit4.CustomRunner
|
||||
buildSessionFactory();
|
||||
|
||||
@ -69,7 +68,7 @@ public void testOrm1Support() {
|
||||
tx.rollback();
|
||||
s.close();
|
||||
|
||||
assertEquals( "HHH00196 should not be called", 0, BytemanHelper.getAndResetInvocationCount() );
|
||||
assertFalse( triggerable.wasTriggered() );
|
||||
|
||||
// which means we also need to close it manually
|
||||
releaseSessionFactory();
|
||||
|
@ -26,20 +26,23 @@
|
||||
import org.jboss.byteman.contrib.bmunit.BMRule;
|
||||
import org.jboss.byteman.contrib.bmunit.BMRules;
|
||||
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.loader.Loader;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.byteman.BytemanHelper;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.logger.LoggerInspectionRule;
|
||||
import org.hibernate.testing.logger.Triggerable;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Sanne Grinovero
|
||||
@ -49,6 +52,11 @@
|
||||
@RunWith(BMUnitRunner.class)
|
||||
public class CriteriaLockingTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Rule
|
||||
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
|
||||
Logger.getMessageLogger(CoreMessageLogger.class, Loader.class.getName())
|
||||
);
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {Bid.class, Item.class};
|
||||
@ -59,15 +67,12 @@ protected Class<?>[] getAnnotatedClasses() {
|
||||
@BMRule(targetClass = "org.hibernate.dialect.Dialect",
|
||||
targetMethod = "useFollowOnLocking",
|
||||
action = "return true",
|
||||
name = "H2DialectUseFollowOnLocking"),
|
||||
@BMRule(targetClass = "org.hibernate.internal.CoreMessageLogger_$logger",
|
||||
targetMethod = "usingFollowOnLocking",
|
||||
helper = "org.hibernate.testing.byteman.BytemanHelper",
|
||||
action = "countInvocation()",
|
||||
name = "countWarnings")
|
||||
name = "H2DialectUseFollowOnLocking")
|
||||
})
|
||||
public void testSetLockModeNONEDoNotLogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue() {
|
||||
buildSessionFactory();
|
||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000444" );
|
||||
|
||||
final Session s = openSession();
|
||||
final Transaction tx = s.beginTransaction();
|
||||
|
||||
@ -87,7 +92,7 @@ public void testSetLockModeNONEDoNotLogAWarnMessageWhenTheDialectUseFollowOnLock
|
||||
|
||||
releaseSessionFactory();
|
||||
|
||||
assertEquals( "HHH000444 should not be called", 0, BytemanHelper.getAndResetInvocationCount() );
|
||||
assertFalse( triggerable.wasTriggered() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -95,15 +100,12 @@ public void testSetLockModeNONEDoNotLogAWarnMessageWhenTheDialectUseFollowOnLock
|
||||
@BMRule(targetClass = "org.hibernate.dialect.Dialect",
|
||||
targetMethod = "useFollowOnLocking",
|
||||
action = "return true",
|
||||
name = "H2DialectUseFollowOnLocking"),
|
||||
@BMRule(targetClass = "org.hibernate.internal.CoreMessageLogger_$logger",
|
||||
targetMethod = "usingFollowOnLocking",
|
||||
helper = "org.hibernate.testing.byteman.BytemanHelper",
|
||||
action = "countInvocation()",
|
||||
name = "countWarnings")
|
||||
name = "H2DialectUseFollowOnLocking")
|
||||
})
|
||||
public void testSetLockModeDifferentFromNONELogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue() {
|
||||
buildSessionFactory();
|
||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000444" );
|
||||
|
||||
final Session s = openSession();
|
||||
final Transaction tx = s.beginTransaction();
|
||||
|
||||
@ -122,6 +124,6 @@ public void testSetLockModeDifferentFromNONELogAWarnMessageWhenTheDialectUseFoll
|
||||
s.close();
|
||||
releaseSessionFactory();
|
||||
|
||||
assertEquals( "HHH000444 should not be called", 1, BytemanHelper.getAndResetInvocationCount() );
|
||||
assertTrue( triggerable.wasTriggered() );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user