Search in sources :

Example 6 with TestProblemException

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

the class NamedQueryTests method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.setName("NamedQueryTests");
    suite.addTest(new NamedQueryTests("testNamedSessionQueryNoBinding"));
    suite.addTest(new NamedQueryTests("testNamedSessionQueryBindAllParameters"));
    suite.addTest(new NamedQueryTests("testNamedSessionQueryBindQueryParameters"));
    suite.addTest(new NamedQueryTests("testDescriptorNamedQueryNoBinding"));
    suite.addTest(new NamedQueryTests("testDescriptorNamedQueryBindAllParameter"));
    suite.addTest(new NamedQueryTests("testDescriptorNamedQueryBindQueryParameter"));
    return new TestSetup(suite) {

        protected void setUp() {
            try {
                SimpleSpatialTestCase.repopulate(getSession(), true);
                ReadAllQuery raq = new ReadAllQuery(SimpleSpatial.class);
                ExpressionBuilder eb = raq.getExpressionBuilder();
                SpatialParameters parameters = new SpatialParameters();
                parameters.setQueryType(SpatialParameters.QueryType.WINDOW).setMask(Mask.ANYINTERACT);
                Expression selectionCriteria = SpatialExpressionFactory.relate(eb.get("geometry"), eb.getParameter("GEOMETRY"), parameters);
                raq.setSelectionCriteria(selectionCriteria);
                raq.addAscendingOrdering("id");
                raq.addArgument("GEOMETRY", JGeometry.class);
                getSession().addQuery(SESSION_QUERY_NAME, raq);
                raq = new ReadAllQuery(SimpleSpatial.class);
                eb = raq.getExpressionBuilder();
                parameters = new SpatialParameters();
                parameters.setDistance(10d);
                selectionCriteria = SpatialExpressionFactory.withinDistance(eb.get("geometry"), eb.getParameter("GEOMETRY"), parameters);
                raq.setSelectionCriteria(selectionCriteria);
                raq.addAscendingOrdering("id");
                raq.addArgument("GEOMETRY", JGeometry.class);
                getSession().getClassDescriptor(SimpleSpatial.class).getDescriptorQueryManager().addQuery(DESCRIPTOR_QUERY_NAME, raq);
            } catch (Exception e) {
                throw new TestProblemException("Could not setup JGeometry test model", e);
            }
        }

        protected void tearDown() {
            try {
                getSession().removeQuery(SESSION_QUERY_NAME);
                getSession().getClassDescriptor(SimpleSpatial.class).getDescriptorQueryManager().removeQuery(DESCRIPTOR_QUERY_NAME);
            } catch (Exception e) {
                throw new TestProblemException("Could not tearDown NamedQueryTests for SimpleSpatialTestCase.", e);
            }
        }
    };
}
Also used : TestSetup(junit.extensions.TestSetup) SimpleSpatial(org.eclipse.persistence.testing.models.spatial.jgeometry.SimpleSpatial) TestSuite(junit.framework.TestSuite) Expression(org.eclipse.persistence.expressions.Expression) SpatialParameters(org.eclipse.persistence.expressions.spatial.SpatialParameters) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException)

Example 7 with TestProblemException

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

the class NamedQueryTests method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.setName("NamedQueryTests");
    suite.addTest(new NamedQueryTests("testNamedSessionQueryNoBinding"));
    suite.addTest(new NamedQueryTests("testNamedSessionQueryBindAllParameters"));
    suite.addTest(new NamedQueryTests("testNamedSessionQueryBindQueryParameters"));
    suite.addTest(new NamedQueryTests("testDescriptorNamedQueryNoBinding"));
    suite.addTest(new NamedQueryTests("testDescriptorNamedQueryBindAllParameter"));
    suite.addTest(new NamedQueryTests("testDescriptorNamedQueryBindQueryParameter"));
    return new TestSetup(suite) {

        protected void setUp() {
            try {
                WrappedSpatialTestCase.repopulate(getSession(), true);
                ReadAllQuery raq = new ReadAllQuery(WrappedSpatial.class);
                ExpressionBuilder eb = raq.getExpressionBuilder();
                SpatialParameters parameters = new SpatialParameters();
                parameters.setMask(Mask.ANYINTERACT).setQueryType(QueryType.WINDOW);
                Expression selectionCriteria = SpatialExpressionFactory.relate(eb.get("geometry").getField("geom"), eb.getParameter("GEOMETRY"), parameters);
                raq.setSelectionCriteria(selectionCriteria);
                raq.addAscendingOrdering("id");
                raq.addArgument("GEOMETRY", JGeometry.class);
                getSession().addQuery(SESSION_QUERY_NAME, raq);
                raq = new ReadAllQuery(WrappedSpatial.class);
                eb = raq.getExpressionBuilder();
                parameters = new SpatialParameters();
                parameters.setDistance(10d);
                selectionCriteria = SpatialExpressionFactory.withinDistance(eb.get("geometry").getField("geom"), eb.getParameter("GEOMETRY"), parameters);
                raq.setSelectionCriteria(selectionCriteria);
                raq.addAscendingOrdering("id");
                raq.addArgument("GEOMETRY", MyGeometry.class);
                getSession().getClassDescriptor(WrappedSpatial.class).getDescriptorQueryManager().addQuery(DESCRIPTOR_QUERY_NAME, raq);
            } catch (Exception e) {
                throw new TestProblemException("Could not setup JGeometry test model. Note: This model requires you to run the following CREATE OR REPLACE TYPE MY_GEOMETRY AS OBJECT (id NUMBER, geom MDSYS.SDO_GEOMETRY): ", e);
            }
        }

        protected void tearDown() {
            try {
                getSession().removeQuery(SESSION_QUERY_NAME);
                getSession().getClassDescriptor(WrappedSpatial.class).getDescriptorQueryManager().removeQuery(DESCRIPTOR_QUERY_NAME);
            } catch (Exception e) {
                throw new TestProblemException("Could not tearDown NamedQueryTests for SimpleSpatialTestCase.", e);
            }
        }
    };
}
Also used : TestSetup(junit.extensions.TestSetup) WrappedSpatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.WrappedSpatial) TestSuite(junit.framework.TestSuite) Expression(org.eclipse.persistence.expressions.Expression) SpatialParameters(org.eclipse.persistence.expressions.spatial.SpatialParameters) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException)

