use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.
the class ProjectionSerializerTest method constructors.
@Test
public void constructors() throws IOException {
Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
EntityType type = new EntityType(typeModel);
// constructor
Parameter firstName = new Parameter("firstName", Types.STRING);
Parameter lastName = new Parameter("lastName", Types.STRING);
Parameter age = new Parameter("age", Types.INTEGER);
type.addConstructor(new Constructor(Arrays.asList(firstName, lastName, age)));
Writer writer = new StringWriter();
ProjectionSerializer serializer = new DefaultProjectionSerializer(new JavaTypeMappings());
serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
assertTrue(writer.toString().contains("Expression<String> firstName"));
assertTrue(writer.toString().contains("Expression<String> lastName"));
assertTrue(writer.toString().contains("Expression<Integer> age"));
}
use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.
the class ProjectionSerializerTest method defaultGeneratedAnnotation.
@Test
public void defaultGeneratedAnnotation() throws IOException {
Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
EntityType type = new EntityType(typeModel);
Writer writer = new StringWriter();
ProjectionSerializer serializer = new DefaultProjectionSerializer(new JavaTypeMappings());
serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
String generatedSource = writer.toString();
assertThat(generatedSource, containsString(String.format("import %s;", GeneratedAnnotationResolver.resolveDefault().getName())));
assertThat(generatedSource, containsString("@Generated(\"com.querydsl.codegen.DefaultProjectionSerializer\")\npublic class"));
}
use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.
the class PropertyTest method escapedName.
@Test
public void escapedName() {
Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
EntityType type = new EntityType(typeModel);
Property property = new Property(type, "boolean", type, Collections.<String>emptyList());
assertEquals("boolean$", property.getEscapedName());
}
use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.
the class BeanSerializerTest method toString_.
@Test
public void toString_() throws IOException {
// property
type.addProperty(new Property(type, "entityField", type));
type.addProperty(new Property(type, "collection", new SimpleType(Types.COLLECTION, typeModel)));
type.addProperty(new Property(type, "listField", new SimpleType(Types.LIST, typeModel)));
type.addProperty(new Property(type, "setField", new SimpleType(Types.SET, typeModel)));
type.addProperty(new Property(type, "arrayField", new ClassType(TypeCategory.ARRAY, String[].class)));
type.addProperty(new Property(type, "mapField", new SimpleType(Types.MAP, typeModel, typeModel)));
BeanSerializer serializer = new BeanSerializer();
serializer.setAddToString(true);
serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
assertTrue(String.valueOf(writer).contains(" @Override\n" + " public String toString()"));
}
use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.
the class BeanSerializerTest method fullConstructor.
@Test
public void fullConstructor() throws IOException {
// property
type.addProperty(new Property(type, "entityField", type));
type.addProperty(new Property(type, "collection", new SimpleType(Types.COLLECTION, typeModel)));
type.addProperty(new Property(type, "listField", new SimpleType(Types.LIST, typeModel)));
type.addProperty(new Property(type, "setField", new SimpleType(Types.SET, typeModel)));
type.addProperty(new Property(type, "arrayField", new ClassType(TypeCategory.ARRAY, String[].class)));
type.addProperty(new Property(type, "mapField", new SimpleType(Types.MAP, typeModel, typeModel)));
BeanSerializer serializer = new BeanSerializer();
serializer.setAddFullConstructor(true);
serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
// System.out.println(writer.toString());
}
Aggregations