mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-19 21:00:53 +08:00
47 lines
1.5 KiB
Java
47 lines
1.5 KiB
Java
package com.mysema.query.sql;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import org.junit.Test;
|
|
|
|
import com.mysema.query.sql.domain.Employee;
|
|
import com.mysema.query.sql.domain.QEmployee;
|
|
import com.mysema.query.types.FactoryExpression;
|
|
import com.mysema.query.types.QBean;
|
|
|
|
public class QBeanTest {
|
|
|
|
private final QEmployee e = new QEmployee("e");
|
|
|
|
@Test
|
|
public void Direct_to_Managed_type(){
|
|
FactoryExpression<Employee> expr = new QBean<Employee>(Employee.class, e.superiorId);
|
|
Employee e = expr.newInstance(3);
|
|
assertEquals(Integer.valueOf(3), e.getSuperiorId());
|
|
}
|
|
|
|
@Test
|
|
public void Direct_to_Custom_type(){
|
|
FactoryExpression<Employee> expr = new QBean<Employee>(Employee.class, e.firstname, e.lastname);
|
|
Employee e = expr.newInstance("John","Smith");
|
|
assertEquals("John", e.getFirstname());
|
|
assertEquals("Smith", e.getLastname());
|
|
}
|
|
|
|
@Test
|
|
public void Alias_to_Managed_type(){
|
|
FactoryExpression<Employee> expr = new QBean<Employee>(Employee.class, e.superiorId.as("id"));
|
|
Employee e = expr.newInstance(3);
|
|
assertEquals(3, e.getId().intValue());
|
|
}
|
|
|
|
@Test
|
|
public void Alias_to_Custom_type(){
|
|
FactoryExpression<Employee> expr = new QBean<Employee>(Employee.class, e.firstname.as("lastname"), e.lastname.as("firstname"));
|
|
Employee e = expr.newInstance("John","Smith");
|
|
assertEquals("Smith", e.getFirstname());
|
|
assertEquals("John", e.getLastname());
|
|
}
|
|
|
|
}
|