Search in sources :

Example 31 with JavaWriter

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()"));
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Matchers.containsString(org.hamcrest.Matchers.containsString) ClassType(com.querydsl.codegen.utils.model.ClassType) Test(org.junit.Test)

Example 32 with JavaWriter

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() + " {"));
    }
}
Also used : StringWriter(java.io.StringWriter) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Matchers.containsString(org.hamcrest.Matchers.containsString) EnumMap(java.util.EnumMap) EnumMap(java.util.EnumMap) Map(java.util.Map) Test(org.junit.Test)

Example 33 with JavaWriter

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

Example 34 with JavaWriter

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

Example 35 with JavaWriter

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());
}
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