コード例 #1
0
  /**
   * Tests that when a repeated ORDER BY clause is added to the selector, it is actually ignored.
   */
  @Test
  public void testOrderBySubstitution() {
    SelectorBuilder builder = new SelectorBuilder();

    builder = builder.orderAscBy(CampaignField.BidType).orderDescBy(CampaignField.Amount);
    Selector selector = builder.build();

    assertNotNull(selector.getOrdering());
    assertEquals(2, selector.getOrdering().length);

    builder.orderAscBy(CampaignField.BidType);
    selector = builder.build();

    assertNotNull(selector.getOrdering());
    assertEquals(2, selector.getOrdering().length);

    OrderBy orderBy = selector.getOrdering()[0];

    assertEquals("BidType", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());

    orderBy = selector.getOrdering()[1];

    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.DESCENDING, orderBy.getSortOrder());
  }
コード例 #2
0
  /** Tests the order by criteria */
  @Test
  public void testOrderByBuild() {
    SelectorBuilder builder = new SelectorBuilder();

    builder = builder.orderAscBy(CampaignField.BidType);
    Selector selector = builder.build();

    assertNotNull(selector.getOrdering());
    assertEquals(1, selector.getOrdering().length);

    OrderBy orderBy = selector.getOrdering()[0];

    assertEquals("BidType", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());

    builder.orderAscBy(CampaignField.Amount).orderDescBy(CampaignField.BidType);
    selector = builder.build();

    assertNotNull(selector.getOrdering());
    assertEquals(3, selector.getOrdering().length);

    orderBy = selector.getOrdering()[0];

    assertEquals("BidType", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());

    orderBy = selector.getOrdering()[1];

    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());

    orderBy = selector.getOrdering()[2];

    assertEquals("BidType", orderBy.getField());
    assertEquals(SortOrder.DESCENDING, orderBy.getSortOrder());

    // Removing the OrderBy for BidType
    selector = builder.removeOrderBy("BidType").build();

    assertNotNull(selector.getOrdering());
    assertEquals(1, selector.getOrdering().length);

    orderBy = selector.getOrdering()[0];

    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
  }