@Before public void setUp() { entityModel = new EntityType(Types.OBJECT); //entityModel.addAnnotation(new TableImpl("OBJECT")); entityModel.getData().put("table", "OBJECT"); }
@Before public void setUp() { entityModel = new EntityType(Types.OBJECT); //entityModel.addAnnotation(new TableImpl("OBJECT")); entityModel.getData().put("table", "OBJECT"); }
@Before public void setUp() { entityModel = new EntityType(Types.OBJECT); //entityModel.addAnnotation(new TableImpl("OBJECT")); entityModel.getData().put("table", "OBJECT"); }
@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 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 EscapedName() { Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.mysema.query.DomainClass", "com.mysema.query", "DomainClass", false,false); EntityType type = new EntityType(typeModel); Property property = new Property(type, "boolean", type, Collections.<String>emptyList()); assertEquals("boolean$", property.getEscapedName()); }
@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 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 UncapSimpleName_Escaped3() { ClassType typeModel = new ClassType(TypeCategory.ENTITY, Void.class); EntityType entityModel = new EntityType(typeModel); assertEquals("void$", entityModel.getModifiedSimpleName()); }
@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 SuperType() throws IOException{ EntityType superType = new EntityType(new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2",false,false)); SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type, Collections.singleton(new Supertype(superType, superType))); typeMappings.register(superType, queryTypeFactory.create(superType)); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public final QEntity2 _super = new QEntity2(this);")); }
@Test public void SuperType() throws IOException{ EntityType superType = new EntityType(new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2",false,false)); SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type, Collections.singleton(new Supertype(superType, superType))); typeMappings.register(superType, queryTypeFactory.create(superType)); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public final QEntity2 _super = new QEntity2(this);")); }
@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 Equals_And_HashCode() { Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.mysema.query.DomainClass", "com.mysema.query", "DomainClass", false,false); EntityType type = new EntityType(typeModel); Property p1 = new Property(type, "property", type, Collections.<String>emptyList()); Property p2 = new Property(type, "property", type, Collections.<String>emptyList()); assertEquals(p1, p1); assertEquals(p1, p2); assertEquals(p1.hashCode(), p2.hashCode()); }
@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 UncapSimpleName_Escaped2() { ClassType typeModel = new ClassType(TypeCategory.ENTITY, Object.class); EntityType entityModel = new EntityType(typeModel); assertEquals("object", entityModel.getModifiedSimpleName()); entityModel.addProperty(new Property(entityModel, "OBJECT", "object", typeModel, Collections.<String> emptyList(), false)); assertEquals("object1", entityModel.getModifiedSimpleName()); }
@Test public void GetPathType_Of_InnerClass() { TypeMappings typeMappings = new JavaTypeMappings(); EntityType model = new EntityType(new ClassType(TypeMappingsTest.class)); EntityType type = new EntityType(new ClassType(Entity.class)); typeMappings.register(type, new QueryTypeFactoryImpl("Q","","").create(type)); Type pathType = typeMappings.getPathType(type, model, false); assertEquals("QTypeMappingsTest_Entity", pathType.getSimpleName()); }
@Test public void UncapSimpleName_Escaped() { ClassType typeModel = new ClassType(TypeCategory.ENTITY, Object.class); EntityType entityModel = new EntityType(typeModel); assertEquals("object", entityModel.getModifiedSimpleName()); entityModel.addProperty(new Property(entityModel, "object", typeModel)); assertEquals("object1", entityModel.getModifiedSimpleName()); }