eed3si9n/scalaxb — Issue #126: custom datarec broke comparison
Author: deanhiller
Created: 2011-12-01 16:46:23+00:00
State: open

I marshal the case class to xml and back and comparing them, they are different making it very hard to write tests that compare all fields by just comparing the case classes :(. here is the test case...

@Test def testCompare() {
def toXML2(event: EPCISEventType): NodeSeq = {
toXML[EPCISEventType](event, Some("urn:epcglobal:epcis:xsd:1"), Some("EventObject"), NewTntAPIFactory.defaultScope)
}
def translateToShipFrom(location:String) :DataRecord[Any] = {
val elem = {location}
DataRecord[xml.Elem](Some("urn:epcglobal:hls:1"), Some("shipFromBusinessLocationCode"), elem)
}

def translateToShipTo(location:String) :DataRecord[Any] = {
val elem = {location}
DataRecord[xml.Elem](Some("urn:epcglobal:hls:1"), Some("shipToBusinessLocationCode"), elem)
}
val list = EPC("asdf") :: Nil
val epcList = EPCListType(list: _*)
val bizTxs = BusinessTransactionType(new URI("urn:epcglobal:cbv:bt:0111222000005:XYZdef"),
Some(new URI("urn:epcglobal:cbv:btt:po"))) ::
BusinessTransactionType(new URI("urn:epcglobal:cbv:bt:0111222000005:DAdef"),
Some(new URI("urn:epcglobal:cbv:btt:desadv"))) :: Nil
val readPoint = Some(ReadPointType(new URI("asdf"), None, Nil))
val bizLoc = Some(BusinessLocationType(new URI("bdef"), None, Nil))
val txList = Some(BusinessTransactionListType(bizTxs:_*))

val dateTime = new DateTime().toGregorianCalendar
val xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(dateTime)

val any : List[DataRecord[Any]] = translateToShipFrom("qwer") ::
translateToShipTo("qewte") :: Nil

val shipEvt1 = ObjectEventType(xmlDate, None, "",
None, epcList, OBSERVE,
Some(new URI("urn:epcglobal:bizstep:shipping")),
Some(new URI("urn:epcglobal:cbv:disp:in_transit")),
readPoint, bizLoc, txList, None, any, Map[String, scalaxb.DataRecord[Any]]())

val strXml = toXML2(shipEvt1).toString
val shipEvtTemp = fromXML[EPCISEventType](XML.loadString(strXml))
val shipEvt2 = shipEvtTemp.asInstanceOf[ObjectEventType]

val dataRec1 = shipEvt1.any.head
val dataRec2 = shipEvt2.any.head
//The data records are not equal because of the namespace this time...
Assert.assertNotEquals(dataRec1, dataRec2)

Assert.assertNotEquals(shipEvt1, shipEvt2)
}