Search in sources :

Example 26 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class RestFilterParserTest method testInvalidGroupType.

@Test
public void testInvalidGroupType() throws Exception {
    String data = readDataFromFile("data/invalidRestFilter3.json");
    MetaClass metaClass = metadata.getClass("test$TestEntity");
    thrown.expect(RestFilterParseException.class);
    thrown.expectMessage("Invalid conditions group type: INVALID_GROUP_TYPE");
    restFilterParser.parse(data, metaClass);
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) Test(org.junit.Test)

Example 27 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class RestFilterParserTest method testOrGroup.

@Test
public void testOrGroup() throws Exception {
    new StrictExpectations() {

        {
            RandomStringUtils.randomAlphabetic(anyInt);
            result = "stringParamName";
            RandomStringUtils.randomAlphabetic(anyInt);
            result = "intParamName";
            RandomStringUtils.randomAlphabetic(anyInt);
            result = "booleanParamName";
        }
    };
    String data = readDataFromFile("data/restFilter3.json");
    MetaClass metaClass = metadata.getClass("test$TestEntity");
    RestFilterParseResult parseResult = restFilterParser.parse(data, metaClass);
    String expectedJpqlWhere = "(({E}.stringField <> :stringParamName or " + "{E}.intField > :intParamName) and " + "{E}.booleanField = :booleanParamName)";
    assertEquals(expectedJpqlWhere, parseResult.getJpqlWhere());
    Map<String, Object> queryParameters = parseResult.getQueryParameters();
    assertEquals("stringValue", queryParameters.get("stringParamName"));
    assertEquals(100, queryParameters.get("intParamName"));
    assertEquals(true, queryParameters.get("booleanParamName"));
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) Test(org.junit.Test)

Example 28 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class RestFilterParserTest method testInvalidPropertyValue.

@Test
public void testInvalidPropertyValue() throws Exception {
    String data = readDataFromFile("data/invalidRestFilter2.json");
    MetaClass metaClass = metadata.getClass("test$TestEntity");
    thrown.expect(RestFilterParseException.class);
    thrown.expectMessage("Cannot parse property value: string");
    restFilterParser.parse(data, metaClass);
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) Test(org.junit.Test)

Example 29 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class RestFilterParserTest method testNotEmptyOperator.

@Test
public void testNotEmptyOperator() throws Exception {
    String data = readDataFromFile("data/restFilter7.json");
    MetaClass metaClass = metadata.getClass("test$TestEntity");
    RestFilterParseResult parseResult = restFilterParser.parse(data, metaClass);
    String expectedJpqlWhere = "({E}.stringField is not null)";
    assertEquals(expectedJpqlWhere, parseResult.getJpqlWhere());
    Map<String, Object> queryParameters = parseResult.getQueryParameters();
    assertEquals(0, queryParameters.size());
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) Test(org.junit.Test)

Example 30 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class RestFilterParserTest method testStartsWithOperator.

@Test
public void testStartsWithOperator() throws Exception {
    new StrictExpectations() {

        {
            RandomStringUtils.randomAlphabetic(anyInt);
            result = "paramName1";
        }
    };
    String data = readDataFromFile("data/restFilter6.json");
    MetaClass metaClass = metadata.getClass("test$TestEntity");
    RestFilterParseResult parseResult = restFilterParser.parse(data, metaClass);
    String expectedJpqlWhere = "({E}.stringField like :paramName1)";
    assertEquals(expectedJpqlWhere, parseResult.getJpqlWhere());
    Map<String, Object> queryParameters = parseResult.getQueryParameters();
    assertEquals("(?i)AAA%", queryParameters.get("paramName1"));
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) Test(org.junit.Test)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)302 MetaProperty (com.haulmont.chile.core.model.MetaProperty)103 Entity (com.haulmont.cuba.core.entity.Entity)54 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)36 Nullable (javax.annotation.Nullable)25 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)24 Element (org.dom4j.Element)21 java.util (java.util)18 Inject (javax.inject.Inject)17 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)16 Test (org.junit.Test)15 EntityManager (com.haulmont.cuba.core.EntityManager)14 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)14 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)13 Metadata (com.haulmont.cuba.core.global.Metadata)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)12 Collectors (java.util.stream.Collectors)11 Range (com.haulmont.chile.core.model.Range)10