public void testKeywordFunction() {
    Collector hcc = new Collector();
    cc.getMatchingKeywords("f", 2, hcc);

    HQLCompletionProposal[] completionProposals = hcc.getCompletionProposals();

    assertEquals(4, completionProposals.length);
    assertEquals("alse", completionProposals[0].getCompletion());

    hcc.clear();
    cc.getMatchingFunctions("ma", 2, hcc);

    completionProposals = hcc.getCompletionProposals();

    assertEquals(1, completionProposals.length);
    assertEquals("x", completionProposals[0].getCompletion());

    hcc.clear();
    cc.getMatchingKeywords("FR", 3, hcc);
    completionProposals = hcc.getCompletionProposals();
    assertEquals(1, completionProposals.length);

    hcc.clear();
    cc.getMatchingFunctions("MA", 2, hcc);
    completionProposals = hcc.getCompletionProposals();
    assertEquals(1, completionProposals.length);
  }
  public void testStoreCity() {
    String query = "select p from Product p join p.stores store where store";
    List visible = getVisibleEntityNames(query.toCharArray());
    Collector hcc = new Collector();

    String canonicalPath = cc.getCanonicalPath(visible, "store.city");
    cc.getMatchingProperties(canonicalPath, "", hcc);
    doTestFields(hcc.getCompletionProposals(), new String[] {"id", "name"});
  }
  public void testGetStoreFields() {
    Collector hcc = new Collector();

    cc.getMatchingProperties("Store", "", hcc);
    doTestFields(hcc.getCompletionProposals(), new String[] {"city", "id", "name", "name2"});
    hcc.clear();
    cc.getMatchingProperties("Store", "name", hcc);
    doTestFields(hcc.getCompletionProposals(), new String[] {"name", "name2"});
    hcc.clear();
    cc.getMatchingProperties("Store", "name2", hcc);
    doTestFields(hcc.getCompletionProposals(), new String[] {"name2"});
    hcc.clear();
  }
  private void doTestUnaliasedProductQuery(final String query) {
    Collector hcc = new Collector();

    List visible = getVisibleEntityNames(query.toCharArray());
    cc.getMatchingProperties(cc.getCanonicalPath(visible, "owner"), "f", hcc);

    HQLCompletionProposal[] completionProposals = hcc.getCompletionProposals();
    //
    assertEquals(1, completionProposals.length);
    assertEquals("firstName", completionProposals[0].getSimpleName());
    //
    hcc.clear();
    cc.getMatchingProperties(cc.getCanonicalPath(visible, "owner"), "l", hcc);
    completionProposals = hcc.getCompletionProposals();
    assertEquals(1, completionProposals.length);
    assertEquals("lastName", completionProposals[0].getSimpleName());
    //
    hcc.clear();
    cc.getMatchingProperties(cc.getCanonicalPath(visible, "owner"), "", hcc);
    // firstname, lastname, owner
    assertEquals(3, hcc.getCompletionProposals().length);
    //
    hcc.clear();
    cc.getMatchingProperties(cc.getCanonicalPath(visible, "owner"), "g", hcc);
    assertEquals(0, hcc.getCompletionProposals().length);
  }
  public void testProductOwnerAddress() {
    String query = "select p from Product p where p.owner.";
    List visible = getVisibleEntityNames(query.toCharArray());

    Collector hcc = new Collector();

    cc.getMatchingProperties(cc.getCanonicalPath(visible, "p.owner"), "", hcc);
    doTestFields(hcc.getCompletionProposals(), new String[] {"address", "firstName", "lastName"});

    hcc.clear();
    query = "select p from Product p where p.owner.address.";
    visible = getVisibleEntityNames(query.toCharArray());
    cc.getMatchingProperties(cc.getCanonicalPath(visible, "p.owner.address"), "", hcc);
    doTestFields(hcc.getCompletionProposals(), new String[] {"id", "number", "street"});
  }
  public void testGetMappedClasses() {
    Collector hcc = new Collector();
    cc.getMatchingImports("", hcc);
    assertEquals("Invalid entity names count", 9, hcc.getCompletionProposals().length);

    hcc.clear();
    cc.getMatchingImports(" ", hcc);
    assertTrue("Space prefix should have no classes", hcc.getCompletionProposals().length == 0);

    hcc.clear();
    cc.getMatchingImports("pro", hcc);
    assertTrue("Completion should not be case sensitive", hcc.getCompletionProposals().length == 2);

    hcc.clear();
    cc.getMatchingImports("StoreC", hcc);
    assertEquals("Invalid entity names count", 1, hcc.getCompletionProposals().length);
    assertEquals(
        "StoreCity should have been found",
        "StoreCity",
        hcc.getCompletionProposals()[0].getSimpleName());

    hcc.clear();
    cc.getMatchingImports("NotThere", hcc);
    assertTrue(hcc.getCompletionProposals().length == 0);

    hcc.clear();
    cc.getMatchingImports("Uni", hcc);
    assertEquals("Universe", hcc.getCompletionProposals()[0].getSimpleName());
  }
  public void testGetProductFields() {
    Collector hcc = new Collector();

    cc.getMatchingProperties("Product", "", hcc);
    doTestFields(
        hcc.getCompletionProposals(),
        new String[] {"id", "otherOwners", "owner", "price", "stores", "version", "weight"});
    hcc.clear();

    cc.getMatchingProperties("Product", " ", hcc);
    doTestFields(hcc.getCompletionProposals(), new String[] {});
    hcc.clear();

    cc.getMatchingProperties("Product", "v", hcc);
    doTestFields(hcc.getCompletionProposals(), new String[] {"version"});
    hcc.clear();

    cc.getMatchingProperties("Product", "V", hcc);
    doTestFields(hcc.getCompletionProposals(), new String[] {"version"});
    hcc.clear();

    cc.getMatchingProperties("Product", "X", hcc);
    doTestFields(hcc.getCompletionProposals(), new String[0]);
  }
  public void testUnmappedClassFields() {
    Collector hcc = new Collector();

    cc.getMatchingProperties("UnmappedClass", "", hcc);
    doTestFields(hcc.getCompletionProposals(), new String[0]);
  }