예제 #1
0
  @Test(expectedExceptions = {IllegalStateException.class})
  public void shouldKeepOneToOneSymetric2() {
    initData10();
    OneToOne<Person, Person> rel = db.oneToOneSymmetric(persons, "rel", persons);

    rel.link(1, 2);
    rel.link(5, 2);
  }
예제 #2
0
  @Test
  public void shouldKeepOneToOneSymetric1() {
    initData10();
    OneToOne<Person, Person> rel = db.oneToOneSymmetric(persons, "rel", persons);

    rel.link(1, 2);
    rel.link(3, 4);

    eq(rel.from(1), 2);
    eq(rel.from(2), 1);
    eq(rel.from(3), 4);
    eq(rel.from(4), 3);

    eq(rel.to(1), 2);
    eq(rel.to(2), 1);
    eq(rel.to(3), 4);
    eq(rel.to(4), 3);

    hasId(rel.from(p(1)), 2);
    hasId(rel.from(p(2)), 1);
    hasId(rel.from(p(3)), 4);
    hasId(rel.from(p(4)), 3);

    hasId(rel.to(p(1)), 2);
    hasId(rel.to(p(2)), 1);
    hasId(rel.to(p(3)), 4);
    hasId(rel.to(p(4)), 3);

    eq(rel.to(100), -1);
    eq(rel.from(100), -1);

    eq(rel.to(p(100)), null);
    eq(rel.from(p(100)), null);

    rel.delink(4, 3);

    eq(rel.to(3), -1);
    eq(rel.to(4), -1);
    eq(rel.from(3), -1);
    eq(rel.from(4), -1);

    eq(rel.to(p(3)), null);
    eq(rel.to(p(4)), null);
    eq(rel.from(p(3)), null);
    eq(rel.from(p(4)), null);

    eq(rel.from(1), 2);
    eq(rel.from(2), 1);
    eq(rel.to(1), 2);
    eq(rel.to(2), 1);
  }