Search in sources :

Example 6 with HintRequest

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

the class MacroProcessorTest method inlineFake_two_inlines_in_row.

@Test
public void inlineFake_two_inlines_in_row() {
    HintRequest request = processor.inlineFake("select p. from Player p where @between(p.joinDate, now, now+1, day) and @today(p.leaveDate)", 8);
    assertEquals("select p. from Player p where p.joinDate = :d  and p.leaveDate = :d ", request.getQuery());
    assertEquals(8, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Any), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @between(p.joinDate, now, now+1, day) and @today(p.)", 84);
    assertEquals("select p.name from Player p where p.joinDate = :d  and p. = :d ", request.getQuery());
    assertEquals(56, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Date), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @between(p.joinDate, now, now+1, day) and @between(p., now, now+1, day)", 86);
    assertEquals("select p.name from Player p where p.joinDate = :d  and p. = :d ", request.getQuery());
    assertEquals(56, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Date), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @dateEquals(p.joinDate, :d) and @dateEquals(p. ,:d)", 79);
    assertEquals("select p.name from Player p where p.joinDate = :d  and p.  =:d ", request.getQuery());
    assertEquals(56, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Date), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @today(p.joinDate) and @today(p.)", 65);
    assertEquals("select p.name from Player p where p.joinDate = :d  and p. = :d ", request.getQuery());
    assertEquals(56, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Date), request.getExpectedTypes());
}
Also used : HintRequest(com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest) Test(org.junit.Test)

Example 7 with HintRequest

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

the class AliasRemoverTest method testAliasReplacement.

@Test
public void testAliasReplacement() throws Exception {
    AliasRemover aliasRemover = new AliasRemover();
    HintRequest input = new HintRequest();
    input.setQuery("select queryEntity.!vin as \"vin\" from ref$Car queryEntity");
    input.setPosition(input.getQuery().indexOf("!"));
    input.setExpectedTypes(EnumSet.of(InferredType.Any));
    HintRequest result = aliasRemover.replaceAliases(input);
    Assert.assertEquals('!', result.getQuery().charAt(result.getPosition()));
    Assert.assertTrue(!result.getQuery().contains("as \""));
    System.out.println(result.getQuery());
    input.setQuery("select queryEntity.vin as \"vin\", queryEntity.!version as \"version\" from ref$Car queryEntity");
    input.setPosition(input.getQuery().indexOf("!"));
    input.setExpectedTypes(EnumSet.of(InferredType.Any));
    result = aliasRemover.replaceAliases(input);
    Assert.assertEquals('!', result.getQuery().charAt(result.getPosition()));
    Assert.assertTrue(!result.getQuery().contains("as \""));
    System.out.println(result.getQuery());
    input.setQuery("select queryEntity.!vin as \"vin\", queryEntity.version as \"version\" from ref$Car queryEntity");
    input.setPosition(input.getQuery().indexOf("!"));
    input.setExpectedTypes(EnumSet.of(InferredType.Any));
    result = aliasRemover.replaceAliases(input);
    Assert.assertEquals('!', result.getQuery().charAt(result.getPosition()));
    Assert.assertTrue(!result.getQuery().contains("as \""));
    System.out.println(result.getQuery());
    input.setQuery("select queryEntity.vin as \"vin\", queryEntity.version as \"version\" from ref$Car queryEntity");
    input.setPosition(input.getQuery().indexOf("\"ver"));
    input.setExpectedTypes(EnumSet.of(InferredType.Any));
    result = aliasRemover.replaceAliases(input);
    Assert.assertEquals(' ', result.getQuery().charAt(result.getPosition()));
    Assert.assertTrue(!result.getQuery().contains("as \""));
    System.out.println(result.getQuery());
}
Also used : HintRequest(com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest) AliasRemover(com.haulmont.cuba.gui.components.autocomplete.impl.AliasRemover) Test(org.junit.Test)

Example 8 with HintRequest

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

the class MacroProcessorTest method inlineFake_today.

@Test
public void inlineFake_today() {
    HintRequest request = processor.inlineFake("select p. from Player p where @today(p.joinDate)", 8);
    assertEquals("select p. from Player p where p.joinDate = :d ", request.getQuery());
    assertEquals(8, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Any), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @today(p.)", 42);
    assertEquals("select p.name from Player p where p. = :d ", request.getQuery());
    assertEquals(35, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Date), request.getExpectedTypes());
    request = processor.inlineFake("select p.name from Player p where @today(p.joinDate) and p.", 58);
    assertEquals("select p.name from Player p where p.joinDate = :d  and p.", request.getQuery());
    assertEquals(56, request.getPosition());
    assertEquals(EnumSet.of(InferredType.Any), request.getExpectedTypes());
}
Also used : HintRequest(com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest) Test(org.junit.Test)

Aggregations

HintRequest (com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest)8 Test (org.junit.Test)7 DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)1 DomainModelBuilder (com.haulmont.cuba.core.sys.jpql.DomainModelBuilder)1 AliasRemover (com.haulmont.cuba.gui.components.autocomplete.impl.AliasRemover)1 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)1 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)1 Option (com.haulmont.cuba.gui.components.autocomplete.impl.Option)1 ArrayList (java.util.ArrayList)1