コード例 #1
0
  @Test
  public void shouldFireEventForRelationshipEntityWhenItIsSavedIndirectly() throws Exception {
    FictionalCharacter fingolfin = template.save(new FictionalCharacter("Fingolfin"));
    entities.clear();
    FictionalCharacter morgoth = new FictionalCharacter("Morgoth");
    morgoth.slew(fingolfin, "Dagor Bragollach");

    template.save(morgoth);

    assertThat(entities.size(), is(2));
    assertThat(((FictionalCharacter) entities.get(0)).id, is(morgoth.id));
    assertThat(((Slaying) entities.get(1)).battle, is(equalTo("Dagor Bragollach")));
  }
コード例 #2
0
  @Test
  public void shouldFireEventForRelationshipEntities() throws Exception {
    FictionalCharacter beleg = template.save(new FictionalCharacter("Beleg"));
    FictionalCharacter brandir = template.save(new FictionalCharacter("Brandir"));
    entities.clear();
    FictionalCharacter turin = new FictionalCharacter("Túrin");
    turin.slew(beleg, brandir);

    template.save(turin);

    assertThat(entities.size(), is(3));
    assertThat(((FictionalCharacter) entities.get(0)).id, is(turin.id));
    assertThat(
        ((Slaying) entities.get(1)).slayee.id,
        is(Matchers.<Long>either(equalTo(beleg.id)).or(equalTo(brandir.id))));
    assertThat(
        ((Slaying) entities.get(2)).slayee.id,
        is(Matchers.<Long>either(equalTo(beleg.id)).or(equalTo(brandir.id))));
  }