Search in sources :

Example 1 with JpqlEntityModelImpl

use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl in project cuba by cuba-platform.

the class HintProviderTest method requestHint_entityNameHint_order.

@Test
public void requestHint_entityNameHint_order() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModelImpl playerEntity = builder.produceImmediately("Player");
    JpqlEntityModelImpl parentEntity = builder.produceImmediately("Parent");
    DomainModel model = new DomainModel();
    model.add(playerEntity);
    model.add(parentEntity);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("SELECT p FROM P~");
    List<String> options = response.getOptions();
    assertEquals(2, options.size());
    assertEquals("Parent", options.get(0));
    assertEquals("Player", options.get(1));
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) JpqlEntityModelImpl(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Example 2 with JpqlEntityModelImpl

use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl in project cuba by cuba-platform.

the class HintProviderTest method requestHint_erroneous.

@Test
public void requestHint_erroneous() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModelImpl playerEntity = builder.produceImmediately("Player");
    DomainModel model = new DomainModel();
    model.add(playerEntity);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("select t FROM p...~");
    List<String> options = response.getOptions();
    assertEquals(0, options.size());
    assertEquals("Query error", response.getErrorMessage());
    assertArrayEquals(new String[] { "Cannot parse [p...]", "Error near: \"p\"" }, response.getCauseErrorMessages().toArray());
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) JpqlEntityModelImpl(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Example 3 with JpqlEntityModelImpl

use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl in project cuba by cuba-platform.

the class HintProviderTest method requestHint_entityNameHint_simple.

@Test
public void requestHint_entityNameHint_simple() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModelImpl playerEntity = builder.produceImmediately("Player");
    DomainModel model = new DomainModel();
    model.add(playerEntity);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("SELECT p FROM P~");
    List<String> options = response.getOptions();
    assertEquals(1, options.size());
    assertEquals("Player", options.get(0));
    response = hintProvider.requestHint("FROM N~");
    options = response.getOptions();
    assertEquals(0, options.size());
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) JpqlEntityModelImpl(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Example 4 with JpqlEntityModelImpl

use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl in project cuba by cuba-platform.

the class QueryTransformerAstBasedTest method getResult_noChangesMade.

@Test
public void getResult_noChangesMade() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModelImpl playerEntity = builder.produceImmediately("Player");
    DomainModel model = new DomainModel(playerEntity);
    assertTransformsToSame(model, "SELECT p FROM Player p");
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) JpqlEntityModelImpl(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) Test(org.junit.Test)

Aggregations

DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)4 EntityBuilder (com.haulmont.cuba.core.sys.jpql.model.EntityBuilder)4 JpqlEntityModelImpl (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl)4 Test (org.junit.Test)4 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)3 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)3