예제 #1
0
  @Test
  public void testCascadeUpdateOrgnizationAndJob() {
    User user = createDefaultUser();

    Organization organization1 = new Organization();
    organization1.setName("test1");
    Organization organization2 = new Organization();
    organization2.setName("test2");
    organizationService.save(organization1);
    organizationService.save(organization2);

    user.addOrganizationJob(new UserOrganizationJob(organization1.getId(), null));
    user.addOrganizationJob(new UserOrganizationJob(organization2.getId(), null));
    userService.update(user);

    // 清除缓存
    clear();

    user = userService.findOne(user.getId());
    Assert.assertEquals(2, user.getOrganizationJobs().size());
    Assert.assertEquals(
        organization1.getId(), user.getOrganizationJobs().get(0).getOrganizationId());
    Assert.assertEquals(
        organization2.getId(), user.getOrganizationJobs().get(1).getOrganizationId());
  }
예제 #2
0
  @Test
  public void testClearRelation() {
    User user = createDefaultUser();

    Organization organization1 = new Organization();
    organization1.setName("test1");
    Organization organization2 = new Organization();
    organization2.setName("test2");
    organizationService.save(organization1);
    organizationService.save(organization2);

    Job job1 = new Job();
    job1.setName("test1");
    Job job2 = new Job();
    job2.setName("test2");
    jobService.save(job1);
    jobService.save(job2);

    user.addOrganizationJob(new UserOrganizationJob(organization1.getId(), null));
    user.addOrganizationJob(new UserOrganizationJob(organization2.getId(), job1.getId()));
    user.addOrganizationJob(new UserOrganizationJob(organization2.getId(), job2.getId()));
    userService.update(user);

    // 清除缓存
    clear();

    organizationService.delete(organization1);
    jobService.delete(job1);

    userClearRelationService.clearDeletedUserRelation();

    clear();

    user = userService.findOne(user.getId());

    Assert.assertEquals(2, user.getOrganizationJobs().size());

    Assert.assertEquals(null, user.getOrganizationJobs().get(1).getJobId());
  }