use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.
the class EmbeddableSerializerTest method include.
@Test
public void include() throws IOException {
SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity", false, false);
EntityType entityType = new EntityType(type);
entityType.addProperty(new Property(entityType, "b", new ClassType(TypeCategory.BOOLEAN, Boolean.class)));
entityType.addProperty(new Property(entityType, "c", new ClassType(TypeCategory.COMPARABLE, String.class)));
// entityType.addProperty(new Property(entityType, "cu", new ClassType(TypeCategory.CUSTOM, PropertyType.class)));
entityType.addProperty(new Property(entityType, "d", new ClassType(TypeCategory.DATE, Date.class)));
entityType.addProperty(new Property(entityType, "e", new ClassType(TypeCategory.ENUM, PropertyType.class)));
entityType.addProperty(new Property(entityType, "dt", new ClassType(TypeCategory.DATETIME, Date.class)));
entityType.addProperty(new Property(entityType, "i", new ClassType(TypeCategory.NUMERIC, Integer.class)));
entityType.addProperty(new Property(entityType, "s", new ClassType(TypeCategory.STRING, String.class)));
entityType.addProperty(new Property(entityType, "t", new ClassType(TypeCategory.TIME, Time.class)));
EntityType subType = new EntityType(new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2", false, false));
subType.include(new Supertype(type, entityType));
typeMappings.register(entityType, queryTypeFactory.create(entityType));
typeMappings.register(subType, queryTypeFactory.create(subType));
serializer.serialize(subType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
CompileUtils.assertCompiles("QEntity2", writer.toString());
}
use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.
the class EmbeddableSerializerTest method primitive_array.
@Test
public void primitive_array() throws IOException {
SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity", false, false);
EntityType entityType = new EntityType(type);
entityType.addProperty(new Property(entityType, "bytes", new ClassType(byte[].class)));
typeMappings.register(entityType, queryTypeFactory.create(entityType));
serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
assertTrue(writer.toString().contains("public final SimplePath<byte[]> bytes"));
CompileUtils.assertCompiles("QEntity", writer.toString());
}
use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.
the class EntitySerializerTest method original_category.
@Test
public void original_category() 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()) {
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(writer));
assertTrue(entry.toString(), writer.toString().contains("public class QEntity extends " + entry.getValue() + " {"));
}
}
use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.
the class EntitySerializerTest method different_package.
@Test
public void different_package() throws IOException {
queryTypeFactory = new QueryTypeFactoryImpl("Q", "", ".gen");
EntityType entityType = new EntityType(new ClassType(Entity.class));
typeMappings.register(entityType, queryTypeFactory.create(entityType));
serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
assertTrue(writer.toString().contains("public class QEntitySerializerTest_Entity " + "extends EntityPathBase<EntitySerializerTest.Entity>"));
CompileUtils.assertCompiles("QEntitySerializerTest_Entity", writer.toString());
}
use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.
the class EntitySerializerTest method customGeneratedAnnotation.
@Test
public void customGeneratedAnnotation() throws IOException {
EntityType entityType = new EntityType(new ClassType(Entity.class));
typeMappings.register(entityType, queryTypeFactory.create(entityType));
new DefaultEntitySerializer(typeMappings, Collections.<String>emptySet(), com.querydsl.core.annotations.Generated.class).serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
String generatedSourceCode = writer.toString();
assertTrue(generatedSourceCode.contains("import " + com.querydsl.core.annotations.Generated.class.getName() + ";"));
assertTrue(generatedSourceCode.contains("@" + com.querydsl.core.annotations.Generated.class.getSimpleName() + "(\"com.querydsl.codegen.DefaultEntitySerializer\")\npublic class"));
CompileUtils.assertCompiles("QEntitySerializerTest_Entity", generatedSourceCode);
}
Aggregations