Search in sources :

Example 1 with Property

use of org.apache.cayenne.exp.property.Property in project cayenne by apache.

the class CustomColumnSetExtractorTest method testExtractWithoutPrefix.

@Test
public void testExtractWithoutPrefix() {
    DbEntity mockDbEntity = createMockDbEntity("mock");
    TranslatableQueryWrapper wrapper = new MockQueryWrapperBuilder().withNeedsResultSetMapping(true).withMetaData(new MockQueryMetadataBuilder().withDbEntity(mockDbEntity).build()).build();
    TranslatorContext context = new MockTranslatorContext(wrapper);
    DataMap dataMap = new DataMap();
    dataMap.addDbEntity(mockDbEntity);
    ObjEntity entity = new ObjEntity();
    entity.setName("mock");
    entity.setDataMap(dataMap);
    entity.setDbEntity(mockDbEntity);
    ObjAttribute attribute = new ObjAttribute();
    attribute.setName("not_name");
    attribute.setDbAttributePath("name");
    attribute.setType("my.type");
    entity.addAttribute(attribute);
    dataMap.addObjEntity(entity);
    EntityResolver resolver = new EntityResolver();
    resolver.addDataMap(dataMap);
    BaseProperty<?> property0 = PropertyFactory.createBase(ExpressionFactory.dbPathExp("name"), String.class);
    Collection<Property<?>> properties = Collections.singleton(property0);
    CustomColumnSetExtractor extractor = new CustomColumnSetExtractor(context, properties);
    extractor.extract();
    assertEquals(1, context.getResultNodeList().size());
    ResultNodeDescriptor descriptor0 = context.getResultNodeList().get(0);
    assertSame(property0, descriptor0.getProperty());
    assertNotNull(descriptor0.getNode());
    assertThat(descriptor0.getNode(), instanceOf(ColumnNode.class));
    assertFalse(descriptor0.isAggregate());
    assertTrue(descriptor0.isInDataRow());
    assertNotNull(descriptor0.getDbAttribute());
    assertNull(descriptor0.getDataRowKey());
    assertEquals(Types.VARBINARY, descriptor0.getJdbcType());
    assertEquals("java.lang.String", descriptor0.getJavaType());
}
Also used : ObjAttribute(org.apache.cayenne.map.ObjAttribute) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) EntityResolver(org.apache.cayenne.map.EntityResolver) DataMap(org.apache.cayenne.map.DataMap) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) BaseProperty(org.apache.cayenne.exp.property.BaseProperty) Property(org.apache.cayenne.exp.property.Property) Test(org.junit.Test)

Aggregations

ColumnNode (org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode)1 BaseProperty (org.apache.cayenne.exp.property.BaseProperty)1 Property (org.apache.cayenne.exp.property.Property)1 DataMap (org.apache.cayenne.map.DataMap)1 DbEntity (org.apache.cayenne.map.DbEntity)1 EntityResolver (org.apache.cayenne.map.EntityResolver)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 Test (org.junit.Test)1