added tests

This commit is contained in:
Timo Westkämper 2010-10-12 20:20:41 +00:00
parent 9e10586a2e
commit bd2e87f0d9
3 changed files with 106 additions and 0 deletions

View File

@ -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;

View File

@ -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.<String>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
}
}

View File

@ -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<byte[]> 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
}
}