예제 #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 testGenerateDocumentedDomain() {
    Domain dom = MVCoreFactoryImpl.eINSTANCE.createDomain();
    dom.setName("Person");

    Documentation doc = MVCoreFactoryImpl.eINSTANCE.createDocumentation();
    doc.setValue("heipådeg");
    dom.getDocumentation().add(doc);
    GrailsGenerator gen = new GrailsGenerator();

    String s = gen.buildEDomainClass(dom, "test");
    System.out.println(s);
    assertTrue(s.contains("heipådeg"));
  }
예제 #3
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"));
  }
예제 #4
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)"));
  }
예제 #5
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"));
  }
예제 #6
0
  @Test
  public void testGenerateReferenceDomain() {
    Domain dom = MVCoreFactoryImpl.eINSTANCE.createDomain();
    dom.setName("Person");

    MVCore.Reference ref = MVCoreFactoryImpl.eINSTANCE.createReference();
    ref.setName("ref");
    ref.setSrc(dom);
    ref.setTarget(dom);
    ref.setUpperBound(1);
    dom.getReferences().add(ref);

    GrailsGenerator gen = new GrailsGenerator();

    String s = gen.buildEDomainClass(dom, "test");
    System.out.println(s);
    assertTrue(s.contains("Person ref"));
  }
예제 #7
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"));
  }