Search in sources :

Example 21 with HintProvider

use of com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider in project cuba by cuba-platform.

the class HintProviderTest method requestHint_fieldNameHint_where_exists.

@Test
public void requestHint_fieldNameHint_where_exists() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name", "owner");
    builder.startNewEntity("Player");
    builder.addStringAttribute("name");
    builder.addStringAttribute("nickname");
    builder.addReferenceAttribute("team", "Team");
    JpqlEntityModel playerEntity = builder.produce();
    DomainModel model = new DomainModel();
    model.add(teamEntity);
    model.add(playerEntity);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("select p.name from Player p " + "where exists " + "(select 1 " + "from Team t " + "where t.onwer = p.~)");
    List<String> options = response.getOptions();
    assertEquals(3, options.size());
    assertEquals("name", options.get(0));
    assertEquals("nickname", options.get(1));
    assertEquals("team", options.get(2));
    response = hintProvider.requestHint("select t.~ from Player p " + "where exists " + "(select 1 " + "from Team t " + "where t.onwer = p.name)");
    options = response.getOptions();
    assertEquals(0, options.size());
    assertEquals("Query error", response.getErrorMessage());
    assertEquals(1, response.getCauseErrorMessages().size());
    assertEquals("Cannot parse [t.]", response.getCauseErrorMessages().get(0));
    response = hintProvider.requestHint("select p.name from Player p " + "where exists " + "(select 1 " + "from Team t " + "where t.~ = p.name)");
    options = response.getOptions();
    assertEquals(2, options.size());
    assertEquals("name", options.get(0));
    assertEquals("owner", options.get(1));
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Aggregations

DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)21 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)21 EntityBuilder (com.haulmont.cuba.core.sys.jpql.model.EntityBuilder)20 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)20 Test (org.junit.Test)20 JpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)17 JpqlEntityModelImpl (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl)3 DomainModelBuilder (com.haulmont.cuba.core.sys.jpql.DomainModelBuilder)1 HintRequest (com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest)1 Option (com.haulmont.cuba.gui.components.autocomplete.impl.Option)1 ArrayList (java.util.ArrayList)1