예제 #1
0
  @Test
  public void testQualifierAsIndex() {
    Bank bank = new Bank();
    for (int i = 0; i < 10000; i++) {
      Client client = new Client();
      client.setIdNumber("aaa" + i);
      if (i % 2 == 0) {
        client.setSurname("aaa");
      } else {
        client.setSurname("bbb");
      }
      bank.addToClient(client);
    }
    db.commit();

    // This getters will hit the index.
    // Finding qualified properties are efficient.
    Assert.assertEquals("aaa1", bank.getClientForIdNumberQualifier("aaa1").getIdNumber());
    Assert.assertEquals("aaa1111", bank.getClientForIdNumberQualifier("aaa1111").getIdNumber());
    Assert.assertEquals("aaa9999", bank.getClientForIdNumberQualifier("aaa9999").getIdNumber());
    Assert.assertNull(bank.getClientForIdNumberQualifier("aaa10001"));

    Assert.assertEquals(5000, bank.getClientForSurnameQualifier("aaa").size());
    Assert.assertEquals(5000, bank.getClientForSurnameQualifier("bbb").size());
    Assert.assertEquals(
        "aaa", bank.getClientForSurnameQualifier("aaa").iterator().next().getSurname());
    Assert.assertEquals(
        "bbb", bank.getClientForSurnameQualifier("bbb").iterator().next().getSurname());
  }
예제 #2
0
  @Test(expected = IllegalStateException.class)
  public void testQualifierEnsuresUniqueness() {
    Bank bank = new Bank();
    Client john = new Client();
    john.setIdNumber("aaa1");
    john.setSurname("Smith");
    bank.addToClient(john);

    Client joe = new Client();
    joe.setIdNumber("aaa1");
    john.setSurname("Clark");
    bank.addToClient(joe);
  }