use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee in project eclipselink by eclipse-ee4j.
the class ReportQueryConstructorExpressionTestSuite method testConstructorExpressionWithOtherAttributes.
public void testConstructorExpressionWithOtherAttributes() {
ExpressionBuilder employees = new ExpressionBuilder();
ReportQuery query = new ReportQuery(Employee.class, employees);
query.addAttribute("firstName");
query.addAttribute("lastName");
List reportResults = (List) getServerSession("fieldaccess").executeQuery(query);
ConstructorReportItem citem = new ConstructorReportItem("Employee");
citem.setResultType(Employee.class);
citem.addAttribute(employees.get("firstName"));
citem.addAttribute(employees.get("lastName"));
query.addConstructorReportItem(citem);
Vector results = (Vector) getServerSession("fieldaccess").executeQuery(query);
Iterator i = results.iterator();
Iterator report = reportResults.iterator();
while (i.hasNext()) {
ReportQueryResult result1 = (ReportQueryResult) i.next();
Employee emp = (Employee) result1.get("Employee");
// Employee emp = (Employee)i.next();
ReportQueryResult result2 = (ReportQueryResult) report.next();
if (emp.getFirstName() != null) {
assertTrue("Null first name in constructor query", result1.get("firstName") != null);
assertTrue("Null first name", result2.get("firstName") != null);
assertTrue("Wrong first name", emp.getFirstName().equals(result2.get("firstName")));
}
if (emp.getLastName() != null) {
assertTrue("Null last name in constructor query", result1.get("lastName") != null);
assertTrue("Null last name", result2.get("lastName") != null);
assertTrue("Wrong last name", emp.getLastName().equals(result2.get("lastName")));
}
}
assertTrue("Different result sizes", !(report.hasNext()));
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee in project eclipselink by eclipse-ee4j.
the class ReportQueryConstructorExpressionTestSuite method testSimpleConstructorExpressionWithNamedQuery.
public void testSimpleConstructorExpressionWithNamedQuery() {
ExpressionBuilder employees = new ExpressionBuilder();
ReportQuery query = new ReportQuery(Employee.class, employees);
query.addAttribute("firstName");
query.addAttribute("lastName");
EntityManager em = createEntityManager("fieldaccess");
Vector reportResults = (Vector) getServerSession("fieldaccess").executeQuery(query);
Vector results = (Vector) em.createNamedQuery("constuctFieldAccessEmployees").getResultList();
Iterator i = results.iterator();
Iterator report = reportResults.iterator();
while (i.hasNext()) {
Employee emp = (Employee) i.next();
ReportQueryResult result = (ReportQueryResult) report.next();
if (emp.getFirstName() != null) {
assertTrue("Null first name", result.get("firstName") != null);
assertTrue("Wrong first name", emp.getFirstName().equals(result.get("firstName")));
}
if (emp.getLastName() != null) {
assertTrue("Null last name", result.get("lastName") != null);
assertTrue("Wrong last name", emp.getLastName().equals(result.get("lastName")));
}
}
assertTrue("Different result sizes", !(report.hasNext()));
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee in project eclipselink by eclipse-ee4j.
the class ReportQueryMultipleReturnTestSuite method testSimpleReturnObject.
public void testSimpleReturnObject() {
ReportQuery reportQuery = new ReportQuery();
reportQuery.returnWithoutReportQueryResult();
reportQuery.setReferenceClass(Employee.class);
ExpressionBuilder empbuilder = new ExpressionBuilder();
reportQuery.addAttribute("manager", empbuilder.get("manager"));
reportQuery.setSelectionCriteria(empbuilder.get("salary").greaterThan(1));
List result = (List) getServerSession("fieldaccess").executeQuery(reportQuery);
Object resultItem = result.get(0);
assertTrue("Failed to return Employees correctly, Not An Employee", Employee.class.isAssignableFrom(resultItem.getClass()));
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee in project eclipselink by eclipse-ee4j.
the class ReportQueryMultipleReturnTestSuite method testReturnUnrelatedObjectAndDirectToField.
public void testReturnUnrelatedObjectAndDirectToField() {
ReportQuery reportQuery = new ReportQuery();
reportQuery.returnWithoutReportQueryResult();
reportQuery.setReferenceClass(Employee.class);
ExpressionBuilder empbuilder = new ExpressionBuilder();
ExpressionBuilder addBuilder = new ExpressionBuilder(Address.class);
reportQuery.addAttribute("salary", empbuilder.get("salary"));
reportQuery.addAttribute("manager", empbuilder.get("manager"));
reportQuery.addAttribute("adress.city", addBuilder.get("city"));
reportQuery.setSelectionCriteria(empbuilder.get("salary").greaterThan(1));
List result = (List) getServerSession("fieldaccess").executeQuery(reportQuery);
Object innerResult = result.get(0);
assertTrue("Failed to return Employees correctly, Not an Object Array", Object[].class.isAssignableFrom(innerResult.getClass()));
Object resultItem = ((Object[]) innerResult)[0];
assertTrue("Failed to return Employees correctly, Not A Number", Number.class.isAssignableFrom(resultItem.getClass()));
assertTrue("Failed to return Employees correctly, Not Correct Result", ((Number) resultItem).intValue() > 1);
resultItem = ((Object[]) innerResult)[1];
assertTrue("Failed to return Employees correctly, Not An Employee", Employee.class.isAssignableFrom(resultItem.getClass()));
resultItem = ((Object[]) innerResult)[2];
assertTrue("Failed to return Employees correctly, Not a City", String.class.isAssignableFrom(resultItem.getClass()));
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee in project eclipselink by eclipse-ee4j.
the class FetchGroupTrackerWeavingTests method verifyCheckFetchedForSetWithFetchGroup_OneToMany.
@Test
public void verifyCheckFetchedForSetWithFetchGroup_OneToMany() {
Employee emp = new Employee();
TestFetchGroup fg = new TestFetchGroup();
((FetchGroupTracker) emp)._persistence_setFetchGroup(fg);
assertNull(this.checkAttribute);
assertNull(this.checkForSetAttribute);
emp.setPhoneNumbers(new ArrayList<PhoneNumber>());
assertNull(this.checkAttribute);
assertNotNull(this.checkForSetAttribute);
assertEquals("phoneNumbers", this.checkForSetAttribute);
}
Aggregations