use of org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator in project eclipselink by eclipse-ee4j.
the class UnregisteredNewObjectOptimisticLockTest method test.
@Override
protected void test() {
try {
UnitOfWork uow = getSession().acquireUnitOfWork();
Employee orig = (Employee) uow.readObject(Employee.class);
uow.setShouldNewObjectsBeCached(true);
Employee newEmp = (Employee) new EmployeePopulator().basicEmployeeExample6();
orig.getManagedEmployees().add(newEmp);
newEmp.setManager(orig);
uow.commit();
uow = getSession().acquireUnitOfWork();
newEmp = (Employee) uow.readObject(newEmp);
newEmp.setFirstName("Changed Name");
uow.commit();
} catch (OptimisticLockException e) {
throw new TestErrorException("bug 3431586 unregistered new object version number not merged into cache");
}
}
use of org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator in project eclipselink by eclipse-ee4j.
the class QueryParameterForOneToOneValidationTest method test.
@Override
public void test() {
// find a suitable id
org.eclipse.persistence.testing.models.employee.domain.Employee empExample = (org.eclipse.persistence.testing.models.employee.domain.Employee) new EmployeePopulator().basicEmployeeExample10();
ExpressionBuilder testBuilder = new ExpressionBuilder();
Expression testExpression = testBuilder.get("firstName").equal(empExample.getFirstName());
testExpression = testExpression.and(testBuilder.get("lastName").equal(empExample.getLastName()));
Employee testEmp = (Employee) getSession().readObject(Employee.class, testExpression);
if (testEmp == null) {
throw new TestErrorException("Employee example was not retrieved from DB (null): " + empExample);
}
int id = testEmp.getId().intValue();
getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
ReadAllQuery query = new ReadAllQuery(PhoneNumber.class);
ExpressionBuilder builder = query.getExpressionBuilder();
Expression expression = builder.get("owner").equal(builder.getParameter("the_parameter"));
query.setSelectionCriteria(expression);
query.addArgument("the_parameter", Integer.class);
try {
// doesn't matter what id is queried
Vector params = new Vector();
params.add(id);
// special case for conforming
if (this.shouldConform) {
// enable conforming
query.setCacheUsage(ObjectLevelReadQuery.CheckCacheOnly);
// preload objects into identitymap
getSession().readAllObjects(PhoneNumber.class);
getSession().readAllObjects(Employee.class);
}
getSession().executeQuery(query, params);
} catch (EclipseLinkException te) {
caughtException = te;
} catch (Exception e) {
throw new TestException("Caught exception " + e.toString() + "running test " + getName());
}
}
use of org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator in project eclipselink by eclipse-ee4j.
the class EmployeeChangeFlagBasicTestModel method getInsertObjectTestSuite.
public static TestSuite getInsertObjectTestSuite() {
TestSuite suite = new TestSuite();
suite.setName("EmployeeInsertObjectTestSuite");
suite.setDescription("This suite tests the insertion of each object in the employee demo.");
EmployeePopulator system = new EmployeePopulator();
suite.addTest(new InsertObjectTest(system.basicEmployeeExample1()));
suite.addTest(new InsertObjectTest(system.basicEmployeeExample2()));
suite.addTest(new InsertObjectTest(system.basicEmployeeExample3()));
suite.addTest(new InsertObjectTest(system.basicEmployeeExample4()));
suite.addTest(new InsertObjectTest(system.basicEmployeeExample5()));
suite.addTest(new InsertObjectTest(system.basicSmallProjectExample1()));
suite.addTest(new InsertObjectTest(system.basicSmallProjectExample2()));
suite.addTest(new InsertObjectTest(system.basicSmallProjectExample3()));
suite.addTest(new InsertObjectTest(system.basicLargeProjectExample1()));
suite.addTest(new InsertObjectTest(system.basicLargeProjectExample2()));
suite.addTest(new InsertObjectTest(system.basicLargeProjectExample3()));
return suite;
}
use of org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator in project eclipselink by eclipse-ee4j.
the class ConcurrentNewObjectTest method test.
@Override
protected void test() {
UnitOfWorkImpl unitOfWork1 = (UnitOfWorkImpl) getSession().acquireUnitOfWork();
Address address = new EmployeePopulator().addressExample1();
Employee originalClone = (Employee) unitOfWork1.readObject(Employee.class);
originalClone.setAddress(address);
unitOfWork1.issueSQLbeforeCompletion();
// Simulate use of the JTS
unitOfWork1.setPendingMerge();
address = (Address) getSession().readObject(address);
try {
unitOfWork1.mergeClonesAfterCompletion();
} catch (Exception exception) {
throw new TestErrorException("New Object was read into Cache before Merged by creator, creator threw error");
}
}
use of org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator in project eclipselink by eclipse-ee4j.
the class UpdateChangeObjectTest method changeObject.
@Override
protected void changeObject() {
Employee employee = (Employee) this.workingCopy;
// Transformation
employee.setNormalHours(new java.sql.Time[2]);
employee.setStartTime(Helper.timeFromHourMinuteSecond(1, 1, 1));
employee.setEndTime(Helper.timeFromHourMinuteSecond(1, 1, 1));
// Aggregate
employee.setPeriod(new EmploymentPeriod(Helper.dateFromYearMonthDate(2001, 1, 1), Helper.dateFromYearMonthDate(2002, 2, 2)));
// One to many private
employee.setPhoneNumbers(new Vector());
employee.addPhoneNumber(new PhoneNumber("home", "613", "2263374"));
employee.addPhoneNumber(new PhoneNumber("office", "416", "8224599"));
// Many to many
employee.setProjects(new Vector());
employee.addProject((Project) getUnitOfWork().readObject(SmallProject.class));
employee.addProject((Project) getUnitOfWork().readObject(LargeProject.class));
// Direct collection
employee.setResponsibilitiesList(new Vector());
employee.addResponsibility("make cafee");
employee.addResponsibility("buy donuts");
// One to one private/public
employee.setAddress(new EmployeePopulator().addressExample12());
// make sure that the employee is not his own manager
Vector employees = getUnitOfWork().readAllObjects(Employee.class);
Employee manager = null;
for (int i = 0; i < employees.size(); i++) {
manager = (Employee) employees.elementAt(i);
if (!manager.getId().equals(employee.getId())) {
break;
}
}
employee.setManager(manager);
}
Aggregations