use of org.eclipse.persistence.testing.models.jpa.advanced.LargeProject in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testDatabaseSyncNewObject.
public void testDatabaseSyncNewObject() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Project project = new LargeProject();
em.persist(project);
project.setName("Blah");
project.setTeamLeader(new Employee());
project.getTeamLeader().addProject(project);
em.flush();
} catch (RuntimeException ex) {
rollbackTransaction(em);
if (ex instanceof IllegalStateException)
return;
}
fail("Failed to throw illegal argument when finding unregistered new object cascading on database sync");
}
use of org.eclipse.persistence.testing.models.jpa.advanced.LargeProject in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testOverwrittingAndOverLoadingMethods.
// This test weaving works with over-writing methods in subclasses, and overloading methods.
public void testOverwrittingAndOverLoadingMethods() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Address address = new Address();
address.setCity("Ottawa");
Employee employee = new Employee();
employee.setAddress(address);
LargeProject project = new LargeProject();
project.setTeamLeader(employee);
em.persist(employee);
em.persist(project);
commitTransaction(em);
closeEntityManager(em);
em = createEntityManager();
beginTransaction(em);
employee = em.find(Employee.class, employee.getId());
project = em.find(LargeProject.class, project.getId());
if ((employee.getAddress("Home") == null) || (!employee.getAddress("Home").getCity().equals("Ottawa"))) {
fail("Get address did not work.");
}
employee.setAddress("Toronto");
if (!employee.getAddress().getCity().equals("Toronto")) {
fail("Set address did not work.");
}
if (project.getTeamLeader() != employee) {
fail("Get team leader did not work, team is: " + project.getTeamLeader() + " but should be:" + employee);
}
em.remove(employee.getAddress());
em.remove(employee);
em.remove(project);
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.LargeProject in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testWeaving.
/**
* Test that all of the classes in the advanced model were weaved as expected.
*/
public void testWeaving() {
// Only test if weaving was on, test runs without weaving must set this system property.
if (isWeavingEnabled()) {
internalTestWeaving(new Employee(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), true);
internalTestWeaving(new FormerEmployment(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Address(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new PhoneNumber(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new EmploymentPeriod(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
// field-locking
internalTestWeaving(new Buyer(), false, isWeavingForFetchGroupsEnabled(), false);
// field-locking
internalTestWeaving(new GoldBuyer(), false, isWeavingForFetchGroupsEnabled(), false);
// field-locking
internalTestWeaving(new PlatinumBuyer(), false, isWeavingForFetchGroupsEnabled(), false);
// eager 1-m
internalTestWeaving(new Department(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Golfer(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new GolferPK(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new SmallProject(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new LargeProject(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Man(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Woman(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
// serialized
internalTestWeaving(new Vegetable(), false, isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new VegetablePK(), false, isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new WorldRank(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Equipment(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new EquipmentCode(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new PartnerLink(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.LargeProject in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testNonRefreshLazyRelationship.
// Bug 335322
public void testNonRefreshLazyRelationship() {
if (isOnServer()) {
return;
}
EntityManager setupEm = createEntityManager();
setupEm.getTransaction().begin();
Employee emp = new Employee();
setupEm.persist(emp);
Employee direct = new Employee("Managed", "EMployee");
setupEm.persist(direct);
emp.getManagedEmployees().add(direct);
direct.setManager(emp);
Dealer dealer = new Dealer("Jim", "Bob");
emp.getDealers().add(dealer);
setupEm.persist(dealer);
Project project = new LargeProject("Alpha Alpha Zulu");
setupEm.persist(project);
emp.getProjects().add(project);
setupEm.getTransaction().commit();
clearCache();
EntityManager em1 = createEntityManager();
EntityManager em2 = createEntityManager();
emp = em1.find(Employee.class, emp.getId());
Employee emp2 = em2.find(Employee.class, emp.getId());
Employee direct2 = em2.find(Employee.class, direct.getId());
Dealer dealer2 = em2.find(Dealer.class, dealer.getId());
Project project2 = em2.find(Project.class, project.getId());
em1.getTransaction().begin();
emp.getManagedEmployees().iterator().next().setFirstName("something");
emp.getDealers().get(0).setFirstName("Something");
emp.getProjects().iterator().next().setName("Beta Beta Wiskey");
em1.getTransaction().commit();
em2.refresh(emp2);
try {
assertEquals("Did not cascade refresh across untriggered lazy", emp2.getManagedEmployees().iterator().next().getFirstName(), "something");
assertEquals("Cascaded refresh to non cascade refresh entity", emp2.getDealers().get(0).getFirstName(), "Jim");
assertEquals("Cascade refresh to non cascade refresh", emp2.getProjects().iterator().next().getName(), "Alpha Alpha Zulu");
} finally {
try {
em2.getTransaction().begin();
em2.remove(emp2);
em2.remove(direct2);
em2.remove(dealer2);
em2.remove(project2);
em2.getTransaction().commit();
} catch (Exception e) {
}
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.LargeProject in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testDeleteAllProjects.
public void testDeleteAllProjects() {
if ((JUnitTestCase.getServerSession()).getPlatform().isSymfoware()) {
getServerSession().logMessage("Test testDeleteAllProjects skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193).");
return;
}
String errorMsg = "";
SmallProject sp = null;
LargeProject lp = null;
HugeProject hp = null;
SpecialHugeProject slp = null;
EntityManager em = createEntityManager();
beginTransaction(em);
String[] classesToDelete = { "Project", "SmallProject", "LargeProject", "HugeProject", "SpecialHugeProject" };
try {
for (int i = 0; i < classesToDelete.length; i++) {
if (sp == null) {
sp = new SmallProject();
em.persist(sp);
}
if (lp == null) {
lp = new LargeProject();
em.persist(lp);
}
if (hp == null) {
hp = new HugeProject();
em.persist(hp);
}
if (slp == null) {
slp = new SpecialHugeProject();
em.persist(slp);
}
em.flush();
String classToDelete = classesToDelete[i];
em.createQuery("DELETE FROM " + classToDelete + " p").executeUpdate();
em.clear();
sp = em.find(SmallProject.class, sp.getId());
lp = em.find(LargeProject.class, lp.getId());
hp = em.find(HugeProject.class, hp.getId());
slp = em.find(SpecialHugeProject.class, slp.getId());
String unexpectedlyDeleted = "";
String unexpectedlyNotDeleted = "";
if (sp == null) {
if (classToDelete.equals("LargeProject") || classToDelete.equals("HugeProject") || classToDelete.equals("SpecialHugeProject")) {
unexpectedlyDeleted += "SmallProject; ";
}
} else {
if (classToDelete.equals("Project") || classToDelete.equals("SmallProject")) {
unexpectedlyNotDeleted += "SmallProject; ";
}
}
if (lp == null) {
if (classToDelete.equals("SmallProject") || classToDelete.equals("HugeProject") || classToDelete.equals("SpecialHugeProject")) {
unexpectedlyDeleted += "LargeProject; ";
}
} else {
if (classToDelete.equals("Project") || classToDelete.equals("LargeProject")) {
unexpectedlyNotDeleted += "LargeProject; ";
}
}
if (hp == null) {
if (classToDelete.equals("SmallProject") || classToDelete.equals("SpecialHugeProject")) {
unexpectedlyDeleted += "HugeProject; ";
}
} else {
if (classToDelete.equals("Project") || classToDelete.equals("LargeProject") || classToDelete.equals("HugeProject")) {
unexpectedlyNotDeleted += "HugeProject; ";
}
}
if (slp == null) {
if (classToDelete.equals("SmallProject")) {
unexpectedlyDeleted += "SpecialHugeProject; ";
}
} else {
if (classToDelete.equals("Project") || classToDelete.equals("LargeProject") || classToDelete.equals("HugeProject") || classToDelete.equals("SpecialHugeProject")) {
unexpectedlyNotDeleted += "SpecialHugeProject; ";
}
}
String localErrorMsg = "";
if (unexpectedlyDeleted.length() > 0) {
localErrorMsg += "\n\t\tUnexpectedlyDeleted: " + unexpectedlyDeleted;
}
if (unexpectedlyNotDeleted.length() > 0) {
localErrorMsg += "\n\t\tUnexpectedlyNotDeleted: " + unexpectedlyNotDeleted;
}
if (localErrorMsg.length() > 0) {
errorMsg += "\n\tDELETE FROM " + classToDelete + " p" + localErrorMsg;
}
}
} finally {
closeEntityManagerAndTransaction(em);
}
if (errorMsg.length() > 0) {
fail(errorMsg);
}
}
Aggregations