コード例 #1
0
 @Test
 public void testRemove() {
   Project obj = dod.getRandomProject();
   assertNotNull("Data on demand for 'Project' failed to initialize correctly", obj);
   Long id = obj.getId();
   assertNotNull("Data on demand for 'Project' failed to provide an identifier", id);
   obj = Project.findProject(id);
   try {
     obj.remove();
   } catch (IllegalStateException e) {
     assertTrue(
         "Failed to remove 'Project' with identifier '" + id + "'",
         "error_description_project_to_remove_in_progress".equals(e.getMessage())
             || "error_description_project_to_remove_has_history".equals(e.getMessage()));
     return;
   }
   obj.flush();
   assertNull("Failed to remove 'Project' with identifier '" + id + "'", Project.findProject(id));
 }
コード例 #2
0
  @Test
  public void testRemoveWhenReferenced() {
    Project obj = dod.getNewTransientProject(5);
    assertNotNull("Data on demand for 'Project' failed to initialize correctly", obj);
    obj.setDateFrom(DateTrimmer.addDays(DateTrimmer.today(), -10));
    obj.setDateTo(DateTrimmer.addDays(DateTrimmer.today(), -5));
    Set<Site> sites = new HashSet<Site>();
    for (int i = 0; i < 5; ++i) {
      while (!sites.add(siteDataOnDemand.getRandomSite())) ;
    }
    obj.getSites().addAll(sites);
    for (Site site : sites) {
      site.getProjects().add(obj);
      site.persist();
    }
    obj.persist();
    Long id = obj.getId();
    obj.remove();
    assertNull("Project failed to remove", Project.findProject(id));
    for (Site site : sites) {
      assertFalse("Project not removed", Site.findSite(site.getId()).getProjects().contains(obj));
    }

    obj = dod.getRandomProject();
    obj.setDateFrom(DateTrimmer.addDays(DateTrimmer.today(), -10));
    obj.setDateTo(DateTrimmer.addDays(DateTrimmer.today(), -5));
    JobPositionHistoryEntry jphe =
        jobPositionHistoryEntryDataOnDemand.getNewTransientJobPositionHistoryEntry(4);
    jphe.getJobPosition().setProject(obj);
    obj.getJobPositions().add(jphe.getJobPosition());
    jphe.getJobPosition().persist();
    jphe.persist();
    obj.persist();
    exception.expect(IllegalStateException.class);
    exception.expectMessage("error_description_project_to_remove_has_history");
    obj.remove();
  }