use of com.querydsl.codegen.utils.JavaWriter 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.JavaWriter in project querydsl by querydsl.
the class EmbeddableSerializerTest method originalCategory.
@Test
public void originalCategory() throws IOException {
Map<TypeCategory, String> categoryToSuperClass = new EnumMap<TypeCategory, String>(TypeCategory.class);
categoryToSuperClass.put(TypeCategory.COMPARABLE, "ComparablePath<Entity>");
categoryToSuperClass.put(TypeCategory.ENUM, "EnumPath<Entity>");
categoryToSuperClass.put(TypeCategory.DATE, "DatePath<Entity>");
categoryToSuperClass.put(TypeCategory.DATETIME, "DateTimePath<Entity>");
categoryToSuperClass.put(TypeCategory.TIME, "TimePath<Entity>");
categoryToSuperClass.put(TypeCategory.NUMERIC, "NumberPath<Entity>");
categoryToSuperClass.put(TypeCategory.STRING, "StringPath");
categoryToSuperClass.put(TypeCategory.BOOLEAN, "BooleanPath");
for (Map.Entry<TypeCategory, String> entry : categoryToSuperClass.entrySet()) {
StringWriter w = new StringWriter();
SimpleType type = new SimpleType(entry.getKey(), "Entity", "", "Entity", false, false);
EntityType entityType = new EntityType(type);
typeMappings.register(entityType, queryTypeFactory.create(entityType));
serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(w));
assertTrue(entry.getValue() + " is missing from " + w, w.toString().contains("public class QEntity extends " + entry.getValue() + " {"));
}
}
use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.
the class EmbeddableSerializerTest method empty.
@Test
public void empty() throws IOException {
SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity", false, false);
EntityType entityType = new EntityType(type);
typeMappings.register(entityType, queryTypeFactory.create(entityType));
serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
CompileUtils.assertCompiles("QEntity", writer.toString());
}
use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.
the class EmbeddableSerializerTest method customGeneratedAnnotation.
@Test
public void customGeneratedAnnotation() throws IOException {
SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity", false, false);
EntityType entityType = new EntityType(type);
typeMappings.register(entityType, queryTypeFactory.create(entityType));
new DefaultEmbeddableSerializer(typeMappings, Collections.<String>emptySet(), com.querydsl.core.annotations.Generated.class).serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
String generatedSourceCode = writer.toString();
assertThat(generatedSourceCode, containsString("@Generated(\"com.querydsl.codegen.DefaultEmbeddableSerializer\")\npublic class"));
CompileUtils.assertCompiles("QEntity", generatedSourceCode);
}
use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.
the class EmbeddableSerializerTest method superType.
@Test
public void superType() throws IOException {
EntityType superType = new EntityType(new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2", false, false));
SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity", false, false);
EntityType entityType = new EntityType(type, Collections.singleton(new Supertype(superType, superType)));
typeMappings.register(superType, queryTypeFactory.create(superType));
typeMappings.register(entityType, queryTypeFactory.create(entityType));
serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
assertTrue(writer.toString().contains("public final QEntity2 _super = new QEntity2(this);"));
// CompileUtils.assertCompiles("QEntity", writer.toString());
}
Aggregations