Search in sources :

Example 31 with SimpleType

use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.

the class ProjectionSerializerTest method constructors.

@Test
public void constructors() throws IOException {
    Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
    EntityType type = new EntityType(typeModel);
    // constructor
    Parameter firstName = new Parameter("firstName", Types.STRING);
    Parameter lastName = new Parameter("lastName", Types.STRING);
    Parameter age = new Parameter("age", Types.INTEGER);
    type.addConstructor(new Constructor(Arrays.asList(firstName, lastName, age)));
    Writer writer = new StringWriter();
    ProjectionSerializer serializer = new DefaultProjectionSerializer(new JavaTypeMappings());
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    assertTrue(writer.toString().contains("Expression<String> firstName"));
    assertTrue(writer.toString().contains("Expression<String> lastName"));
    assertTrue(writer.toString().contains("Expression<Integer> age"));
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) SimpleType(com.querydsl.codegen.utils.model.SimpleType) StringWriter(java.io.StringWriter) Constructor(com.querydsl.codegen.utils.model.Constructor) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Parameter(com.querydsl.codegen.utils.model.Parameter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Test(org.junit.Test)

Example 32 with SimpleType

use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.

the class ProjectionSerializerTest method defaultGeneratedAnnotation.

@Test
public void defaultGeneratedAnnotation() throws IOException {
    Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
    EntityType type = new EntityType(typeModel);
    Writer writer = new StringWriter();
    ProjectionSerializer serializer = new DefaultProjectionSerializer(new JavaTypeMappings());
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    String generatedSource = writer.toString();
    assertThat(generatedSource, containsString(String.format("import %s;", GeneratedAnnotationResolver.resolveDefault().getName())));
    assertThat(generatedSource, containsString("@Generated(\"com.querydsl.codegen.DefaultProjectionSerializer\")\npublic class"));
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) SimpleType(com.querydsl.codegen.utils.model.SimpleType) StringWriter(java.io.StringWriter) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Matchers.containsString(org.hamcrest.Matchers.containsString) StringWriter(java.io.StringWriter) Writer(java.io.Writer) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Test(org.junit.Test)

Example 33 with SimpleType

use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.

the class PropertyTest method escapedName.

@Test
public void escapedName() {
    Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
    EntityType type = new EntityType(typeModel);
    Property property = new Property(type, "boolean", type, Collections.<String>emptyList());
    assertEquals("boolean$", property.getEscapedName());
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) SimpleType(com.querydsl.codegen.utils.model.SimpleType) Test(org.junit.Test)

Example 34 with SimpleType

use of com.querydsl.codegen.utils.model.SimpleType 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 35 with SimpleType

use of com.querydsl.codegen.utils.model.SimpleType in project querydsl by querydsl.

the class BeanSerializerTest method fullConstructor.

@Test
public void fullConstructor() 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.setAddFullConstructor(true);
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
// System.out.println(writer.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)

Aggregations

SimpleType (com.querydsl.codegen.utils.model.SimpleType)35 Type (com.querydsl.codegen.utils.model.Type)17 Test (org.junit.Test)17 ClassType (com.querydsl.codegen.utils.model.ClassType)15 JavaWriter (com.querydsl.codegen.utils.JavaWriter)8 StringWriter (java.io.StringWriter)6 EntityType (com.querydsl.codegen.EntityType)5 Parameter (com.querydsl.codegen.utils.model.Parameter)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 Before (org.junit.Before)5 File (java.io.File)3 Writer (java.io.Writer)3 Map (java.util.Map)3 BeanSerializer (com.querydsl.codegen.BeanSerializer)2 Configuration (com.querydsl.sql.Configuration)2 MetaDataExporter (com.querydsl.sql.codegen.MetaDataExporter)2 NumericMapping (com.querydsl.sql.codegen.support.NumericMapping)2 RenameMapping (com.querydsl.sql.codegen.support.RenameMapping)2 TypeMapping (com.querydsl.sql.codegen.support.TypeMapping)2 Connection (java.sql.Connection)2