Search in sources :

Example 41 with JavaWriter

use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.

the class EntitySerializerTest method defaultGeneratedAnnotation.

@Test
public void defaultGeneratedAnnotation() throws IOException {
    EntityType entityType = new EntityType(new ClassType(Entity.class));
    typeMappings.register(entityType, queryTypeFactory.create(entityType));
    serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    String generatedSourceCode = writer.toString();
    assertTrue(generatedSourceCode.contains(String.format("import %s;", GeneratedAnnotationResolver.resolveDefault().getName())));
    assertTrue(generatedSourceCode.contains("@Generated(\"com.querydsl.codegen.DefaultEntitySerializer\")\npublic class"));
    CompileUtils.assertCompiles("QEntitySerializerTest_Entity", generatedSourceCode);
}
Also used : JavaWriter(com.querydsl.codegen.utils.JavaWriter) Test(org.junit.Test)

Example 42 with JavaWriter

use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.

the class EntitySerializerTest method javadocs_for_innerClass.

@Test
public void javadocs_for_innerClass() throws IOException {
    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("QEntitySerializerTest_Entity is a Querydsl query type for Entity"));
    CompileUtils.assertCompiles("QEntitySerializerTest_Entity", writer.toString());
}
Also used : JavaWriter(com.querydsl.codegen.utils.JavaWriter) Test(org.junit.Test)

Example 43 with JavaWriter

use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.

the class EntitySerializerTest 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());
}
Also used : JavaWriter(com.querydsl.codegen.utils.JavaWriter) Test(org.junit.Test)

Example 44 with JavaWriter

use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.

the class EntitySerializerTest 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(subType, queryTypeFactory.create(subType));
    serializer.serialize(subType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    CompileUtils.assertCompiles("QEntity2", writer.toString());
}
Also used : JavaWriter(com.querydsl.codegen.utils.JavaWriter) Test(org.junit.Test)

Example 45 with JavaWriter

use of com.querydsl.codegen.utils.JavaWriter in project querydsl by querydsl.

the class EntitySerializerTest method properties.

@Test
public void properties() 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)));
    typeMappings.register(entityType, queryTypeFactory.create(entityType));
    serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    CompileUtils.assertCompiles("QEntity", writer.toString());
}
Also used : JavaWriter(com.querydsl.codegen.utils.JavaWriter) Test(org.junit.Test)

Aggregations

JavaWriter (com.querydsl.codegen.utils.JavaWriter)45 Test (org.junit.Test)41 Matchers.containsString (org.hamcrest.Matchers.containsString)13 SimpleType (com.querydsl.codegen.utils.model.SimpleType)8 ClassType (com.querydsl.codegen.utils.model.ClassType)6 Writer (java.io.Writer)6 StringWriter (java.io.StringWriter)5 Type (com.querydsl.codegen.utils.model.Type)4 CodeWriter (com.querydsl.codegen.utils.CodeWriter)3 ScalaWriter (com.querydsl.codegen.utils.ScalaWriter)2 File (java.io.File)2 OutputStreamWriter (java.io.OutputStreamWriter)2 EnumMap (java.util.EnumMap)2 Map (java.util.Map)2 Property (com.querydsl.codegen.Property)1 SimpleCompiler (com.querydsl.codegen.utils.SimpleCompiler)1 Constructor (com.querydsl.codegen.utils.model.Constructor)1 Parameter (com.querydsl.codegen.utils.model.Parameter)1 ColumnImpl (com.querydsl.sql.ColumnImpl)1 PrimaryKeyData (com.querydsl.sql.codegen.support.PrimaryKeyData)1