Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This commit adds the annotation parsing to ModelGroup, and tests to check it #289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion core/src/main/groovy/com/predic8/schema/ModelGroup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import groovy.xml.QName
import javax.xml.namespace.QName as JQName

abstract class ModelGroup extends SchemaComponent{


Annotation annotation
List<SchemaComponent> particles = []
def minOccurs = 1
def maxOccurs = 1
Expand All @@ -33,6 +34,10 @@ abstract class ModelGroup extends SchemaComponent{

protected parseChildren(token, child, params) {
switch (child ){
case 'annotation' :
annotation = new Annotation(schema: schema)
annotation.parse(token, params) ; break

case 'element' : def element = new Element(schema:schema)
element.parse(token, params)
particles << element ; break
Expand Down
12 changes: 12 additions & 0 deletions core/src/test/groovy/com/predic8/schema/AllTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,16 @@ class AllTest extends GroovyTestCase{
assertEquals('?XXX?', emp.city.toString())
assertEquals('', emp.person.isHuman.toString())
}

void testAllAnnotation() {
def employee = schema.getType(EMPLOYEE_TYPE)
def all = employee.model
assertNotNull(all)
def annotation = all.getAnnotation()
assertNotNull( annotation );
def documentation = annotation.getDocumentations().first();
assertNotNull( documentation );
def documentationContent = documentation.content;
assertEquals( "Hello world", documentationContent );
}
}
13 changes: 12 additions & 1 deletion core/src/test/groovy/com/predic8/schema/ChoiceTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ class ChoiceTest extends GroovyTestCase{
assertEquals('+49 228 2402099', inf.phone.toString())
}

void testChoiceAnnotation() {
def employee = schema.getType(CONT_INF)
def contactInfo = employee.model
assertNotNull(contactInfo)
def annotation = contactInfo.getAnnotation()
assertNotNull( annotation );
def documentation = annotation.getDocumentations().first();
assertNotNull( documentation );
def documentationContent = documentation.content;
assertEquals( "Hello world", documentationContent );
}

/*void testRequestTemplateCreator() {
def strWriter = new StringWriter()
def creator = new RequestTemplateCreator(builder : new MarkupBuilder(strWriter))
Expand All @@ -68,4 +80,3 @@ class ChoiceTest extends GroovyTestCase{
assertEquals('?XXX?', emp.person.lastName.toString())
}*/
}

5 changes: 4 additions & 1 deletion core/src/test/resources/schema/all/all.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

<xsd:complexType name="EmployeeType">
<xsd:all minOccurs="1">
<xsd:annotation>
<xsd:documentation>Hello world</xsd:documentation>
</xsd:annotation>
<xsd:element name="person">
<xsd:complexType>
<xsd:group ref="tns:PersonGroup" />
Expand All @@ -25,4 +28,4 @@

<xsd:element name="employee" type="tns:EmployeeType" />

</xsd:schema>
</xsd:schema>
6 changes: 5 additions & 1 deletion core/src/test/resources/schema/choice/choice.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

<xsd:complexType name="ContactInfoType">
<xsd:choice>
<xsd:sequence>
<xsd:annotation>
<xsd:documentation>Hello world</xsd:documentation>
</xsd:annotation>

<xsd:sequence>
<xsd:element name="city" type="xsd:string" />
<xsd:element name="zip" type="xsd:string" />
</xsd:sequence>
Expand Down