/** Test the inverse of LESS THAN */
  @Test
  public void testInverseOfLT() {
    query.addFilter(new LessThanFilter("accessLevel", 5));
    List<User> users = processor.execute(query);

    Query<User> refQuery = new Query<User>(User.class);
    refQuery.addFilter(new GreaterOrEqualFilter("accessLevel", 5));
    List<User> usersGE5 = processor.execute(refQuery);
    List<User> ref = userDAO.findAll();
    ref.removeAll(usersGE5);

    assertEquals(ref.size(), users.size());
    assertTrue(users.containsAll(ref));
  }
Exemplo n.º 2
0
  /** Test if the {@link NotFilter} is correct */
  @Test
  public void testNot() {
    Product p = productDAO.findByName("P1").get(0);
    query.addFilter(new NotFilter(new EqualFilter("product", p)));
    List<Ticket> tickets = processor.execute(query);

    Query<Ticket> refQuery = new Query<Ticket>(Ticket.class);
    refQuery.addFilter(new EqualFilter("product", p));
    List<Ticket> ticketsForProduct = processor.execute(refQuery);
    List<Ticket> ref = ticketDAO.findAll();
    ref.removeAll(ticketsForProduct);

    assertEquals(ref.size(), tickets.size());
    assertTrue(tickets.containsAll(ref));
  }
  /**
   * Test an execution of a {@link Query} with a {@link LessThanFilter}. The following conditions
   * are checked :<br>
   *
   * <ul>
   *   <li>The list contains 1 user
   *   <li>The list contains the user "U3"
   * </ul>
   */
  @Test
  public void testLessThanFilterQuery() {
    query.addFilter(new LessThanFilter("accessLevel", 5));
    List<User> users = processor.execute(query);

    assertEquals(1, users.size());
    assertTrue(users.contains(userDAO.findByLogin("user3")));
  }
Exemplo n.º 4
0
  /**
   * Execute the query
   *
   * @param command The query command
   * @return The view which will be display
   */
  @RequestMapping(value = "contact/search", method = RequestMethod.POST)
  public ModelAndView search(@ModelAttribute("contactQuery") ContactQueryCommand command) {
    Map<String, Object> map = new HashMap<String, Object>();
    List<Contact> result = null;
    Query<Contact> query = new Query<Contact>(Contact.class);

    if (!command.getContactName().isEmpty()) {
      if (command.getMatchMode() == ContactQueryCommand.EXACT_MATCH_MODE) {
        query.addFilter(new EqualFilter("name", command.getContactName()));
      } else {
        query.addFilter(new LikeFilter("name", command.getContactName()));
      }
    }

    result = contactDAO.filter(query);
    map.put("result", result);
    return new ModelAndView("contact/result", map);
  }
Exemplo n.º 5
0
  /**
   * Test an execution of a {@link Query} with a {@link NotFilter}. The following conditions are
   * checked :<br>
   *
   * <ul>
   *   <li>The list contains 2 tickets
   *   <li>The list contains the ticket "T4"
   *   <li>The list contains the ticket "T5"
   * </ul>
   */
  @Test
  public void testNotFilterQuery() {
    Product p = productDAO.findByName("P1").get(0);
    query.addFilter(new NotFilter(new EqualFilter("product", p)));
    List<Ticket> tickets = processor.execute(query);

    assertEquals(2, tickets.size());
    assertTrue(tickets.contains(ticketDAO.findByTitle("T4").get(0)));
    assertTrue(tickets.contains(ticketDAO.findByTitle("T5").get(0)));
  }
Exemplo n.º 6
0
 /**
  * Test if an {@link IllegalArgumentException} is thrown by passing a <code>null</code> argument
  * to {@link NotFilter}
  */
 @Test(expected = IllegalArgumentException.class)
 public void testNotFilterWithNullArgument() {
   query.addFilter(new NotFilter(null));
   processor.execute(query);
 }
 /**
  * Test if an {@link IllegalArgumentException} is thrown by passing a <code>null</code> value
  * argument to {@link LessThanFilter}
  */
 @Test(expected = IllegalArgumentException.class)
 public void testLessThanFilterWithNullValue() {
   query.addFilter(new LessThanFilter("accessLevel", null));
   processor.execute(query);
 }
 /**
  * Test if an {@link IllegalArgumentException} is thrown by passing a <code>null</code> property
  * argument to {@link LessThanFilter}
  */
 @Test(expected = IllegalArgumentException.class)
 public void testLessThanFilterWithNullProperty() {
   query.addFilter(new LessThanFilter(null, 5));
   processor.execute(query);
 }
 /**
  * Test if an {@link ClassCastException} is thrown by passing an invalid value argument to {@link
  * LessThanFilter}
  */
 @Test(expected = ClassCastException.class)
 public void testLessThanFilterWithInvalidArguments() {
   query.addFilter(new LessThanFilter("accessLevel", "five"));
   processor.execute(query);
 }