Testcase update with slf4j

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@984835 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2010-08-12 15:34:30 +00:00
parent 754cc62f5c
commit 7bfc33e468
1 changed files with 25 additions and 7 deletions

View File

@ -21,24 +21,37 @@ package org.apache.openjpa.integration.slf4j;
import javax.persistence.EntityManager;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.lib.log.SLF4JLogFactory;
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
/**
* Simple test case to verify SLF4JLogFactory is being loaded
*/
public class TestLogFactory extends SingleEMFTestCase {
String systemPropLog = null;
public void setUp() throws Exception {
// Maven users may disable logging via a global system prop - which breaks this testcase.
systemPropLog = System.getProperty("openjpa.Log");
System.getProperties().remove("openjpa.Log");
super.setUp();
}
public void tearDown() throws Exception {
super.tearDown();
if(systemPropLog != null) {
System.setProperty("openjpa.Log", systemPropLog);
}
}
public void testSLF4J() {
OpenJPAEntityManagerFactorySPI emf = createNamedEMF("openjpa-integration-slf4j");
try {
EntityManager em = emf.createEntityManager();
// do some logging
Log log = getLog();
Log log = getLog();
String logFactory = log.getClass().getName();
log.info("Log class=" + logFactory);
assertTrue("SLF4JLogFactory", logFactory.indexOf("SLF4JLogFactory") != -1);
assertEquals(SLF4JLogFactory.LogAdapter.class.getName(), logFactory);
// next one should not be logged if using slf4j-simple binding - only INFO, WARN and ERROR
log.trace("TRACE level logging");
@ -47,6 +60,11 @@ public class TestLogFactory extends SingleEMFTestCase {
closeEMF(emf);
}
}
public String getPersistenceUnitName() {
// override puName instead of creating our own EMF.
// getLog uses the SingleEMFTestCase's emf.
return "openjpa-integration-slf4j";
}
}