@Test public void testGenerateLogableDomain() { Domain dom = MVCoreFactoryImpl.eINSTANCE.createDomain(); dom.setName("Person"); dom.setLoggable("true"); Attribute attr = MVCoreFactoryImpl.eINSTANCE.createAttribute(); attr.setName("name"); attr.setType(getDataTypeFor("EString")); dom.getAttributes().add(attr); GrailsGenerator gen = new GrailsGenerator(); String s = gen.buildEDomainClass(dom, "test"); assertTrue(s.contains("static loggable = true")); }
@Test public void testGenerateUniqueConstraintDomainAttribute() { Domain dom = MVCoreFactoryImpl.eINSTANCE.createDomain(); dom.setName("Person"); dom.setLoggable("true"); Attribute attr = MVCoreFactoryImpl.eINSTANCE.createAttribute(); attr.setName("age"); attr.setType(getDataTypeFor("int")); attr.setUnique(true); dom.getAttributes().add(attr); GrailsGenerator gen = new GrailsGenerator(); String s = gen.buildEDomainClass(dom, "test"); assertTrue(s.contains("age(unique: true)")); }
@Test public void testGenerateCustomConstraintDomainAttribute() { Domain dom = MVCoreFactoryImpl.eINSTANCE.createDomain(); dom.setName("Person"); dom.setLoggable("true"); Attribute attr = MVCoreFactoryImpl.eINSTANCE.createAttribute(); attr.setName("age"); attr.setType(getDataTypeFor("int")); dom.getAttributes().add(attr); Constraint constr = MVCoreFactoryImpl.eINSTANCE.createConstraint(); constr.setType(ConstraintType.CUSTOM_CONSTRAINT); constr.setValue("range:0..99"); attr.getConstraints().add(constr); GrailsGenerator gen = new GrailsGenerator(); String s = gen.buildEDomainClass(dom, "test"); assertTrue(s.contains("age(range:0..99)")); }