Example 8 with TestProblemException

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

the class Query_OrderedHint method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.setName("Query_OrderedHint");
    suite.addTest(new Query_OrderedHint("testReadAll"));
    return new TestSetup(suite) {

        protected void setUp() {
            try {
                WrappedSpatialTestCase.repopulate(getSession(), true);
            } catch (Exception e) {
                throw new TestProblemException("Could not setup JGeometry test model. Note: This model requires you to run the following CREATE OR REPLACE TYPE MY_GEOMETRY AS OBJECT (id NUMBER, geom MDSYS.SDO_GEOMETRY): ", e);
            }
        }

        protected void tearDown() {
        }
    };
}
Also used : TestSetup(junit.extensions.TestSetup) TestSuite(junit.framework.TestSuite) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException)

Example 9 with TestProblemException

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

the class AllChangeSetsTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    Vector employees = uow.readAllObjects(Employee.class);
    // let's require at least 5 object
    if (employees.size() <= 4) {
        throw new TestProblemException("only " + employees.size() + " employees were read, need at least 5");
    }
    // Existing object has changed - should be counted
    Employee emp = (Employee) employees.firstElement();
    emp.setFirstName("Changed");
    changedObjectsCount++;
    Address add = emp.getAddress();
    if (emp.getAddress() != null) {
        // Existing object has changed - should be counted
        add.setCity("Changed");
        changedObjectsCount++;
    }
    // New object - should be counted
    Employee newEmp = new Employee();
    Employee newEmpClone = (Employee) uow.registerObject(newEmp);
    newEmpClone.setFirstName("New");
    changedObjectsCount++;
    Iterator it = emp.getPhoneNumbers().iterator();
    while (it.hasNext()) {
        PhoneNumber phone = (PhoneNumber) it.next();
        // to force reading the phone in and therefore registering in uow
        // Registered but not changed - should NOT be counted
        String code = phone.getAreaCode();
    }
    // forcedUpdate with false - should NOT be counted (doesn't affect cache)
    Employee emp1 = (Employee) employees.elementAt(1);
    uow.forceUpdateToVersionField(emp1, false);
    // forcedUpdate with true - should be counted
    Employee emp2 = (Employee) employees.elementAt(2);
    uow.forceUpdateToVersionField(emp2, true);
    changedObjectsCount++;
    uow.commit();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Address(org.eclipse.persistence.testing.models.employee.domain.Address) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) Iterator(java.util.Iterator) PhoneNumber(org.eclipse.persistence.testing.models.employee.domain.PhoneNumber) Vector(java.util.Vector)

Example 10 with TestProblemException

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

the class CommitAfterExecuteModifyQueryDuringTransTest method reset.

/**
 * Test makes modifications that is not wrapped in a transaction..
 * so we have to reset our change
 */
@Override
public void reset() {
    Vector myV = new Vector();
    myV.addElement(originalEmployee.firstName);
    myV.addElement(initialVersionField);
    myV.addElement(originalEmployee.lastName);
    try {
        getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
        getSession().executeQuery(dataModifyQuery, myV);
    } catch (Exception internalException) {
        throw new TestProblemException("Test case may not have cleaned up correctly affecting other tests", internalException);
    }
}
Also used : TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) Vector(java.util.Vector) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException)

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