From: <hei...@us...> - 2008-07-26 13:30:31
|
Revision: 1453 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=1453&view=rev Author: heikkidoeleman Date: 2008-07-26 13:30:39 +0000 (Sat, 26 Jul 2008) Log Message: ----------- Removed Slots from PostalAddress; Junit / XMLUnit tests for ebXML PostalAddress Modified Paths: -------------- sandbox/3.0.x/src/main/config/ebxml-jibx-binding.xml sandbox/3.0.x/src/org/geonetwork/ebxml/informationmodel/provenance/PostalAddress.java Added Paths: ----------- sandbox/3.0.x/test/org/geonetwork/ebxml/informationmodel/provenance/PostalAddressTest.java sandbox/3.0.x/test/org/geonetwork/ebxml/informationmodel/provenance/TelephoneNumberTest.java sandbox/3.0.x/test/test/data/provenance/PostalAddressTestData.xml sandbox/3.0.x/test/test/data/provenance/TelephoneNumberTestData.xml sandbox/3.0.x/test/test/utilities/provenance/PostalAddressFactory.java sandbox/3.0.x/test/test/utilities/provenance/TelephoneNumberFactory.java Modified: sandbox/3.0.x/src/main/config/ebxml-jibx-binding.xml =================================================================== --- sandbox/3.0.x/src/main/config/ebxml-jibx-binding.xml 2008-07-26 13:10:03 UTC (rev 1452) +++ sandbox/3.0.x/src/main/config/ebxml-jibx-binding.xml 2008-07-26 13:30:39 UTC (rev 1453) @@ -277,10 +277,7 @@ <mapping name="PostalAddress" class="org.geonetwork.ebxml.informationmodel.provenance.PostalAddress"> <value style="attribute" name="city" field="city" usage="optional" /> <value style="attribute" name="country" field="country" usage="optional" /> - <value style="attribute" name="postalCode" field="postalCode" usage="optional" /> - <collection field="slots" factory="org.geonetwork.ebxml.informationmodel.provenance.PostalAddress.setFactory" usage="optional"> - <structure type="org.geonetwork.ebxml.informationmodel.core.Slot" usage="optional" /> - </collection> + <value style="attribute" name="postalCode" field="postalCode" usage="optional" /> <value style="attribute" name="stateOrProvince" field="stateOrProvince" usage="optional" /> <value style="attribute" name="street" field="street" usage="optional" /> <value style="attribute" name="streetNumber" field="streetNumber" usage="optional" /> Modified: sandbox/3.0.x/src/org/geonetwork/ebxml/informationmodel/provenance/PostalAddress.java =================================================================== --- sandbox/3.0.x/src/org/geonetwork/ebxml/informationmodel/provenance/PostalAddress.java 2008-07-26 13:10:03 UTC (rev 1452) +++ sandbox/3.0.x/src/org/geonetwork/ebxml/informationmodel/provenance/PostalAddress.java 2008-07-26 13:30:39 UTC (rev 1453) @@ -47,11 +47,10 @@ private ShortName city; private ShortName country; private ShortName postalCode; - private Set<Slot> slots; private ShortName stateOrProvince; private ShortName street; private String32 streetNumber; - + @Override public int hashCode() { final int prime = 31; @@ -60,7 +59,6 @@ result = prime * result + ((country == null) ? 0 : country.hashCode()); result = prime * result + ((postalCode == null) ? 0 : postalCode.hashCode()); - result = prime * result + ((slots == null) ? 0 : slots.hashCode()); result = prime * result + ((stateOrProvince == null) ? 0 : stateOrProvince.hashCode()); result = prime * result + ((street == null) ? 0 : street.hashCode()); @@ -92,11 +90,6 @@ return false; } else if (!postalCode.equals(other.postalCode)) return false; - if (slots == null) { - if (other.slots != null) - return false; - } else if (!slots.equals(other.slots)) - return false; if (stateOrProvince == null) { if (other.stateOrProvince != null) return false; @@ -132,12 +125,6 @@ public void setPostalCode(ShortName postalCode) { this.postalCode = postalCode; } - public Set<Slot> getSlots() { - return slots; - } - public void setSlots(Set<Slot> slots) { - this.slots = slots; - } public ShortName getStateOrProvince() { return stateOrProvince; } Added: sandbox/3.0.x/test/org/geonetwork/ebxml/informationmodel/provenance/PostalAddressTest.java =================================================================== --- sandbox/3.0.x/test/org/geonetwork/ebxml/informationmodel/provenance/PostalAddressTest.java (rev 0) +++ sandbox/3.0.x/test/org/geonetwork/ebxml/informationmodel/provenance/PostalAddressTest.java 2008-07-26 13:30:39 UTC (rev 1453) @@ -0,0 +1,139 @@ +//============================================================================= +//=== Copyright (C) 2008 European Space Agency (ESA). +//=== +//=== This program is free software; you can redistribute it and/or modify +//=== it under the terms of the GNU General Public License as published by +//=== the Free Software Foundation; either version 2 of the License, or (at +//=== your option) any later version. +//=== +//=== This program is distributed in the hope that it will be useful, but +//=== WITHOUT ANY WARRANTY; without even the implied warranty of +//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +//=== General Public License for more details. +//=== +//=== You should have received a copy of the GNU General Public License +//=== along with this program; if not, write to the Free Software +//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA +//=== +//=== Contact: Jeroen Ticheler - E-mail: geo...@os... + +//============================================================================== + +package org.geonetwork.ebxml.informationmodel.provenance; + +import java.io.BufferedWriter; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; + +import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.DifferenceListener; +import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; +import org.custommonkey.xmlunit.XMLTestCase; +import org.jibx.runtime.BindingDirectory; +import org.jibx.runtime.IBindingFactory; +import org.jibx.runtime.IMarshallingContext; +import org.jibx.runtime.IUnmarshallingContext; +import org.jibx.runtime.JiBXException; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import test.utilities.provenance.EmailAddressFactory; +import test.utilities.provenance.PostalAddressFactory; + +/** + * Tests marshalling and unmarshalling. + * + * @author heikki doeleman + * + */ +public class PostalAddressTest extends XMLTestCase { + + public PostalAddressTest(String name) { + super(name); + } + + + /** + * Tests unmarshalling (XML is instantiated as Java object) for PostalAddress. + * @throws FileNotFoundException + * @throws JiBXException + */ + public void testUnmarshal() throws FileNotFoundException, JiBXException { + // get input XML from file system + File testDataFile = new File("classes/test/data/provenance/PostalAddressTestData.xml"); + if(! testDataFile.exists()) { + System.err.println("Could not find test data file: " + testDataFile.getAbsolutePath()); + throw new FileNotFoundException("Could not find test data file: " + testDataFile.getAbsolutePath()); + } + else { + FileReader fileReader = new FileReader(testDataFile); + + // create JiBX unmarshal context + IBindingFactory bfact = BindingDirectory.getFactory(PostalAddress.class); + IUnmarshallingContext unMarshallingContext = bfact.createUnmarshallingContext(); + + // unmarshal to PostalAddress + PostalAddress unMarshallingResult = (PostalAddress)unMarshallingContext.unmarshalDocument(fileReader); + + // get expected result from test factory + PostalAddress expectedResult = PostalAddressFactory.create(); + + // test equality + assertEquals("Unmarshalling PostalAddress", expectedResult, unMarshallingResult); + } + } + + /** + * Tests marshalling (Java object puts out XML) a LocalizedString. + * @throws JiBXException + * @throws SAXException + * @throws IOException + */ + public void testMarshal() throws JiBXException, SAXException, IOException { + // create a PostalAddress with some values + PostalAddress o = PostalAddressFactory.create(); + + // set up JiBX marshalling context + IBindingFactory bfact = BindingDirectory.getFactory(PostalAddress.class); + IMarshallingContext marshallingContext = bfact.createMarshallingContext(); + + // marshal to console - nice if you're looking + Writer outConsole = new BufferedWriter(new OutputStreamWriter(System.out)); + marshallingContext.setOutput(outConsole); + marshallingContext.setIndent(3); + marshallingContext.marshalDocument(o, "UTF-8", null); + + // marshal to outputstream + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Writer out = new BufferedWriter(new OutputStreamWriter(outputStream)); + marshallingContext.setIndent(3); + marshallingContext.setOutput(out); + marshallingContext.marshalDocument(o, "UTF-8", null); + + // convert to InputSource for the comparison test + InputSource marshallingResult = new InputSource(new ByteArrayInputStream(outputStream.toByteArray())); + + // get expected result from filesystem + File testDataFile = new File("classes/test/data/provenance/PostalAddressTestData.xml"); + if(! testDataFile.exists()) { + System.err.println("Could not find test data file: " + testDataFile.getAbsolutePath()); + throw new FileNotFoundException("Could not find test data file: " + testDataFile.getAbsolutePath()); + } + else { + FileReader fileReader = new FileReader(testDataFile); + InputSource expectedResult = new InputSource(fileReader); + // comparison test + DifferenceListener differenceListener = new IgnoreTextAndAttributeValuesDifferenceListener(); + Diff diff = new Diff(expectedResult, marshallingResult); + diff.overrideDifferenceListener(differenceListener); + assertTrue("Marshalled PostalAddress matches expected XML " + diff, diff.similar()); + } + } + +} Added: sandbox/3.0.x/test/org/geonetwork/ebxml/informationmodel/provenance/TelephoneNumberTest.java =================================================================== --- sandbox/3.0.x/test/org/geonetwork/ebxml/informationmodel/provenance/TelephoneNumberTest.java (rev 0) +++ sandbox/3.0.x/test/org/geonetwork/ebxml/informationmodel/provenance/TelephoneNumberTest.java 2008-07-26 13:30:39 UTC (rev 1453) @@ -0,0 +1,138 @@ +//============================================================================= +//=== Copyright (C) 2008 European Space Agency (ESA). +//=== +//=== This program is free software; you can redistribute it and/or modify +//=== it under the terms of the GNU General Public License as published by +//=== the Free Software Foundation; either version 2 of the License, or (at +//=== your option) any later version. +//=== +//=== This program is distributed in the hope that it will be useful, but +//=== WITHOUT ANY WARRANTY; without even the implied warranty of +//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +//=== General Public License for more details. +//=== +//=== You should have received a copy of the GNU General Public License +//=== along with this program; if not, write to the Free Software +//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA +//=== +//=== Contact: Jeroen Ticheler - E-mail: geo...@os... + +//============================================================================== + +package org.geonetwork.ebxml.informationmodel.provenance; + +import java.io.BufferedWriter; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; + +import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.DifferenceListener; +import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; +import org.custommonkey.xmlunit.XMLTestCase; +import org.jibx.runtime.BindingDirectory; +import org.jibx.runtime.IBindingFactory; +import org.jibx.runtime.IMarshallingContext; +import org.jibx.runtime.IUnmarshallingContext; +import org.jibx.runtime.JiBXException; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import test.utilities.provenance.TelephoneNumberFactory; + +/** + * Tests marshalling and unmarshalling. + * + * @author heikki doeleman + * + */ +public class TelephoneNumberTest extends XMLTestCase { + + public TelephoneNumberTest(String name) { + super(name); + } + + + /** + * Tests unmarshalling (XML is instantiated as Java object) for TelephoneNumber. + * @throws FileNotFoundException + * @throws JiBXException + */ + public void testUnmarshal() throws FileNotFoundException, JiBXException { + // get input XML from file system + File testDataFile = new File("classes/test/data/provenance/TelephoneNumberTestData.xml"); + if(! testDataFile.exists()) { + System.err.println("Could not find test data file: " + testDataFile.getAbsolutePath()); + throw new FileNotFoundException("Could not find test data file: " + testDataFile.getAbsolutePath()); + } + else { + FileReader fileReader = new FileReader(testDataFile); + + // create JiBX unmarshal context + IBindingFactory bfact = BindingDirectory.getFactory(TelephoneNumber.class); + IUnmarshallingContext unMarshallingContext = bfact.createUnmarshallingContext(); + + // unmarshal to TelephoneNumber + TelephoneNumber unMarshallingResult = (TelephoneNumber)unMarshallingContext.unmarshalDocument(fileReader); + + // get expected result from test factory + TelephoneNumber expectedResult = TelephoneNumberFactory.create(); + + // test equality + assertEquals("Unmarshalling TelephoneNumber", expectedResult, unMarshallingResult); + } + } + + /** + * Tests marshalling (Java object puts out XML) a LocalizedString. + * @throws JiBXException + * @throws SAXException + * @throws IOException + */ + public void testMarshal() throws JiBXException, SAXException, IOException { + // create a TelephoneNumber with some values + TelephoneNumber o = TelephoneNumberFactory.create(); + + // set up JiBX marshalling context + IBindingFactory bfact = BindingDirectory.getFactory(TelephoneNumber.class); + IMarshallingContext marshallingContext = bfact.createMarshallingContext(); + + // marshal to console - nice if you're looking + Writer outConsole = new BufferedWriter(new OutputStreamWriter(System.out)); + marshallingContext.setOutput(outConsole); + marshallingContext.setIndent(3); + marshallingContext.marshalDocument(o, "UTF-8", null); + + // marshal to outputstream + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + Writer out = new BufferedWriter(new OutputStreamWriter(outputStream)); + marshallingContext.setIndent(3); + marshallingContext.setOutput(out); + marshallingContext.marshalDocument(o, "UTF-8", null); + + // convert to InputSource for the comparison test + InputSource marshallingResult = new InputSource(new ByteArrayInputStream(outputStream.toByteArray())); + + // get expected result from filesystem + File testDataFile = new File("classes/test/data/provenance/TelephoneNumberTestData.xml"); + if(! testDataFile.exists()) { + System.err.println("Could not find test data file: " + testDataFile.getAbsolutePath()); + throw new FileNotFoundException("Could not find test data file: " + testDataFile.getAbsolutePath()); + } + else { + FileReader fileReader = new FileReader(testDataFile); + InputSource expectedResult = new InputSource(fileReader); + // comparison test + DifferenceListener differenceListener = new IgnoreTextAndAttributeValuesDifferenceListener(); + Diff diff = new Diff(expectedResult, marshallingResult); + diff.overrideDifferenceListener(differenceListener); + assertTrue("Marshalled TelephoneNumber matches expected XML " + diff, diff.similar()); + } + } + +} Added: sandbox/3.0.x/test/test/data/provenance/PostalAddressTestData.xml =================================================================== --- sandbox/3.0.x/test/test/data/provenance/PostalAddressTestData.xml (rev 0) +++ sandbox/3.0.x/test/test/data/provenance/PostalAddressTestData.xml 2008-07-26 13:30:39 UTC (rev 1453) @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<tns:PostalAddress xmlns:tns="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0" city="city" country="country" postalCode="postalCode" stateOrProvince="stateOrProvince" street="street" streetNumber="streetNumber"/> \ No newline at end of file Added: sandbox/3.0.x/test/test/data/provenance/TelephoneNumberTestData.xml =================================================================== --- sandbox/3.0.x/test/test/data/provenance/TelephoneNumberTestData.xml (rev 0) +++ sandbox/3.0.x/test/test/data/provenance/TelephoneNumberTestData.xml 2008-07-26 13:30:39 UTC (rev 1453) @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<tns:TelephoneNumber xmlns:tns="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0" areaCode="areacode" countryCode="country" extension="extensio" number="number" phoneType="phonetype"/> \ No newline at end of file Added: sandbox/3.0.x/test/test/utilities/provenance/PostalAddressFactory.java =================================================================== --- sandbox/3.0.x/test/test/utilities/provenance/PostalAddressFactory.java (rev 0) +++ sandbox/3.0.x/test/test/utilities/provenance/PostalAddressFactory.java 2008-07-26 13:30:39 UTC (rev 1453) @@ -0,0 +1,42 @@ +//============================================================================= +//=== Copyright (C) 2008 European Space Agency (ESA). +//=== +//=== This program is free software; you can redistribute it and/or modify +//=== it under the terms of the GNU General Public License as published by +//=== the Free Software Foundation; either version 2 of the License, or (at +//=== your option) any later version. +//=== +//=== This program is distributed in the hope that it will be useful, but +//=== WITHOUT ANY WARRANTY; without even the implied warranty of +//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +//=== General Public License for more details. +//=== +//=== You should have received a copy of the GNU General Public License +//=== along with this program; if not, write to the Free Software +//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA +//=== +//=== Contact: Jeroen Ticheler - E-mail: geo...@os... + +//============================================================================== + +package test.utilities.provenance; + +import org.geonetwork.ebxml.informationmodel.core.datatype.ShortName; +import org.geonetwork.ebxml.informationmodel.core.datatype.String32; +import org.geonetwork.ebxml.informationmodel.provenance.PostalAddress; + +public class PostalAddressFactory { + + public synchronized static PostalAddress create() { + PostalAddress o = new PostalAddress(); + + o.setCity(new ShortName("city")); + o.setCountry(new ShortName("country")); + o.setPostalCode(new ShortName("postalCode")); + o.setStateOrProvince(new ShortName("stateOrProvince")); + o.setStreet(new ShortName("street")); + o.setStreetNumber(new String32("streetNumber")); + + return o; + } +} Added: sandbox/3.0.x/test/test/utilities/provenance/TelephoneNumberFactory.java =================================================================== --- sandbox/3.0.x/test/test/utilities/provenance/TelephoneNumberFactory.java (rev 0) +++ sandbox/3.0.x/test/test/utilities/provenance/TelephoneNumberFactory.java 2008-07-26 13:30:39 UTC (rev 1453) @@ -0,0 +1,42 @@ +//============================================================================= +//=== Copyright (C) 2008 European Space Agency (ESA). +//=== +//=== This program is free software; you can redistribute it and/or modify +//=== it under the terms of the GNU General Public License as published by +//=== the Free Software Foundation; either version 2 of the License, or (at +//=== your option) any later version. +//=== +//=== This program is distributed in the hope that it will be useful, but +//=== WITHOUT ANY WARRANTY; without even the implied warranty of +//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +//=== General Public License for more details. +//=== +//=== You should have received a copy of the GNU General Public License +//=== along with this program; if not, write to the Free Software +//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA +//=== +//=== Contact: Jeroen Ticheler - E-mail: geo...@os... + +//============================================================================== + +package test.utilities.provenance; + +import org.geonetwork.ebxml.informationmodel.core.datatype.String16; +import org.geonetwork.ebxml.informationmodel.core.datatype.String32; +import org.geonetwork.ebxml.informationmodel.core.datatype.String8; +import org.geonetwork.ebxml.informationmodel.provenance.TelephoneNumber; + +public class TelephoneNumberFactory { + + public synchronized static TelephoneNumber create() { + TelephoneNumber o = new TelephoneNumber(); + + o.setAreaCode(new String8("areacode")); + o.setCountryCode(new String8("country")); + o.setExtension(new String8("extensio")); + o.setNumber(new String16("number")); + o.setPhoneType(new String32("phonetype")); + + return o; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |