Search in sources :

Example 16 with JavaWriter

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

Example 17 with JavaWriter

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

Example 18 with JavaWriter

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

Example 19 with JavaWriter

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

Example 20 with JavaWriter

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