コード例 #1
0
  @Test
  public void testGenerateDomainCustomConstraintDomain() {
    Domain dom = MVCoreFactoryImpl.eINSTANCE.createDomain();
    dom.setName("Person");
    Attribute attr = MVCoreFactoryImpl.eINSTANCE.createAttribute();
    attr.setName("age");
    attr.setType(getDataTypeFor("int"));
    dom.getAttributes().add(attr);

    Attribute attr2 = MVCoreFactoryImpl.eINSTANCE.createAttribute();
    attr2.setName("shoesize");
    attr2.setType(getDataTypeFor("int"));
    dom.getAttributes().add(attr2);

    Constraint constr = MVCoreFactoryImpl.eINSTANCE.createConstraint();
    constr.setType(ConstraintType.CUSTOM_CONSTRAINT);
    constr.setValue("age(validator: {shoesize + age < 100})");

    dom.getConstraints().add(constr);

    GrailsGenerator gen = new GrailsGenerator();

    String s = gen.buildEDomainClass(dom, "test");

    assertTrue(s.contains("age(validator: {shoesize + age < 100})"));
  }
コード例 #2
0
  @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"));
  }
コード例 #3
0
  @Test
  public void testGenerateNotNullConstraintDomainAttribute() {
    Domain dom = MVCoreFactoryImpl.eINSTANCE.createDomain();
    dom.setName("Person");
    Attribute attr = MVCoreFactoryImpl.eINSTANCE.createAttribute();
    attr.setName("age");
    attr.setType(getDataTypeFor("int"));
    attr.setRequired(true);
    dom.getAttributes().add(attr);

    GrailsGenerator gen = new GrailsGenerator();

    String s = gen.buildEDomainClass(dom, "test");

    assertTrue(s.contains("age(nullable: false)"));
  }
コード例 #4
0
  @Test
  public void testGenerateSimpleDomain() {
    Domain dom = MVCoreFactoryImpl.eINSTANCE.createDomain();
    dom.setName("Person");
    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");
    // System.out.println(s);
    assertTrue(s.contains("package test"));
    assertTrue(s.contains("class Person"));
    assertTrue(s.contains("String name"));
  }
コード例 #5
0
  @Test
  public void testGenerateSuperTypeDomain() {
    Domain dom = MVCoreFactoryImpl.eINSTANCE.createDomain();
    dom.setName("Person");
    Attribute attr = MVCoreFactoryImpl.eINSTANCE.createAttribute();
    attr.setName("age");
    attr.setType(getDataTypeFor("int"));
    dom.getAttributes().add(attr);

    Domain parent = MVCoreFactoryImpl.eINSTANCE.createDomain();
    parent.setName("Entity");

    dom.setSuper(parent);

    GrailsGenerator gen = new GrailsGenerator();

    String s = gen.buildEDomainClass(dom, "test");
    System.out.println(s);
    assertTrue(s.contains("class Person extends Entity"));
  }