@Test public void testMinimalSchema() throws Exception { Schema schema = new Schema(1, "org.greenrobot.testdao"); Entity addressEntity = schema.addEntity("Addresse"); Property idProperty = addressEntity.addIdProperty().getProperty(); addressEntity.addIntProperty("count").index(); addressEntity.addIntProperty("dummy").notNull(); assertEquals(1, schema.getEntities().size()); assertEquals(3, addressEntity.getProperties().size()); File outputDir = new File("build/test-out"); outputDir.mkdirs(); File daoFile = new File(outputDir, "org/greenrobot/testdao/" + addressEntity.getClassName() + "Dao.java"); daoFile.delete(); assertFalse(daoFile.exists()); new DaoGenerator().generateAll(schema, outputDir.getPath()); assertEquals("PRIMARY KEY", idProperty.getConstraints()); assertTrue(daoFile.toString(), daoFile.exists()); }
protected void createSimple(String name, boolean indexed) { Entity notNull = schema.addEntity(name); notNull.addIdProperty().notNull(); notNull.addBooleanProperty("simpleBoolean").notNull(); notNull.addByteProperty("simpleByte").notNull(); notNull.addShortProperty("simpleShort").notNull(); notNull.addIntProperty("simpleInt").notNull(); notNull.addLongProperty("simpleLong").notNull(); notNull.addFloatProperty("simpleFloat").notNull(); notNull.addDoubleProperty("simpleDouble").notNull(); PropertyBuilder simpleString = notNull.addStringProperty("simpleString"); if(indexed) { simpleString.index(); } notNull.addByteArrayProperty("simpleByteArray"); }
protected Entity createTest() { Entity testEntity = schema.addEntity("TestEntity"); testEntity.setJavaDoc("This entity is used by internal tests of greenDAO.\n" + "(This JavaDoc is defined in the generator project.)"); testEntity.setCodeBeforeClass("// This is another test comment, you could also apply annotations like this"); testEntity.addIdProperty().javaDocField("JavaDoc test field"); testEntity.addIntProperty("simpleInt").notNull().javaDocGetter("JavaDoc test getter"); testEntity.addIntProperty("simpleInteger").javaDocSetter("JavaDoc test setter"); testEntity.addStringProperty("simpleStringNotNull").notNull().javaDocGetterAndSetter("JavaDoc test getter and setter"); testEntity.addStringProperty("simpleString"); testEntity.addStringProperty("indexedString").index(); testEntity.addStringProperty("indexedStringAscUnique").indexAsc(null, true); testEntity.addDateProperty("simpleDate"); testEntity.addBooleanProperty("simpleBoolean"); testEntity.addByteArrayProperty("simpleByteArray"); return testEntity; }
protected void createIndexedString() { Entity entity = schema.addEntity("IndexedStringEntity"); entity.addIdProperty(); entity.addStringProperty("indexedString").index(); }