Search in sources :

Example 1 with AliasRemover

use of com.haulmont.cuba.gui.components.autocomplete.impl.AliasRemover 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)

Aggregations

AliasRemover (com.haulmont.cuba.gui.components.autocomplete.impl.AliasRemover)1 HintRequest (com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest)1 Test (org.junit.Test)1