I wonder how I could make use of scalacheck on types generated by scalaxb stemming from complex xsds like this one:
http://wiki.xmldation.com/@api/deki/files/379/=pain.001.001.03.xsd
The actual documents resemble payments and I want to restrict the test-data in the one or other way (account owners/numbers, amounts, countries).
the actual components to test are: xml-parsers checking the syntax and producing error-messages, xml-parsers parsing the documents to a record-like data-structure, xml-printers writing such documents.
Would it be feasible ?
One of the ways you can check for the validity of scalaxb-generated case classes and typeclass instances is to do the roundtrip. It's not perfect, but it should test consistency of the classes.
For example, you could start with XML document, parse it into a case class, and turn it back to XML document again. For that you'd need to define a generator covering various scenarios.
Or, go the other way, start with arbitrary case classes, convert them to XML documents, and parse it back into case classes. I think it would be more straightforward to define case class generators like The arbitrary Generator examples:
implicit lazy val arbBool: Arbitrary[Boolean] = Arbitrary(oneOf(true, false))
For example, an Arbitrary
instance for the following AddressType2Code
can be defined in the same way.
<xs:simpleType name="AddressType2Code">
<xs:restriction base="xs:string">
<xs:enumeration value="ADDR"/>
<xs:enumeration value="PBOX"/>
<xs:enumeration value="HOME"/>
<xs:enumeration value="BIZZ"/>
<xs:enumeration value="MLTO"/>
<xs:enumeration value="DLVY"/>
</xs:restriction>
</xs:simpleType>
Using these as building blocks, Arbitrary
instance for complex type can be constructed like implicit def arbTree[T]
.
The benefit of having Arbitrary
instances around, is you can then proceed to test your business logic code with it, pretending that XML document already exists.