Search in sources :

Example 16 with TestProblemException

use of org.eclipse.persistence.testing.framework.TestProblemException in project eclipselink by eclipse-ee4j.

the class SessionHelper method createDatabaseSession.

/**
 * Creates {@link DatabaseSession} from project and connect it to database.
 * {@link DatabaseSession#logout()} must be called before session instance is disposed.
 */
public static DatabaseSession createDatabaseSession(final Project project) {
    DatabaseSession session = project.createDatabaseSession();
    session.setSessionLog(LOG);
    try {
        session.login();
    } catch (Exception ex) {
        throw new TestProblemException("Database needs to be setup for AQ, with the user " + NoSQLProperties.getDBUserName(), ex);
    }
    return session;
}
Also used : DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException)

Example 17 with TestProblemException

use of org.eclipse.persistence.testing.framework.TestProblemException in project eclipselink by eclipse-ee4j.

the class OpenJPAPerformanceRegressionModel method setupProvider.

/**
 * Setup the JPA provider.
 */
@Override
public void setupProvider() {
    // Configure provider to be OpenJPA.
    String providerClass = "org.apache.openjpa.persistence.PersistenceProviderImpl";
    PersistenceProvider provider = null;
    try {
        provider = (PersistenceProvider) Class.forName(providerClass).getConstructor().newInstance();
    } catch (Exception error) {
        throw new TestProblemException("Failed to create persistence provider.", error);
    }
    Map properties = new HashMap();
    // properties.put("jakarta.persistence.nonJtaDataSource", "datasource");
    properties.put("openjpa.ConnectionDriverName", getSession().getLogin().getDriverClassName());
    properties.put("openjpa.ConnectionURL", getSession().getLogin().getConnectionString());
    properties.put("openjpa.ConnectionUserName", getSession().getLogin().getUserName());
    properties.put("openjpa.ConnectionPassword", getSession().getLogin().getPassword());
    if (getSession().shouldLogMessages()) {
        properties.put("openjpa.Log", "DefaultLevel=WARN,SQL=TRACE");
    }
    getExecutor().setEntityManagerFactory(provider.createEntityManagerFactory("performance", properties));
}
Also used : HashMap(java.util.HashMap) PersistenceProvider(jakarta.persistence.spi.PersistenceProvider) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) Map(java.util.Map) HashMap(java.util.HashMap) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException)

Example 18 with TestProblemException

use of org.eclipse.persistence.testing.framework.TestProblemException in project eclipselink by eclipse-ee4j.

the class TopLinkJPAPerformanceRegressionModel method setupProvider.

/**
 * Setup the JPA provider.
 */
@Override
public void setupProvider() {
    // Configure provider to be TopLink.
    String providerClass = "oracle.toplink.PersistenceProvider";
    PersistenceProvider provider = null;
    try {
        provider = (PersistenceProvider) Class.forName(providerClass).getConstructor().newInstance();
    } catch (Exception error) {
        throw new TestProblemException("Failed to create persistence provider.", error);
    }
    Map properties = new HashMap();
    properties.put("toplink.jdbc.driver", getSession().getLogin().getDriverClassName());
    properties.put("toplink.jdbc.url", getSession().getLogin().getConnectionString());
    properties.put("toplink.jdbc.user", getSession().getLogin().getUserName());
    properties.put("toplink.jdbc.password", getSession().getLogin().getPassword());
    properties.put("toplink.logging.level", getSession().getSessionLog().getLevelString());
    getExecutor().setEntityManagerFactory(provider.createEntityManagerFactory("performance", properties));
}
Also used : HashMap(java.util.HashMap) PersistenceProvider(jakarta.persistence.spi.PersistenceProvider) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) Map(java.util.Map) HashMap(java.util.HashMap) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException)

Example 19 with TestProblemException

use of org.eclipse.persistence.testing.framework.TestProblemException in project eclipselink by eclipse-ee4j.

the class DbChangeNotificationInternalTestModel method setupUser.

protected void setupUser() {
    if (!getSession().getPlatform().isOracle()) {
        throw new TestWarningException("Supports Oracle platform only");
    }
    oldSession = getSession();
    if (!oldSession.getLogin().getUserName().equalsIgnoreCase(aqUser)) {
        // 1 - might need to install aq procesures?
        // in sqlplus - @@<orahome>\ora92\rdbms\admin\catproc.sql
        // - as SYSDBA
        // 2 - create a AQ user <aquser> with password <aqpassword>
        // grant connect, resource , aq_administrator_role to <aquser> identified by <aqpassword>
        // grant execute on dbms_aq to <aquser>
        // grant execute on dbms_aqadm to <aquser>
        // grant execute on dbms_lock to <aquser>
        DatabaseLogin login = (DatabaseLogin) oldSession.getLogin().clone();
        login.setUserName(aqUser);
        login.setPassword(aqPassword);
        DatabaseSession session = new Project(login).createDatabaseSession();
        session.setSessionLog(getSession().getSessionLog());
        session.setLogLevel(getSession().getLogLevel());
        try {
            session.login();
        } catch (Exception exception) {
            throw new TestProblemException("Database needs to be setup for AQ, needs user " + OracleAqHelper.getAqUser());
        }
        getExecutor().setSession(session);
    }
}
Also used : DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) Project(org.eclipse.persistence.sessions.Project) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException)

