@Test public void Capitalization() throws IOException{ // property type.addProperty(new Property(type, "cId", type)); BeanSerializer serializer = new BeanSerializer(); serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public DomainClass getcId() {")); }
@Test public void Interfaces2() throws IOException { BeanSerializer serializer = new BeanSerializer(); serializer.addInterface(Serializable.class); serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public class DomainClass implements Serializable {")); }
public void export(Session session, File targetFolder) throws IOException { List<EntityType> entityTypes = new ArrayList<EntityType>(); // collect entity types for (OWLClass owlClass : session.findInstances(OWLClass.class)) { if (owlClass.getId().isURI()) { EntityType entityType; if (oneOfAsEnum && !owlClass.getOneOf().isEmpty()) { entityType = createEnumType(owlClass); } else { entityType = createBeanType(owlClass); } entityTypes.add(entityType); } } // serialize BeanSerializer beanSerializer = new BeanSerializer(); beanSerializer.setPrintSupertype(true); for (EntityType entityType : entityTypes) { File folder = new File(targetFolder, entityType.getPackageName().replace('.', '/')); folder.mkdirs(); File javaFile = new File(folder, entityType.getSimpleName() + ".java"); javaFile.createNewFile(); Writer writer = new OutputStreamWriter(new FileOutputStream(javaFile), "UTF-8"); try { beanSerializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); } finally { writer.close(); } } }
BeanSerializer serializer = new BeanSerializer(); if (beanInterfaces != null) { for (String iface : beanInterfaces) { int sepIndex = iface.lastIndexOf('.'); if (sepIndex < 0) { serializer.addInterface(new SimpleType(iface)); } else { String packageName = iface.substring(0, sepIndex); String simpleName = iface.substring(sepIndex + 1); serializer.addInterface(new SimpleType(iface, packageName, simpleName)); serializer.setAddFullConstructor(beanAddFullConstructor); serializer.setAddToString(beanAddToString); serializer.setPrintSupertype(beanPrintSupertype); exporter.setBeanSerializer(serializer);
@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()")); }
@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()); }
@Test public void Minimal_Configuration_with_Bean_prefix() throws SQLException{ MetaDataExporter exporter = new MetaDataExporter(); exporter.setSchemaPattern("PUBLIC"); exporter.setPackageName("test"); exporter.setNamePrefix(""); exporter.setBeanPrefix("Bean"); exporter.setBeanSerializer(new BeanSerializer()); exporter.setTargetFolder(new File("target/a")); exporter.export(metadata); assertTrue(new File("target/a/test/DateTest.java").exists()); assertTrue(new File("target/a/test/BeanDateTest.java").exists()); }
@Test public void Minimal_Configuration_with_Bean_suffix() throws SQLException{ MetaDataExporter exporter = new MetaDataExporter(); exporter.setSchemaPattern("PUBLIC"); exporter.setPackageName("test"); exporter.setNamePrefix(""); exporter.setBeanSuffix("Bean"); exporter.setBeanSerializer(new BeanSerializer()); exporter.setTargetFolder(new File("target/b")); exporter.export(metadata); assertTrue(new File("target/b/test/DateTest.java").exists()); assertTrue(new File("target/b/test/DateTestBean.java").exists()); }
@Test public void Annotations() throws IOException{ type.addAnnotation(new QueryEntityImpl()); BeanSerializer serializer = new BeanSerializer(); serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); String str = writer.toString(); assertTrue(str.contains("import com.mysema.query.annotations.QueryEntity;")); assertTrue(str.contains("@QueryEntity")); }
@Test public void Interfaces() throws IOException { BeanSerializer serializer = new BeanSerializer(); serializer.addInterface(new ClassType(Serializable.class)); serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public class DomainClass implements Serializable {")); }
@Test public void Explicit_Configuration() throws SQLException{ MetaDataExporter exporter = new MetaDataExporter(); exporter.setSchemaPattern("PUBLIC"); exporter.setNamePrefix("Q"); exporter.setPackageName("test"); exporter.setTargetFolder(new File("target/7")); exporter.setNamingStrategy(new DefaultNamingStrategy()); exporter.setBeanSerializer(new BeanSerializer()); exporter.setBeanPackageName("test2"); exporter.export(metadata); assertTrue(new File("target/7/test/QDateTest.java").exists()); assertTrue(new File("target/7/test2/DateTest.java").exists()); }
@Test public void Annotated_Property() throws IOException{ Property property = new Property(type, "entityField", type); property.addAnnotation(new QueryEntityImpl()); type.addProperty(property); BeanSerializer serializer = new BeanSerializer(); serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); String str = writer.toString(); assertTrue(str.contains("import com.mysema.query.annotations.QueryEntity;")); assertTrue(str.contains("@QueryEntity")); }
@Test public void Annotated_Property_Not_Serialized() throws IOException{ Property property = new Property(type, "entityField", type); property.addAnnotation(new QueryEntityImpl()); type.addProperty(property); BeanSerializer serializer = new BeanSerializer(false); serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); String str = writer.toString(); assertFalse(str.contains("import com.mysema.query.annotations.QueryEntity;")); assertFalse(str.contains("@QueryEntity")); }
BeanSerializer serializer = new BeanSerializer(); serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); String str = writer.toString();