From bd2e87f0d9f48acd30e5e4fdd45d8c3d079361f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Tue, 12 Oct 2010 20:20:41 +0000 Subject: [PATCH] added tests --- .../com/mysema/query/codegen/Supertype.java | 5 ++ .../codegen/EmbeddableSerializerTest.java | 49 +++++++++++++++++ .../query/codegen/EntitySerializerTest.java | 52 +++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 querydsl-core/src/test/java/com/mysema/query/codegen/EmbeddableSerializerTest.java diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/Supertype.java b/querydsl-core/src/main/java/com/mysema/query/codegen/Supertype.java index a0d8fe1d6..ad3a852e7 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/Supertype.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/Supertype.java @@ -20,6 +20,11 @@ public class Supertype { public Supertype(Type type) { this.type = type; } + + public Supertype(Type type, EntityType entityType) { + this.type = type; + this.entityType = entityType; + } public EntityType getEntityType() { return entityType; diff --git a/querydsl-core/src/test/java/com/mysema/query/codegen/EmbeddableSerializerTest.java b/querydsl-core/src/test/java/com/mysema/query/codegen/EmbeddableSerializerTest.java new file mode 100644 index 000000000..1169b80c5 --- /dev/null +++ b/querydsl-core/src/test/java/com/mysema/query/codegen/EmbeddableSerializerTest.java @@ -0,0 +1,49 @@ +package com.mysema.query.codegen; + +import java.io.IOException; +import java.io.StringWriter; +import java.sql.Time; +import java.util.Collections; +import java.util.Date; + +import org.junit.Test; + +import com.mysema.codegen.JavaWriter; +import com.mysema.codegen.model.ClassType; +import com.mysema.codegen.model.SimpleType; +import com.mysema.codegen.model.TypeCategory; +import com.mysema.query.annotations.PropertyType; + +public class EmbeddableSerializerTest { + + EntitySerializer serializer = new EmbeddableSerializer(new TypeMappings(), Collections.emptySet()); + StringWriter writer = new StringWriter(); + + @Test + public void Properties() throws IOException{ + SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); + EntityType entityType = new EntityType("Q",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))); + + serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); + // TODO : assertions + } + + @Test + public void Empty() throws IOException{ + SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); + EntityType entityType = new EntityType("Q",type); + + serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); + // TODO : assertions + } + +} diff --git a/querydsl-core/src/test/java/com/mysema/query/codegen/EntitySerializerTest.java b/querydsl-core/src/test/java/com/mysema/query/codegen/EntitySerializerTest.java index 24fc94e0f..b8a42cc9b 100644 --- a/querydsl-core/src/test/java/com/mysema/query/codegen/EntitySerializerTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/codegen/EntitySerializerTest.java @@ -9,7 +9,9 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.StringWriter; +import java.sql.Time; import java.util.Collections; +import java.util.Date; import org.junit.Test; @@ -17,6 +19,7 @@ import com.mysema.codegen.JavaWriter; import com.mysema.codegen.model.ClassType; import com.mysema.codegen.model.SimpleType; import com.mysema.codegen.model.TypeCategory; +import com.mysema.query.annotations.PropertyType; public class EntitySerializerTest { @@ -48,5 +51,54 @@ public class EntitySerializerTest { serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public final SimplePath bytes")); } + + @Test + public void Include() throws IOException{ + SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); + EntityType entityType = new EntityType("Q",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("Q",new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2",false,false)); + subType.include(new Supertype(type,entityType)); + + serializer.serialize(subType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); + // TODO : assertions + } + + @Test + public void Properties() throws IOException{ + SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); + EntityType entityType = new EntityType("Q",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))); + + serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); + // TODO : assertions + } + + @Test + public void SuperType() throws IOException{ + EntityType superType = new EntityType("Q",new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2",false,false)); + SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); + EntityType entityType = new EntityType("Q",type, Collections.singleton(new Supertype(superType, superType))); + + serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); + // TODO : assertions + } }