@Test public void EntitySerializer() throws Exception { new EntitySerializer(typeMappings, Collections.<String>emptyList()) .serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); }
@Override protected void introImports(CodeWriter writer, SerializerConfig config, EntityType model) throws IOException { super.introImports(writer, config, model);
super.outro(model, writer);
@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()) { 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()+" {")); } }
@Override protected void constructorsForVariables(CodeWriter writer, EntityType model) throws IOException { super.constructorsForVariables(writer, model); String localName = writer.getRawName(model); String genericName = writer.getGenericName(true, model); if (!localName.equals(genericName)) { writer.suppressWarnings("all"); } writer.beginConstructor(new Parameter("variable", Types.STRING), new Parameter("schema", Types.STRING), new Parameter("table", Types.STRING)); writer.line(SUPER,"(", writer.getClassConstant(localName) + COMMA + "forVariable(variable), schema, table);"); constructorContent(writer, model); writer.end(); }
super.serializeProperties(model, config, writer); super.serializeProperties(model, config, writer);
@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()) { 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()+" {")); } }
@Test public void Delegates() throws IOException{ SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); Delegate delegate = new Delegate(type, type, "test", Collections.<Parameter>emptyList(), Types.STRING); entityType.addDelegate(delegate); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("return Entity.test(this);")); }
@Test public void EntitySerializer2() throws Exception { new EntitySerializer(typeMappings,Collections.<String>emptyList()) .serialize(type, new SimpleSerializerConfig(true,true,true,true,""), new JavaWriter(writer)); }
@Test public void Correct_Imports() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "test.Entity", "test", "Entity",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("import test.Entity;")); assertTrue(writer.toString().contains("public class QEntity extends EntityPathBase<Entity> {")); }
@Test public void Delegates() throws IOException{ SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); Delegate delegate = new Delegate(type, type, "test", Collections.<Parameter>emptyList(), Types.STRING); entityType.addDelegate(delegate); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("return Entity.test(this);")); }
@Test public void No_Package() 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)); assertTrue(writer.toString().contains("public class QEntity extends BeanPath<Entity> {")); }
@Test public void Empty() throws IOException{ SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); // TODO : assertions }
@Test public void Correct_Superclass() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "java.util.Locale", "java.util", "Locale",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); //System.out.println(writer); assertTrue(writer.toString().contains("public class QLocale extends BeanPath<Locale> {")); }
@Test public void No_Package() 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)); assertTrue(writer.toString().contains("public class QEntity extends EntityPathBase<Entity> {")); }
@Test public void Correct_Superclass() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "java.util.Locale", "java.util", "Locale",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); // System.out.println(writer); assertTrue(writer.toString().contains("public class QLocale extends EntityPathBase<Locale> {")); }
@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")); }
@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)); // System.err.println(writer.toString()); assertTrue(writer.toString().contains("public class QEntitySerializerTest_Entity " + "extends EntityPathBase<EntitySerializerTest.Entity>")); }
@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))); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public final SimplePath<byte[]> bytes")); }
@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))); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public final SimplePath<byte[]> bytes")); }