Example 20 with TestProblemException

use of org.eclipse.persistence.testing.framework.TestProblemException in project eclipselink by eclipse-ee4j.

the class ProxyAuthenticationConnectionCustomizerTestCase method testServerSession.

void testServerSession() {
    ServerSession ss = (ServerSession) getSession();
    if (shouldEnableStatementCaching) {
        ss.getPlatform().setShouldCacheAllStatements(true);
    }
    verifyUser("ServerSession first read", getReadUser(ss), expectedMainSessionUser);
    // The first ClientSession created without proxy properties - should always use the same user as ServerSession.
    ClientSession cs1 = ss.acquireClientSession();
    if (shoulUseExclusiveIsolatedSession) {
        // verify that IsolatedSession is used if required.
        if (!(cs1 instanceof ExclusiveIsolatedClientSession)) {
            throw new TestProblemException("The ClientSession must be ExclusiveIsolatedClientSession");
        }
    }
    verifyUser("ClientSession1 before transaction read", getReadUser(cs1), expectedMainSessionUser);
    cs1.beginTransaction();
    verifyUser("ClientSession1in transaction read", getReadUser(cs1), expectedMainSessionUser);
    verifyUser("ClientSession1 wrote", getWriteUser(cs1), expectedMainSessionUser);
    cs1.rollbackTransaction();
    verifyUser("ClientSession1 after transaction read", getReadUser(cs1), expectedMainSessionUser);
    cs1.release();
    // The second ClientSession created with proxy properties.
    ClientSession cs2 = ss.acquireClientSession(clientSessionProxyProperties);
    if (shoulUseExclusiveIsolatedSession) {
        verifyUser("ExclusiveIsolatedClientSession2 before transaction read", getReadUser(cs2), expectedClientSessionUser);
    } else {
        verifyUser("ClientSession2 before transaction read", getReadUser(cs2), expectedMainSessionUser);
    }
    cs2.beginTransaction();
    verifyUser("ClientSession2 in transaction read", getReadUser(cs2), expectedClientSessionUser);
    verifyUser("ClientSession2 wrote", getWriteUser(cs2), expectedClientSessionUser);
    cs2.rollbackTransaction();
    if (shoulUseExclusiveIsolatedSession) {
        verifyUser("ExclusiveIsolatedClientSession2 after transaction read", getReadUser(cs2), expectedClientSessionUser);
    } else {
        verifyUser("ClientSession2 after transaction read", getReadUser(cs2), expectedMainSessionUser);
    }
    cs2.release();
    // verify that ServerSession still uses the correct user.
    // Because there is one one connection in each connection pool (internal pool case) this would fail in case proxy customizer
    // wasn't removed by cs2.
    verifyUser("ServerSession second read", getReadUser(ss), expectedMainSessionUser);
    // The third ClientSession created without proxy properties again - should always use the same user as ServerSession.
    // Because there is one one connection in each connection pool (internal pool case) this would fail in case proxy customizer
    // wasn't removed by cs2.
    ClientSession cs3 = ss.acquireClientSession();
    verifyUser("ClientSession3 before transaction read", getReadUser(cs3), expectedMainSessionUser);
    cs3.beginTransaction();
    verifyUser("ClientSession3 in transaction read", getReadUser(cs3), expectedMainSessionUser);
    verifyUser("ClientSession3 wrote", getWriteUser(cs3), expectedMainSessionUser);
    cs3.rollbackTransaction();
    verifyUser("ClientSession3 after transaction read", getReadUser(cs3), expectedMainSessionUser);
    cs3.release();
}
Also used : ServerSession(org.eclipse.persistence.sessions.server.ServerSession) ExclusiveIsolatedClientSession(org.eclipse.persistence.internal.sessions.ExclusiveIsolatedClientSession) ExclusiveIsolatedClientSession(org.eclipse.persistence.internal.sessions.ExclusiveIsolatedClientSession) ClientSession(org.eclipse.persistence.sessions.server.ClientSession) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException)

Aggregations

TestProblemException (org.eclipse.persistence.testing.framework.TestProblemException)48 TestSetup (junit.extensions.TestSetup)18 TestSuite (junit.framework.TestSuite)18 PersistenceProvider (jakarta.persistence.spi.PersistenceProvider)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 SQLException (java.sql.SQLException)4 Vector (java.util.Vector)3 NamingException (javax.naming.NamingException)3 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)3 DatabaseAccessor (org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor)3 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)3 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)3 TestWarningException (org.eclipse.persistence.testing.framework.TestWarningException)3 RMISecurityManager (java.rmi.RMISecurityManager)2 RemoteException (java.rmi.RemoteException)2 Connection (java.sql.Connection)2 Statement (java.sql.Statement)2 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)2 Expression (org.eclipse.persistence.expressions.Expression)2