コード例 #1
0
  /**
   * Tests fetching entities by using property of child item(s)
   *
   * @param factory
   */
  @Test(dataProvider = "repositoryFactories")
  public void testWithChildRelation(RepositoryFactory factory) {
    IOrderRepository repo = factory.getRepository(IOrderRepository.class);

    List<Order> orders = repo.findOrdersWithItem("soap");
    Assert.assertEquals(orders.size(), 2);
    Assert.assertEquals(
        CommonUtils.toSet(orders.get(0).getTitle(), orders.get(1).getTitle()),
        CommonUtils.toSet("order1", "order2"));

    orders = repo.findOrdersWithItem("book");
    Assert.assertEquals(orders.size(), 1);
    Assert.assertEquals(CommonUtils.toSet(orders.get(0).getTitle()), CommonUtils.toSet("order3"));

    orders = repo.findOrdersWithItem("nonexisting");
    Assert.assertEquals(orders.size(), 0);
  }
コード例 #2
0
  /**
   * Testes finding with nested relation and also which has UN-MAPPED relation via join table
   *
   * @param factory
   */
  @Test(dataProvider = "repositoryFactories")
  public void testWithNestedRelation(RepositoryFactory factory) {
    IOrderRepository repo = factory.getRepository(IOrderRepository.class);

    List<Order> orders = repo.findOrdersOfCusomerGroup("Group3");
    Assert.assertEquals(orders.size(), 2);
    Assert.assertEquals(
        CommonUtils.toSet(orders.get(0).getTitle(), orders.get(1).getTitle()),
        CommonUtils.toSet("order1", "order2"));

    orders = repo.findOrdersOfCusomerGroup("Group2");
    Assert.assertEquals(orders.size(), 1);
    Assert.assertEquals(CommonUtils.toSet(orders.get(0).getTitle()), CommonUtils.toSet("order3"));

    orders = repo.findOrdersOfCusomerGroup("unknown");
    Assert.assertEquals(orders.size(), 0);
  }
コード例 #3
0
  @Test(dataProvider = "repositoryFactories")
  public void testWithMappedJoinRelation(RepositoryFactory factory) {
    ICustomerGroupRepository repo = factory.getRepository(ICustomerGroupRepository.class);

    List<CustomerGroup> groups = repo.findGroupsOfCusomer("Customer1");
    Assert.assertEquals(groups.size(), 2);
    Assert.assertEquals(
        CommonUtils.toSet(groups.get(0).getName(), groups.get(1).getName()),
        CommonUtils.toSet("Group1", "Group3"));

    groups = repo.findGroupsOfCusomer("Customer2");
    Assert.assertEquals(groups.size(), 2);
    Assert.assertEquals(
        CommonUtils.toSet(groups.get(0).getName(), groups.get(1).getName()),
        CommonUtils.toSet("Group1", "Group2"));

    groups = repo.findGroupsOfCusomer("nonexisting");
    Assert.assertEquals(groups.size(), 0);
  }
コード例 #4
0
  /**
   * Tests fetching entities with nested parent entity property as condition Also validates the sub
   * entity proxies are set properly
   *
   * @param factory
   */
  @Test(dataProvider = "repositoryFactories")
  public void testWithParentRelation(RepositoryFactory factory) {
    IOrderRepository repo = factory.getRepository(IOrderRepository.class);

    List<Order> orders = repo.findOrdersOfCusomer("Customer1");
    Assert.assertEquals(orders.size(), 2);
    Assert.assertEquals(
        CommonUtils.toSet(orders.get(0).getTitle(), orders.get(1).getTitle()),
        CommonUtils.toSet("order1", "order2"));
    Assert.assertEquals(orders.get(0).getItems().size(), 2);

    orders = repo.findOrdersOfCusomer("Customer2");
    Assert.assertEquals(orders.size(), 1);
    Assert.assertEquals(CommonUtils.toSet(orders.get(0).getTitle()), CommonUtils.toSet("order3"));

    // test if nested entity proxy works fine
    Assert.assertEquals(orders.get(0).getCustomer().getName(), "Customer2");

    orders = repo.findOrdersOfCusomer("Customerxxx");
    Assert.assertEquals(orders.size(), 0);
  }