use of org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testServerDetectionLogging.
/**
* Bug #476018
* This test verifies that EclipseLink prints server detection related log
* messages at appropriate level - FINE in session log, FINER in other cases
*/
public void testServerDetectionLogging() {
if (isOnServer()) {
return;
}
closeEntityManagerFactory();
SessionLog original = AbstractSessionLog.getLog();
try {
AbstractSessionLog.setLog(new LogWrapper());
// check session log for "Configured server platform message"
Map<String, Object> properties = new HashMap<>();
properties.putAll(JUnitTestCaseHelper.getDatabaseProperties());
properties.put(PersistenceUnitProperties.LOGGING_LEVEL, original.getLevelString());
properties.put(PersistenceUnitProperties.LOGGING_LOGGER, LogWrapper.class.getName());
EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) Persistence.createEntityManagerFactory(getPersistenceUnitName(), properties);
emf.refreshMetadata(properties);
SimpleSessionLogWrapper wr = (SimpleSessionLogWrapper) emf.getServerSession().getSessionLog();
assertEquals("configured_server_platform should be printed at FINE level", wr.getLevel() <= SessionLog.FINE, wr.expected());
// it may happen that logging is not fully configured as that happens
// after detecting server platform; in such case, messages are printed out
// by an instance of DefaultSessionLog
LogWrapper lw = new LogWrapper("detect_server_platform");
AbstractSessionLog.setLog(lw);
AbstractSessionLog.getLog().setSession(null);
lw.setSession(null);
ServerPlatformUtils.detectServerPlatform(null);
assertEquals("detect_server_platform should be printed at FINER level", lw.getLevel() <= SessionLog.FINER, lw.expected());
lw = new LogWrapper("detect_server_platform");
AbstractSessionLog.setLog(lw);
Session ss = wr.getSession();
AbstractSessionLog.getLog().setSession(ss);
AbstractSessionLog.getLog().getSession().setSessionLog(lw);
lw.setSession(ss);
ServerPlatformUtils.detectServerPlatform((ServerSession) ss);
assertEquals("detect_server_platform should be printed at FINER level", lw.getLevel() <= SessionLog.FINER, lw.expected());
} finally {
AbstractSessionLog.setLog(original);
closeEntityManagerFactory();
}
}
use of org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl in project eclipselink by eclipse-ee4j.
the class AdvancedMultiTenantSchemaJunitTest method testPolicyConfigurationDefault.
public void testPolicyConfigurationDefault() {
if (!getPlatform().isMySQL()) {
warning("this test is supported on MySQL only");
return;
}
if (skipTest) {
warning("this test requires DB schema created in testSetup to be available.");
return;
}
// default configuration: shared EMF = true, shared cache = false
// strategy = 'external'
emf = Persistence.createEntityManagerFactory(getPersistenceUnitName(), emfProperties);
ServerSession session = ((EntityManagerFactoryImpl) emf).getServerSession();
MultitenantPolicy policy = session.getProject().getMultitenantPolicy();
assertNotNull("project MultitenantPolicy is null", policy);
assertTrue("not SchemaPerMultitenantPolicy", policy.isSchemaPerMultitenantPolicy());
assertTrue("not shared EMF", ((SchemaPerMultitenantPolicy) policy).shouldUseSharedEMF());
assertFalse("shared cache", ((SchemaPerMultitenantPolicy) policy).shouldUseSharedCache());
assertEquals(PersistenceUnitProperties.MULTITENANT_SCHEMA_PROPERTY_DEFAULT, ((SchemaPerMultitenantPolicy) policy).getContextProperty());
assertEquals(EntityManagerProperties.MULTITENANT_SCHEMA_PROPERTY_DEFAULT, ((SchemaPerMultitenantPolicy) policy).getContextProperty());
assertTrue("unknown context property", session.getMultitenantContextProperties().contains(PersistenceUnitProperties.MULTITENANT_SCHEMA_PROPERTY_DEFAULT));
}
use of org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testEMFClose.
public void testEMFClose() {
// This test tests the bug fix for 260511
// The NPE would be thrown if the EnityManager
// was created through the constructor
String errorMsg = "";
EntityManagerFactory em = new EntityManagerFactoryImpl(JUnitTestCase.getServerSession());
try {
em.close();
} catch (RuntimeException ex) {
errorMsg = "EMFClose: " + ex.getMessage() + ";";
}
if (errorMsg.length() > 0) {
fail(errorMsg);
}
}
use of org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl in project eclipselink by eclipse-ee4j.
the class TestJNDIConnector method testWasTargetServerLookupType.
@Test
public void testWasTargetServerLookupType() {
ServerSession session = ((EntityManagerFactoryImpl) wasEmf).getServerSession();
_connector.connect(new Properties(), session);
Assert.assertEquals(String.class, _handler.getParamType());
}
use of org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl in project eclipselink by eclipse-ee4j.
the class DynamicTestHelper method createEMF.
public static EntityManagerFactory createEMF(String emName) {
PersistenceContentHandler myContentHandler = new PersistenceContentHandler();
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
SAXParser sp = spf.newSAXParser();
XMLReader xmlReader = sp.getXMLReader();
XMLExceptionHandler xmlErrorHandler = new XMLExceptionHandler();
xmlReader.setErrorHandler(xmlErrorHandler);
xmlReader.setContentHandler(myContentHandler);
InputSource inputSource = new InputSource(new StringReader(DYNAMIC_PERSISTENCE_XML));
xmlReader.parse(inputSource);
} catch (Exception e) {
return null;
}
// only ever one
final SEPersistenceUnitInfo puInfo = myContentHandler.getPersistenceUnits().get(0);
puInfo.setPersistenceUnitRootUrl(dynamicTestUrl);
PersistenceProvider provider = new PersistenceProvider() {
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map) {
return null;
}
@Override
public EntityManagerFactory createEntityManagerFactory(String emName, Map map) {
if (emName.equals(puInfo.getPersistenceUnitName())) {
EntityManagerSetupImpl entityManagerSetupImpl = new EntityManagerSetupImpl(DYNAMIC_PERSISTENCE_NAME, DYNAMIC_PERSISTENCE_NAME);
map.put(PersistenceUnitProperties.WEAVING, "static");
puInfo.getProperties().put(PersistenceUnitProperties.EXCLUDE_ECLIPSELINK_ORM_FILE, "true");
entityManagerSetupImpl.predeploy(puInfo, map);
return new EntityManagerFactoryImpl(entityManagerSetupImpl, map);
} else {
return null;
}
}
@Override
public ProviderUtil getProviderUtil() {
return null;
}
@Override
public void generateSchema(PersistenceUnitInfo info, Map map) {
}
@Override
public boolean generateSchema(String persistenceUnitName, Map map) {
// TODO Auto-generated method stub
return false;
}
};
return provider.createEntityManagerFactory(emName, getDatabaseProperties());
}
Aggregations