Modified: xmlbeans/trunk/test/src/xmlobject/detailed/SelectChildrenTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/detailed/SelectChildrenTests.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/detailed/SelectChildrenTests.java (original) +++ xmlbeans/trunk/test/src/xmlobject/detailed/SelectChildrenTests.java Fri Jan 18 23:08:44 2019 @@ -16,47 +16,42 @@ package xmlobject.detailed; -import org.openuri.test.selectChildren.*; - -import org.apache.xmlbeans.*; +import org.apache.xmlbeans.QNameSet; +import org.apache.xmlbeans.QNameSetBuilder; +import org.apache.xmlbeans.XmlObject; +import org.junit.Test; +import org.openuri.test.selectChildren.ElemWithAnyDocument; +import org.openuri.test.selectChildren.NormalDocument; +import org.openuri.test.selectChildren.NormalType; +import org.openuri.test.selectChildren.WithAnyType; +import xmlobject.common.SelectChildrenAttribCommon; import javax.xml.namespace.QName; -import java.util.*; +import java.util.HashSet; +import java.util.Set; -import xmlobject.common.SelectChildrenAttribCommon; +import static org.junit.Assert.assertTrue; -/** - * - * - */ -public class SelectChildrenTests - extends SelectChildrenAttribCommon -{ - public SelectChildrenTests(String name) - { - super(name); - } +public class SelectChildrenTests extends SelectChildrenAttribCommon { + private static String scUri = "http://openuri.org/test/selectChildren"; + private static String scStartFrag = "<xm xmlns:sc=\"" + scUri + "\">"; + private static String abcUri = "http://abc"; + private static String defUri = "http://def"; + private static String xyzUri = "http://xyz"; - static String scUri = "http://openuri.org/test/selectChildren"; - static String scStartFrag = "<xm xmlns:sc=\"" + scUri + "\">"; - - static String abcUri = "http://abc"; - static String defUri = "http://def"; - static String xyzUri = "http://xyz"; - - static String anyStartFrag = "<xm xmlns:sc=\"" + scUri + "\"" + - " xmlns:abc=\"" + abcUri + "\"" + - " xmlns:def=\"" + defUri + "\"" + - " xmlns:xyz=\"" + xyzUri + "\"" + ">"; + private static String anyStartFrag = "<xm xmlns:sc=\"" + scUri + "\"" + + " xmlns:abc=\"" + abcUri + "\"" + + " xmlns:def=\"" + defUri + "\"" + + " xmlns:xyz=\"" + xyzUri + "\"" + ">"; - static String endFrag = "</xm>"; + private static String endFrag = "</xm>"; ////////////////////////////////////////////////////////////////// // Tests + @Test public void testSelectWithQName() - throws Exception - { + throws Exception { String xml = getXml("xbean/xmlobject/SelectChildren-NormalDoc.xml"); XmlObject[] xos; // For the return from selectChildren @@ -64,7 +59,7 @@ public class SelectChildrenTests NormalDocument doc = NormalDocument.Factory.parse(xml); assertTrue(doc.validate()); - NormalType norm = doc.getNormal(); + NormalType norm = doc.getNormal(); exps = new String[]{scStartFrag + "first element" + endFrag}; xos = norm.selectChildren(new QName(scUri, "first")); @@ -72,10 +67,9 @@ public class SelectChildrenTests this.validateTest("testSelectWithQName", exps, xos); } - + @Test public void testSelectWithURI() - throws Exception - { + throws Exception { String xml = getXml("xbean/xmlobject/SelectChildren-NormalDoc.xml"); XmlObject[] xos; // For the return from selectChildren @@ -83,7 +77,7 @@ public class SelectChildrenTests NormalDocument doc = NormalDocument.Factory.parse(xml); assertTrue(doc.validate()); - NormalType norm = doc.getNormal(); + NormalType norm = doc.getNormal(); exps = new String[]{scStartFrag + "second element" + endFrag}; xos = norm.selectChildren(scUri, "second"); @@ -91,9 +85,9 @@ public class SelectChildrenTests this.validateTest("testSelectWithURI", exps, xos); } + @Test public void testSelectWithQNameSet() - throws Exception - { + throws Exception { String xml = getXml("xbean/xmlobject/SelectChildren-NormalDoc.xml"); XmlObject[] xos; // For the return from selectChildren @@ -101,19 +95,19 @@ public class SelectChildrenTests NormalDocument doc = NormalDocument.Factory.parse(xml); assertTrue(doc.validate()); - NormalType norm = doc.getNormal(); + NormalType norm = doc.getNormal(); - QName[] qArr = new QName[] { new QName(scUri, "first"), - new QName(scUri, "numbers"), - new QName(scUri, "second")}; + QName[] qArr = new QName[]{new QName(scUri, "first"), + new QName(scUri, "numbers"), + new QName(scUri, "second")}; QNameSet qSet = QNameSet.forArray(qArr); exps = new String[]{scStartFrag + "first element" + endFrag, - scStartFrag + "second element" + endFrag, - scStartFrag + "10" + endFrag, - scStartFrag + "11" + endFrag, - scStartFrag + "12" + endFrag }; + scStartFrag + "second element" + endFrag, + scStartFrag + "10" + endFrag, + scStartFrag + "11" + endFrag, + scStartFrag + "12" + endFrag}; xos = norm.selectChildren(qSet); @@ -122,9 +116,9 @@ public class SelectChildrenTests ////////////////////////////////////////////////////////////////////// // Tests with 'any' Element + @Test public void testSelectWithQNameForAny() - throws Exception - { + throws Exception { XmlObject[] xos; // For the return from selectChildren String[] exps; // For the expected xml strings @@ -135,14 +129,14 @@ public class SelectChildrenTests WithAnyType any = doc.getElemWithAny(); // Select children from a known namespace xos = any.selectChildren(new QName(defUri, "someElem2")); - exps = new String[]{anyStartFrag + "DEF Namespace" + endFrag }; + exps = new String[]{anyStartFrag + "DEF Namespace" + endFrag}; validateTest("testSelectWithQNameForAny", exps, xos); } + @Test public void testSelectWithURIForAny() - throws Exception - { + throws Exception { XmlObject[] xos; // For the return from selectChildren String[] exps; // For the expected xml strings @@ -153,14 +147,14 @@ public class SelectChildrenTests WithAnyType any = doc.getElemWithAny(); // Select children from a known namespace xos = any.selectChildren(scUri, "simple"); - exps = new String[]{anyStartFrag + "Simple String" + endFrag }; + exps = new String[]{anyStartFrag + "Simple String" + endFrag}; validateTest("testSelectWithURIForAny", exps, xos); } + @Test public void testSelectWithWildcard() - throws Exception - { + throws Exception { XmlObject[] xos; // For the return from selectChildren String[] exps; // For the expected xml strings String xml = getXml("xbean/xmlobject/SelectChildren-AnyTypeDoc.xml"); @@ -170,20 +164,20 @@ public class SelectChildrenTests WithAnyType any = doc.getElemWithAny(); xos = any.selectChildren(QNameSet.forWildcardNamespaceString("##other", - scUri)); + scUri)); exps = new String[]{anyStartFrag + "ABC Namespace" + endFrag, - anyStartFrag + "DEF Namespace" + endFrag, - anyStartFrag + "XYX Namespace" + endFrag, - anyStartFrag + "ABC-SameElem" + endFrag, - anyStartFrag + "DEF-SameElem" + endFrag, - anyStartFrag + "XYZ-SameElem" + endFrag}; + anyStartFrag + "DEF Namespace" + endFrag, + anyStartFrag + "XYX Namespace" + endFrag, + anyStartFrag + "ABC-SameElem" + endFrag, + anyStartFrag + "DEF-SameElem" + endFrag, + anyStartFrag + "XYZ-SameElem" + endFrag}; validateTest("testSelectWithWildcard", exps, xos); } + @Test public void testSelectWithQNameBuilder() - throws Exception - { + throws Exception { XmlObject[] xos; // For the return from selectChildren String[] exps; // For the expected xml strings String xml = getXml("xbean/xmlobject/SelectChildren-AnyTypeDoc.xml"); @@ -192,25 +186,22 @@ public class SelectChildrenTests WithAnyType any = doc.getElemWithAny(); - Set excFromIncSet = new HashSet(); + Set<QName> excFromIncSet = new HashSet<QName>(); excFromIncSet.add(new QName(scUri, "simple")); - Set excSet = new HashSet(); + Set<String> excSet = new HashSet<String>(); excSet.add(xyzUri); - Set incFromExcSet = new HashSet(); + Set<QName> incFromExcSet = new HashSet<QName>(); incFromExcSet.add(new QName(xyzUri, "sameElem")); QNameSet qset = new QNameSetBuilder(excSet, - null, - excFromIncSet, - incFromExcSet).toQNameSet(); + null, + excFromIncSet, + incFromExcSet).toQNameSet(); xos = any.selectChildren(qset); - for (int i =0; i < xos.length; i++) + for (int i = 0; i < xos.length; i++) System.out.println(xos[i].xmlText()); - } - - }
Modified: xmlbeans/trunk/test/src/xmlobject/detailed/SerializationDetailedTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/detailed/SerializationDetailedTests.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/detailed/SerializationDetailedTests.java (original) +++ xmlbeans/trunk/test/src/xmlobject/detailed/SerializationDetailedTests.java Fri Jan 18 23:08:44 2019 @@ -16,10 +16,8 @@ package xmlobject.detailed; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.apache.xmlbeans.XmlInteger; +import org.junit.Test; import org.w3c.dom.DocumentFragment; import org.w3c.dom.Node; @@ -29,29 +27,29 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.math.BigInteger; -public class SerializationDetailedTests extends TestCase -{ - public SerializationDetailedTests (String name) { super(name); } - public static Test suite() { return new TestSuite(SerializationDetailedTests.class); } +import static org.junit.Assert.assertTrue; - public void testDocFragmentSerialization() throws Exception - { - XmlInteger xmlInt = XmlInteger.Factory.newInstance(); - xmlInt.setBigIntegerValue(new BigInteger("10")); +public class SerializationDetailedTests { - Node node = xmlInt.getDomNode(); - assertTrue("DOM node from XmlObject not instance of DocumentFragment (it is a "+node+")", node instanceof DocumentFragment); + @Test + public void testDocFragmentSerialization() throws Exception { + XmlInteger xmlInt = XmlInteger.Factory.newInstance(); + xmlInt.setBigIntegerValue(new BigInteger("10")); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(out); - oos.writeObject(xmlInt); + Node node = xmlInt.getDomNode(); + assertTrue("DOM node from XmlObject not instance of DocumentFragment (it is a " + node + ")", node instanceof DocumentFragment); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(out); + oos.writeObject(xmlInt); - ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(in); - XmlInteger deserialized = (XmlInteger) ois.readObject(); - node = deserialized.getDomNode(); - assertTrue("DOM node from deserialized XmlObject not instance of DocumentFragment (it is a "+node+")", node instanceof DocumentFragment); } + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(in); + XmlInteger deserialized = (XmlInteger) ois.readObject(); + node = deserialized.getDomNode(); + assertTrue("DOM node from deserialized XmlObject not instance of DocumentFragment (it is a " + node + ")", node instanceof DocumentFragment); } + +} Modified: xmlbeans/trunk/test/src/xmlobject/detailed/SetIdentityTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/detailed/SetIdentityTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/detailed/SetIdentityTest.java (original) +++ xmlbeans/trunk/test/src/xmlobject/detailed/SetIdentityTest.java Fri Jan 18 23:08:44 2019 @@ -16,61 +16,29 @@ package xmlobject.detailed; -import junit.framework.*; -import junit.framework.Assert.*; - -import java.io.*; - -import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlBeans; -import org.apache.xmlbeans.XmlOptions; -import org.apache.xmlbeans.XmlCursor.TokenType; -import org.apache.xmlbeans.XmlDocumentProperties; -import org.apache.xmlbeans.XmlCursor.XmlBookmark; -import org.apache.xmlbeans.SchemaType; - -import javax.xml.namespace.QName; - -import xmlcursor.common.*; - -import java.net.URL; - -import tools.util.Util; -import tools.util.JarUtil; +import org.apache.xmlbeans.XmlObject; +import org.junit.Test; import org.tranxml.tranXML.version40.CarLocationMessageDocument; -import org.tranxml.tranXML.version40.GeographicLocationDocument.GeographicLocation; import org.tranxml.tranXML.version40.CodeList309; +import org.tranxml.tranXML.version40.GeographicLocationDocument.GeographicLocation; import org.tranxml.tranXML.version40.LocationIdentifierDocument.LocationIdentifier; +import tools.util.JarUtil; +import xmlcursor.common.Common; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -/** - * - * - */ -public class SetIdentityTest extends TestCase { - public SetIdentityTest(String sName) { - super(sName); - } - - public static Test suite() { - return new TestSuite(SetIdentityTest.class); - } - - public void testClassPath() throws Exception { - String sClassPath = System.getProperty("java.class.path"); - int i = sClassPath.indexOf(Common.CARLOCATIONMESSAGE_JAR); - assertTrue(i >= 0); - } +public class SetIdentityTest { + @Test public void testSetIdentity() throws Exception { CarLocationMessageDocument clm = (CarLocationMessageDocument) XmlObject.Factory.parse( JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM)); XmlCursor xc = clm.newCursor(); - xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT + - "$this//GeographicLocation"); + xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT + "$this//GeographicLocation"); xc.toNextSelection(); GeographicLocation gl = (GeographicLocation) xc.getObject(); xc.dispose(); Modified: xmlbeans/trunk/test/src/xmlobject/detailed/SoapFaultTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/detailed/SoapFaultTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/detailed/SoapFaultTest.java (original) +++ xmlbeans/trunk/test/src/xmlobject/detailed/SoapFaultTest.java Fri Jan 18 23:08:44 2019 @@ -15,42 +15,28 @@ package xmlobject.detailed; -import junit.framework.TestCase; - import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; -import org.apache.xmlbeans.XmlError; - -import javax.xml.namespace.QName; - -import org.xmlsoap.schemas.soap.envelope.Fault; -//import org.xmlsoap.schemas.soap.envelope.FaultDocument; +import org.junit.Ignore; +import org.junit.Test; import org.xmlsoap.schemas.soap.envelope.Detail; - +import org.xmlsoap.schemas.soap.envelope.Fault; import xmlobjecttest.soapfaults.FirstFaultType; -import xmlobjecttest.soapfaults.FirstFaultDocument; -import xmlobjecttest.soapfaults.SecondFaultType; -import xmlobjecttest.soapfaults.SecondFaultDocument; +import javax.xml.namespace.QName; import java.util.ArrayList; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -/** - * - */ -public class SoapFaultTest extends TestCase { - public static final String soapenc = "http://schemas.xmlsoap.org/soap/encoding/"; - public static final String soapenv = "http://schemas.xmlsoap.org/soap/envelope/"; - - public SoapFaultTest(String name) { - super(name); - } - - /** Regression test for Radar bug #25114 */ +public class SoapFaultTest { + private static final String soapenv = "http://schemas.xmlsoap.org/soap/envelope/"; /** - * - + * Regression test for Radar bug #25114 + */ + @Test + @Ignore public void testSetDetail() throws Exception { Fault fault = Fault.Factory.newInstance(); fault.setDetail(Detail.Factory.parse(XmlObject.Factory.parse("<foo/>").newXMLInputStream())); @@ -58,72 +44,58 @@ public class SoapFaultTest extends TestC assertEquals("<detail><foo/></detail>", fault.xmlText()); assertEquals("<xml-fragment><foo/></xml-fragment>", fault.getDetail().xmlText()); } - */ - - /** Regression test for Radar bug #25119 */ /** - * + * Regression test for Radar bug #25119 */ + @Test public void testAddNewDetail() throws Exception { Fault fault = Fault.Factory.newInstance(); fault.setFaultcode(new QName(soapenv, "foo")); fault.setFaultstring("Undefined"); fault.addNewDetail().set( - XmlObject.Factory.parse("<foo/>").changeType(Detail.type)); + XmlObject.Factory.parse("<foo/>").changeType(Detail.type)); String expect = "<xml-fragment>" + - "<faultcode xmlns:soapenv=\"" + soapenv + "\">soapenv:foo</faultcode>" + - "<faultstring>Undefined</faultstring>" + - "<detail><foo/></detail>" + - "</xml-fragment>"; + "<faultcode xmlns:soapenv=\"" + soapenv + "\">soapenv:foo</faultcode>" + + "<faultstring>Undefined</faultstring>" + + "<detail><foo/></detail>" + + "</xml-fragment>"; assertEquals(expect, fault.xmlText()); assertEquals(new QName(soapenv, "foo"), fault.getFaultcode()); assertEquals("Undefined", fault.getFaultstring()); assertEquals("<foo/>", fault.getDetail().xmlText()); } - /** Regression test for Radar bug #25409 */ - /** - * - * @status inactive - + * Regression test for Radar bug #25409 + */ + @Test + @Ignore public void testSetFaultDetail() throws Exception { String soapFault = - "<soapenv:Fault xmlns:soapenv=\"" + soapenv + "\">" + - "<faultcode>soapenv:Server</faultcode>" + - "<faultstring>Undefined</faultstring>" + - "<detail>" + - " <soap:a-string xmlns:soap=\"http://xmlobjecttest/soapfaults\">" + - " The First Fault" + - " </soap:a-string>" + - " <soap:a-int xmlns:soap=\"http://xmlobjecttest/soapfaults\">" + - " 1" + - " </soap:a-int>" + - " <soap:a-date xmlns:soap=\"http://xmlobjecttest/soapfaults\">" + - " 2003-03-28" + - " </soap:a-date>" + - "</detail>" + - "</soapenv:Fault>"; + "<soapenv:Fault xmlns:soapenv=\"" + soapenv + "\">" + + "<faultcode>soapenv:Server</faultcode>" + + "<faultstring>Undefined</faultstring>" + + "<detail>" + + " <soap:a-string xmlns:soap=\"http://xmlobjecttest/soapfaults\">" + + " The First Fault" + + " </soap:a-string>" + + " <soap:a-int xmlns:soap=\"http://xmlobjecttest/soapfaults\">" + + " 1" + + " </soap:a-int>" + + " <soap:a-date xmlns:soap=\"http://xmlobjecttest/soapfaults\">" + + " 2003-03-28" + + " </soap:a-date>" + + "</detail>" + + "</soapenv:Fault>"; Fault faultDoc = Fault.Factory.parse(soapFault); - XmlOptions opt=new XmlOptions(); - ArrayList errors=new ArrayList(); + XmlOptions opt = new XmlOptions(); + ArrayList errors = new ArrayList(); opt.setErrorListener(errors); - try{ assertTrue(faultDoc.validate(opt)); - }catch (Throwable t){ - for (int i = 0; i < errors.size(); i++) { - XmlError error = (XmlError) errors.get(i); - System.out.println("\n"); - System.out.println("Message: " + error.getMessage() + "\n"); - if (error.getCursorLocation() != null) - System.out.println("Location of invalid XML: " + - error.getCursorLocation().xmlText() + "\n"); - } - } assertEquals(new QName(soapenv, "Server"), faultDoc.getFaultcode()); assertEquals("Undefined", faultDoc.getFaultstring()); @@ -135,7 +107,6 @@ public class SoapFaultTest extends TestC assertEquals("The First Fault", firstFault.getAString().trim()); assertEquals(1, firstFault.getAInt()); assertEquals(new org.apache.xmlbeans.XmlCalendar("2003-03-28"), - firstFault.getADate()); + firstFault.getADate()); } - */ } Modified: xmlbeans/trunk/test/src/xmlobject/detailed/SubstGroupTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/detailed/SubstGroupTests.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/detailed/SubstGroupTests.java (original) +++ xmlbeans/trunk/test/src/xmlobject/detailed/SubstGroupTests.java Fri Jan 18 23:08:44 2019 @@ -15,12 +15,12 @@ package xmlobject.detailed; -import junit.framework.Assert; -import junit.framework.TestCase; import org.apache.xmlbeans.XmlError; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; import org.apache.xmlbeans.impl.values.XmlValueDisconnectedException; +import org.junit.Assert; +import org.junit.Test; import tools.xml.XmlComparator; import xmlobject.substgroup.*; @@ -29,239 +29,58 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.Iterator; -public class SubstGroupTests extends TestCase -{ - - private String URI = "http://xmlobject/substgroup"; - - public SubstGroupTests(String name) - { - super(name); - } - - /** - * Convenience Method to return: - * <xsd:complexType name="ItemType"> - * <xsd:sequence> - * <xsd:element name="sku" type="xsd:integer"/> - * <xsd:element name="name" type="xsd:string"/> - * </xsd:sequence> - * </xsd:complexType> - * - * @return - */ - public ItemType getItemType() - { - xmlobject.substgroup.ItemType item = ItemType.Factory.newInstance(); - item.setName("ItemType"); - item.setSku(new BigInteger("12")); - return item; - } - - /** - * Convenience Method to return: - * <xsd:element name="item" type="tns:ItemType"/> - * - * @return - */ - public ItemDocument getItemDoc() - { - xmlobject.substgroup.ItemDocument item = ItemDocument.Factory.newInstance(); - ItemType it = item.addNewItem(); - it.setName("ItemDocument"); - it.setSku(new BigInteger("12")); - item.setItem(it); - return item; - } - - - /** - * Convenience Method to return: - * <xsd:element name="chair" substitutionGroup="tns:item"/> - * - * @return - */ - public ChairDocument getChairDoc() - { - xmlobject.substgroup.ChairDocument chair = ChairDocument.Factory.newInstance(); - ItemType item = chair.addNewChair(); - item.setName("Chair"); - item.setSku(new BigInteger("12")); - chair.setChair(item); - return chair; - } - - /** - * Convenience Method to return: - * <xsd:element name="notachair" type="tns:ItemType"/> - * - * @return - */ - public NotachairDocument getNotaChairDoc() - { - xmlobject.substgroup.NotachairDocument nochair = NotachairDocument.Factory.newInstance(); - ItemType item = nochair.addNewNotachair(); - item.setName("NotAChair"); - item.setSku(new BigInteger("12")); - nochair.setNotachair(item); - return nochair; - } - - /** - * Convenience Method to return: - * <xsd:complexType name="BeanBagType"> - * <xsd:complexContent> - * <xsd:extension base="tns:ItemType"> - * <xsd:sequence> - * <xsd:element name="size" type="tns:BeanBagSizeType"/> - * </xsd:sequence> - * </xsd:extension> - * </xsd:complexContent> - * </xsd:complexType> - * - * @return - */ - public BeanBagType getBeanBagType() - { - xmlobject.substgroup.BeanBagType bag = BeanBagType.Factory.newInstance(); - BeanBagSizeType size = bag.addNewSize(); - size.setColor("Blue"); - bag.setSize(size); - bag.setName("BeanBagType"); - bag.setSku(new BigInteger("17")); - return bag; - } - - /** - * Convenience Method to return: - * <xsd:element name="beanBag" type="tns:BeanBagType" - * substitutionGroup="tns:item"/> - * - * @return - */ - public BeanBagDocument getBeanBagDoc() - { - xmlobject.substgroup.BeanBagDocument bean = BeanBagDocument.Factory.newInstance(); - BeanBagType item = bean.addNewBeanBag(); - item.setName("BeanBagDoc"); - item.setSku(new BigInteger("13")); - BeanBagSizeType size = item.addNewSize(); - size.setColor("Blue"); - item.setSize(size); - bean.setBeanBag(item); - return bean; - } - - /** - * Convenience Method to return: - * <xsd:element name="beanBag" type="tns:BeanBagType" - * substitutionGroup="tns:item"/> - * - * @return - */ - public BeanBagDocument getBeanBagDocItem() - { - xmlobject.substgroup.BeanBagDocument bean = BeanBagDocument.Factory.newInstance(); - ItemType item = bean.addNewItem(); - item.setName("BeanBagDocItem"); - item.setSku(new BigInteger("14")); - bean.setItem(item); - return bean; - } - - /** - * Convenience Method to return: - * <xsd:element name="beanBag" type="tns:BeanBagType" - * substitutionGroup="tns:item"/> - * - * @return - */ - public BeanBagDocument getBeanBagDocBagType() - { - xmlobject.substgroup.BeanBagDocument bean = BeanBagDocument.Factory.newInstance(); - ItemType item = bean.addNewBeanBag(); - item.setName("BeanBagDocBeanBag"); - item.setSku(new BigInteger("14")); - bean.setItem(item); - return bean; - } - - /** - * Convenience Method to return: - * <xsd:element name="footstool" type="xsd:string"/> * - * - * @return - */ - public FootstoolDocument getFootStoolDoc() - { - xmlobject.substgroup.FootstoolDocument foot = FootstoolDocument.Factory.newInstance(); - foot.setFootstool("FootStool"); - return foot; - } +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +public class SubstGroupTests { /** * TODO: Determine what the proper Return value is - * - * @throws Exception */ - public void test_invalidSubstitute() throws Exception - { + @Test + public void test_invalidSubstitute() { OrderItem order = OrderItem.Factory.newInstance(); ItemType item = order.addNewItem(); item.setName("ItemType"); item.setSku(new BigInteger("42")); //FootstoolDocument fsd; - boolean cClassException = false; try { //on invalid substitute orignal value is returned. FootstoolDocument fsd = (FootstoolDocument) item.substitute( - FootstoolDocument.type.getDocumentElementName(), - FootstoolDocument.type); + FootstoolDocument.type.getDocumentElementName(), + FootstoolDocument.type); fail("Class Cast Exception was thrown on invalid substitute "); - - } catch (ClassCastException ccEx) { - cClassException = true; } - if (!cClassException) - throw new Exception("An Invalid Substitution did not throw " + - "a Class Cast Exception"); + XmlObject xm = item.substitute( + FootstoolDocument.type.getDocumentElementName(), + FootstoolDocument.type); - try { - XmlObject xm = item.substitute( - FootstoolDocument.type.getDocumentElementName(), - FootstoolDocument.type); - - System.out.println("XM: " + xm.xmlText()); - ArrayList err = new ArrayList(); - XmlOptions xOpts = new XmlOptions().setErrorListener(err); - //no way this should happen - if (xm.validate(xOpts)) { - System.err.println("Invalid substitute validated"); - - for (Iterator iterator = err.iterator(); iterator.hasNext();) { - System.err.println("Error: " + iterator.next()); - } - } + System.out.println("XM: " + xm.xmlText()); + ArrayList err = new ArrayList(); + XmlOptions xOpts = new XmlOptions().setErrorListener(err); + //no way this should happen + if (xm.validate(xOpts)) { + System.err.println("Invalid substitute validated"); - //invalid substitute should leave good state - System.out.println("Item: " + item.xmlText()); + for (Iterator iterator = err.iterator(); iterator.hasNext(); ) { + System.err.println("Error: " + iterator.next()); + } + } - String exp = "<xml-fragment><sku>42</sku><name>ItemType</name></xml-fragment>"; + //invalid substitute should leave good state + System.out.println("Item: " + item.xmlText()); - Assert.assertTrue("text values should be the same", - exp.compareTo(xm.xmlText()) == 0); + String exp = "<xml-fragment><sku>42</sku><name>ItemType</name></xml-fragment>"; - } catch (Exception e) { - throw e; - } + assertEquals("text values should be the same", 0, exp.compareTo(xm.xmlText())); } - public void test_validSubstitute() throws Exception - { + @Test(expected = XmlValueDisconnectedException.class) + public void test_validSubstitute() { + String URI = "http://xmlobject/substgroup"; QName name = new QName(URI, "beanBag"); // get an item xmlobject.substgroup.OrderItem order = OrderItem.Factory.newInstance(); @@ -275,83 +94,31 @@ public class SubstGroupTests extends Tes System.out.println("item type:" + item.getClass().getName()); System.out.println("item XMLText : " + item.xmlText()); - try{ + try { XmlObject xObj = item.substitute(name, BeanBagType.type); - System.out.println("After Substitution :\nSubstituted XObj text: "+xObj.xmlText()); + System.out.println("After Substitution :\nSubstituted XObj text: " + xObj.xmlText()); System.out.println("Substituted XObj type: " + xObj.getClass().getName()); - Assert.assertNotSame("Invalid Substitution. Xobj Types after substitution are the same.",xObj.getClass().getName(),item.getClass().getName() ); + Assert.assertNotSame("Invalid Substitution. Xobj Types after substitution are the same.", xObj.getClass().getName(), item.getClass().getName()); - }catch(NullPointerException npe){ - System.out.println("NPE Thrown: "+npe.getMessage()); + } catch (NullPointerException npe) { + System.out.println("NPE Thrown: " + npe.getMessage()); npe.printStackTrace(); } - boolean xvdThrown = false; - try{ - // invoke some operation on the original XmlObject, it should thrown an XmlValueDisconnectedException - item.xmlText(); - }catch(XmlValueDisconnectedException xvdEx){ - xvdThrown = true; - } - - if( !xvdThrown ){ - Assert.fail("Referencing Item after " + - "substitute did not throw the expected XmlValueDisconnectedException"); - } - + // invoke some operation on the original XmlObject, it should thrown an XmlValueDisconnectedException + item.xmlText(); } - /* public void test_item_downcasts_valid() throws Exception - { - BigInteger bInt = new BigInteger("12"); - - xmlobject.substgroup.OrderItem order = OrderItem.Factory.newInstance(); - ItemType item = order.addNewItem(); - - BeanBagType b2Type = (BeanBagType) item.substitute( - BeanBagDocument.type.getDocumentElementName(), - BeanBagType.type); - - BeanBagSizeType bbSize = b2Type.addNewSize(); - bbSize.setColor("Blue"); - bbSize.setStringValue("Blue"); - b2Type.setSku(bInt); - b2Type.setSize(bbSize); - b2Type.setName("BeanBagType"); - - ItemType nItem = order.getItem(); - item = - (ItemType) nItem.substitute( - ItemDocument.type.getDocumentElementName(), - ItemType.type); - System.out.println( - "Item: " + item.xmlText(new XmlOptions().setSavePrettyPrint())); - ArrayList err = new ArrayList(); - XmlOptions opts = new XmlOptions( - new XmlOptions().setErrorListener(err)); - - if (!item.validate(opts)) - throw new Exception("Downcasting Failed Validation:\n" + err); - - item.setName("ItemType"); - - if (!order.validate(opts)) - throw new Exception("Downcasting Failed Validation:\n" + err); - - }*/ - /** * Tests substition upcase, from item to Document, then ensure validation - * - * @throws Exception */ - public void test_valid_sub() throws Exception - { + @Test + public void test_valid_sub() throws Exception { String expectedXML = "<sub:beanBag xmlns:sub=\"http://xmlobject/substgroup\">" + - " <sku>12</sku>" + - " <name>BeanBagType</name>" + - " <size color=\"Blue\">Blue</size>" + - "</sub:beanBag>"; + " <sku>12</sku>" + + " <name>BeanBagType</name>" + + " <size color=\"Blue\">Blue</size>" + + "</sub:beanBag>"; XmlObject xm = XmlObject.Factory.parse(expectedXML); String itemName = "item"; BigInteger bInt = new BigInteger("12"); @@ -362,20 +129,18 @@ public class SubstGroupTests extends Tes item.setSku(bInt); System.out.println("Order: " + - order.xmlText(new XmlOptions().setSavePrettyPrint())); + order.xmlText(new XmlOptions().setSavePrettyPrint())); System.out.println("valid: " + order.validate()); BeanBagType b2Type = (BeanBagType) item.substitute( - BeanBagDocument.type.getDocumentElementName(), - BeanBagType.type); + BeanBagDocument.type.getDocumentElementName(), + BeanBagType.type); - Assert.assertTrue("Name Value was not as expected\nactual: " + - b2Type.getName() + - " exp: " + - itemName, - b2Type.getName().compareTo(itemName) == 0); - Assert.assertTrue("Integer Value was not as Excepted", - b2Type.getSku().compareTo(bInt) == 0); + assertEquals("Name Value was not as expected\nactual: " + + b2Type.getName() + + " exp: " + + itemName, 0, b2Type.getName().compareTo(itemName)); + assertEquals("Integer Value was not as Excepted", 0, b2Type.getSku().compareTo(bInt)); BeanBagSizeType bbSize = b2Type.addNewSize(); bbSize.setColor("Blue"); @@ -384,23 +149,22 @@ public class SubstGroupTests extends Tes b2Type.setName("BeanBagType"); System.out.println("b2Type: " + - b2Type.xmlText(new XmlOptions().setSavePrettyPrint())); + b2Type.xmlText(new XmlOptions().setSavePrettyPrint())); System.out.println("b2Type: " + b2Type.validate()); System.out.println("Order: " + - order.xmlText(new XmlOptions().setSavePrettyPrint())); + order.xmlText(new XmlOptions().setSavePrettyPrint())); System.out.println("ovalid: " + order.validate()); tools.xml.XmlComparator.Diagnostic diag = new tools.xml.XmlComparator.Diagnostic(); if (!XmlComparator.lenientlyCompareTwoXmlStrings(order.xmlText(), - xm.xmlText(), diag)) + xm.xmlText(), diag)) throw new Exception("Compare Values Fails\n" + diag.toString()); } - - public void test_item_disconnect() throws Exception - { + @Test(expected = XmlValueDisconnectedException.class) + public void test_item_disconnect() { String itemName = "item"; BigInteger bInt = new BigInteger("12"); boolean exThrown = false; @@ -411,43 +175,29 @@ public class SubstGroupTests extends Tes item.setSku(bInt); System.out.println("Order: " + - order.xmlText(new XmlOptions().setSavePrettyPrint())); + order.xmlText(new XmlOptions().setSavePrettyPrint())); System.out.println("valid: " + order.validate()); BeanBagType b2Type = (BeanBagType) item.substitute( - BeanBagDocument.type.getDocumentElementName(), - BeanBagType.type); - - try { - System.out.println("This should Fail: " + item.xmlText()); - System.out.println("This should Fail: " + item.validate()); - } catch (XmlValueDisconnectedException xmvEx) { - exThrown = true; - System.err.println( - "Failed as Expected - message: " + xmvEx.getMessage()); - } catch (Exception e) { - throw e; - } + BeanBagDocument.type.getDocumentElementName(), + BeanBagType.type); - if (!exThrown) - throw new Exception( - "Value Disconnect Exception was not thrown as Expected"); + item.xmlText(); } - - public void test_item_downcasts_valid() throws Exception - { + @Test + public void test_item_downcasts_valid() throws Exception { BigInteger bInt = new BigInteger("12"); ArrayList err = new ArrayList(); XmlOptions opts = new XmlOptions( - new XmlOptions().setErrorListener(err)); + new XmlOptions().setErrorListener(err)); xmlobject.substgroup.OrderItem order = OrderItem.Factory.newInstance(); ItemType item = order.addNewItem(); BeanBagType b2Type = (BeanBagType) item.substitute( - BeanBagDocument.type.getDocumentElementName(), - BeanBagType.type); + BeanBagDocument.type.getDocumentElementName(), + BeanBagType.type); BeanBagSizeType bbSize = b2Type.addNewSize(); bbSize.setColor("Blue"); @@ -461,12 +211,12 @@ public class SubstGroupTests extends Tes //nItem.validate(opts); if (!nItem.validate(opts)) System.out.println( - "nItem - Downcasting Failed Validation:\n" + err); + "nItem - Downcasting Failed Validation:\n" + err); err.clear(); item = (ItemType) nItem.substitute( - ItemDocument.type.getDocumentElementName(), - ItemType.type); + ItemDocument.type.getDocumentElementName(), + ItemType.type); //System.out.println("Item1: " + item.xmlText()); @@ -474,10 +224,8 @@ public class SubstGroupTests extends Tes System.out.println("Item - Downcasting Failed Validation:\n" + err); XmlError[] xErr = getXmlErrors(err); - Assert.assertTrue("Length of xm_errors was greater than expected", - xErr.length == 1); - Assert.assertTrue("Error Code was not as Expected", - xErr[0].getErrorCode().compareTo("cvc-complex-type.2.4b") == 0); + assertEquals("Length of xm_errors was greater than expected", 1, xErr.length); + assertEquals("Error Code was not as Expected", 0, xErr[0].getErrorCode().compareTo("cvc-complex-type.2.4b")); err.clear(); String nName = "ItemType"; @@ -486,7 +234,7 @@ public class SubstGroupTests extends Tes if (!order.validate(opts)) System.out.println( - "Order - Downcasting Failed Validation:\n" + err); + "Order - Downcasting Failed Validation:\n" + err); //Check value was set if (!(nName.compareTo(order.getItem().getName()) == 0)) @@ -495,19 +243,14 @@ public class SubstGroupTests extends Tes //Check Error message String expText = "Element not allowed: size in element item@http://xmlobject/substgroup"; XmlError[] xErr2 = getXmlErrors(err); - Assert.assertTrue("Length of xm_errors was greater than expected", - xErr2.length == 1); - Assert.assertTrue("Error Code was not as Expected", - xErr2[0].getErrorCode().compareTo("cvc-complex-type.2.4b") == - 0); - Assert.assertTrue("Error Message was not as expected", - xErr2[0].getMessage().compareTo(expText) == 0); + assertEquals("Length of xm_errors was greater than expected", 1, xErr2.length); + assertEquals("Error Code was not as Expected", 0, xErr2[0].getErrorCode().compareTo("cvc-complex-type.2.4b")); + assertEquals("Error Message was not as expected", 0, xErr2[0].getMessage().compareTo(expText)); err.clear(); } - private XmlError[] getXmlErrors(ArrayList c) - { + private XmlError[] getXmlErrors(ArrayList c) { XmlError[] errs = new XmlError[c.size()]; for (int i = 0; i < errs.length; i++) { errs[i] = (XmlError) c.get(i); @@ -515,78 +258,35 @@ public class SubstGroupTests extends Tes return errs; } - public void test_null_newName() throws Exception - { - boolean exThrown = false; - try { - xmlobject.substgroup.OrderItem order = OrderItem.Factory.newInstance(); - order.substitute(null, OrderItem.type); - } catch (IllegalArgumentException iaEx) { - exThrown = true; - } - if (exThrown != true) - throw new Exception("Exception was not thrown"); + @Test(expected = IllegalArgumentException.class) + public void test_null_newName() { + xmlobject.substgroup.OrderItem order = OrderItem.Factory.newInstance(); + order.substitute(null, OrderItem.type); } - public void test_null_newType() throws Exception - { - boolean exThrown = false; - try { - OrderItem order = OrderItem.Factory.newInstance(); - order.substitute(OrderItem.type.getDocumentElementName(), null); - - } catch (IllegalArgumentException iaEx) { - exThrown = true; - } catch (Exception e) { - throw e; - } - - if (exThrown != true) - throw new Exception("Exception was not thrown"); + @Test(expected = IllegalArgumentException.class) + public void test_null_newType() { + OrderItem order = OrderItem.Factory.newInstance(); + order.substitute(OrderItem.type.getDocumentElementName(), null); } - public void test_unknownQName() throws Exception - { - boolean exThrown = false; + @Test + public void test_unknownQName() { QName exp = new QName("http://www.w3.org/2001/XMLSchema", "anyType"); - try { - OrderItem order = OrderItem.Factory.newInstance(); - XmlObject xm = order.substitute(new QName("http://baz", "baz"), - OrderItem.type); - - //Verify that the invalid substitution results in an anyType - Assert.assertTrue("Namespace URIs were not the same", - exp.getNamespaceURI().compareTo( - xm.type.getName().getNamespaceURI()) == 0); - Assert.assertTrue("Local Part was not as Expected", - xm.type.getName().getLocalPart().compareTo( - exp.getLocalPart()) == 0); - - } catch (IllegalArgumentException iaEx) { - exThrown = true; - } catch (Exception e) { - throw e; - } + OrderItem order = OrderItem.Factory.newInstance(); + XmlObject xm = order.substitute(new QName("http://baz", "baz"), + OrderItem.type); - if (exThrown == true) - throw new Exception("Exception was not thrown"); + //Verify that the invalid substitution results in an anyType + assertEquals("Namespace URIs were not the same", 0, exp.getNamespaceURI().compareTo( + xm.type.getName().getNamespaceURI())); + assertEquals("Local Part was not as Expected", 0, xm.type.getName().getLocalPart().compareTo( + exp.getLocalPart())); } - public void test_null_Params() throws Exception - { - boolean exThrown = false; - try { - XmlObject xml = XmlObject.Factory.newInstance(); - xml.substitute(null, null); - } catch (IllegalArgumentException iaEx) { - exThrown = true; - } catch (Exception e) { - throw e; - } - - if (exThrown != true) - throw new Exception("Exception was not thrown"); + @Test(expected = IllegalArgumentException.class) + public void test_null_Params() { + XmlObject xml = XmlObject.Factory.newInstance(); + xml.substitute(null, null); } - - } Modified: xmlbeans/trunk/test/src/xmlobject/detailed/TestXmlReader.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/detailed/TestXmlReader.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/detailed/TestXmlReader.java (original) +++ xmlbeans/trunk/test/src/xmlobject/detailed/TestXmlReader.java Fri Jan 18 23:08:44 2019 @@ -15,39 +15,20 @@ package xmlobject.detailed; -import junit.framework.TestCase; - -import java.io.File; -import java.io.IOException; -import java.io.FileReader; -import java.io.PrintWriter; - -import tools.util.ResourceUtil; +import org.junit.Test; import tools.util.JarUtil; - -import org.apache.xmlbeans.XmlBeans; -import org.apache.xmlbeans.XmlObject; -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.XmlCursor.TokenType; -import xmlcursor.common.Common; import xmlobject.common.StringXmlReader; +import static org.junit.Assert.assertTrue; -/** - * - * - */ -public class TestXmlReader extends TestCase { - public TestXmlReader(String name) { - super(name); - } +public class TestXmlReader { /** * Tests read-only concurrency support in XML Beans * See Radar Bug: 33254 */ + @Test public void testConcurrency() throws Exception { // Get the file contents String xmlFile = JarUtil.getResourceFromJar("xbean/xmlcursor/po.xml"); @@ -73,10 +54,4 @@ public class TestXmlReader extends TestC assertTrue("Concurrency Test Failed.", status); } - - - public static void main(String args[]) throws Exception { - new TestXmlReader("Test").testConcurrency(); - } - } \ No newline at end of file Modified: xmlbeans/trunk/test/src/xmlobject/detailed/TestsFromBugs.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/detailed/TestsFromBugs.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/detailed/TestsFromBugs.java (original) +++ xmlbeans/trunk/test/src/xmlobject/detailed/TestsFromBugs.java Fri Jan 18 23:08:44 2019 @@ -15,77 +15,76 @@ package xmlobject.detailed; -import org.apache.xmlbeans.*; import com.mytest.Bar; import com.mytest.Foo; import com.mytest.Info; import com.mytest.TestDocument; +import org.apache.xmlbeans.*; +import org.junit.Test; import test.xmlobject.test36510.Test36510AppDocument; -import junit.framework.TestCase; import java.io.File; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Test file that implements test cases that come from closing bugs. */ -public class TestsFromBugs extends TestCase -{ +public class TestsFromBugs { File instance; - public TestsFromBugs(String name) - { - super(name); - } - /** * Radar Bug: 36156 * Problem with Namespace leaking into siblings */ + @Test public void test36156() - throws Exception - { + throws Exception { String str = "<x><y xmlns=\"bar\"><z xmlns=\"foo\"/></y><a/></x>"; XmlObject x = XmlObject.Factory.parse(str); - assertTrue("Test 36156 failed: ", x.xmlText().equals(str)); + assertEquals("Test 36156 failed: ", x.xmlText(), str); } /* * Radar Bug: 36510 */ + @Test public void test36510() - throws Exception - { - String str = "<test36510-app version='1.0' " + - "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" + - " xsi:schemaLocation='http://test/xmlobject/test36510' " + - "xmlns='http://test/xmlobject/test36510'>" + - "<testConstraint>" + - "<customConstraint>" + - "<description>These portlets don't" + - " require any guarantee</description>" + - "<options>BEST</options>" + - "</customConstraint></testConstraint>" + - "</test36510-app>"; + throws Exception { + String str = + "<test36510-app version='1.0' " + + "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" + + " xsi:schemaLocation='http://test/xmlobject/test36510' " + + "xmlns='http://test/xmlobject/test36510'>" + + "<testConstraint>" + + "<customConstraint>" + + "<description>These portlets don't" + + " require any guarantee</description>" + + "<options>BEST</options>" + + "</customConstraint></testConstraint>" + + "</test36510-app>"; Test36510AppDocument doc = Test36510AppDocument.Factory.parse(str); str = doc.getTest36510App().getTestConstraintArray()[0]. - getCustomConstraint().getOptions().toString(); - assertTrue("Test 36510 failed: ", str.equals("BEST")); + getCustomConstraint().getOptions().toString(); + assertEquals("Test 36510 failed: ", "BEST", str); } /* * Radar Bug: 40907 */ + @Test public void test40907() - throws Exception - { - String str = "<myt:Test xmlns:myt=\"http://www.mytest.com\">" + - "<myt:foo>" + - "<myt:fooMember>this is foo member</myt:fooMember>" + - "</myt:foo>" + - "</myt:Test>"; + throws Exception { + String str = + "<myt:Test xmlns:myt=\"http://www.mytest.com\">" + + "<myt:foo>" + + "<myt:fooMember>this is foo member</myt:fooMember>" + + "</myt:foo>" + + "</myt:Test>"; TestDocument doc = TestDocument.Factory.parse(str); assertTrue("XML Instance did not validate.", doc.validate()); @@ -101,57 +100,57 @@ public class TestsFromBugs extends TestC assertTrue("Modified XML instance did not validate.", doc.validate()); str = "<myt:Test xmlns:myt=\"http://www.mytest.com\">" + - "<myt:foo>" + - "<myt:fooMember>this is foo member</myt:fooMember>" + - "</myt:foo>" + - "<myt:foo xsi:type=\"myt:bar\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + - "<myt:fooMember>new foo member</myt:fooMember>" + - "<myt:barMember>new bar member</myt:barMember>" + - "</myt:foo>" + - "</myt:Test>"; + "<myt:foo>" + + "<myt:fooMember>this is foo member</myt:fooMember>" + + "</myt:foo>" + + "<myt:foo xsi:type=\"myt:bar\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + + "<myt:fooMember>new foo member</myt:fooMember>" + + "<myt:barMember>new bar member</myt:barMember>" + + "</myt:foo>" + + "</myt:Test>"; assertEquals("XML instance is not as expected", doc.xmlText(), str); } /** * Simple Compilation Tests - If the methods are not present, - * - this class won't compile + * - this class won't compile * Ensures method getSourceName is on SchemaComponent and * can be called from SchemaGlobalElement and SchemaGlobalAttribute - * @throws Exception */ - public void test199585() throws Exception - { - String str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + - "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" + - " targetNamespace=\"urn:lax.Doc.Compilation\"\n" + - " xmlns:tns=\"urn:lax.Doc.Compilation\"\n" + - " xmlns:pre=\"noResolutionNamespace\"\n" + - " elementFormDefault=\"qualified\"\n" + - " attributeFormDefault=\"unqualified\">\n" + - " <xs:element name=\"QuantityElement\" type=\"tns:quantity\" />"+ - " <xs:simpleType name=\"quantity\">\n" + - " <xs:restriction base=\"xs:NMTOKEN\">\n" + - " <xs:enumeration value=\"all\"/>\n" + - " <xs:enumeration value=\"most\"/>\n" + - " <xs:enumeration value=\"some\"/>\n" + - " <xs:enumeration value=\"few\"/>\n" + - " <xs:enumeration value=\"none\"/>\n" + - " </xs:restriction>\n" + - " </xs:simpleType>" + - "</xs:schema>"; + @Test + public void test199585() throws Exception { + String str = + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" + + " targetNamespace=\"urn:lax.Doc.Compilation\"\n" + + " xmlns:tns=\"urn:lax.Doc.Compilation\"\n" + + " xmlns:pre=\"noResolutionNamespace\"\n" + + " elementFormDefault=\"qualified\"\n" + + " attributeFormDefault=\"unqualified\">\n" + + " <xs:element name=\"QuantityElement\" type=\"tns:quantity\" />" + + " <xs:simpleType name=\"quantity\">\n" + + " <xs:restriction base=\"xs:NMTOKEN\">\n" + + " <xs:enumeration value=\"all\"/>\n" + + " <xs:enumeration value=\"most\"/>\n" + + " <xs:enumeration value=\"some\"/>\n" + + " <xs:enumeration value=\"few\"/>\n" + + " <xs:enumeration value=\"none\"/>\n" + + " </xs:restriction>\n" + + " </xs:simpleType>" + + "</xs:schema>"; XmlObject[] schemas = new XmlObject[]{ XmlObject.Factory.parse(str)}; XmlOptions xOpt = new XmlOptions().setValidateTreatLaxAsSkip(); SchemaTypeSystem sts = XmlBeans.compileXmlBeans(null, null, schemas, - null, XmlBeans.getBuiltinTypeSystem(), null, xOpt); + null, XmlBeans.getBuiltinTypeSystem(), null, xOpt); //ensure SchemaGlobalElement has getSourceName Method SchemaGlobalElement[] sge = sts.globalElements(); for (int i = 0; i < sge.length; i++) { - System.out.println("SGE SourceName: "+sge[i].getSourceName()); + System.out.println("SGE SourceName: " + sge[i].getSourceName()); } //ensure SchemaGlobalAttribute has getSourceName Method @@ -172,9 +171,5 @@ public class TestsFromBugs extends TestC for (int i = 0; i < sca.length; i++) { System.out.println("SCA SourceName: " + sca[i].getSourceName()); } - - - } - } Modified: xmlbeans/trunk/test/src/xmlobject/detailed/TypedObjectCursor.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/detailed/TypedObjectCursor.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/detailed/TypedObjectCursor.java (original) +++ xmlbeans/trunk/test/src/xmlobject/detailed/TypedObjectCursor.java Fri Jan 18 23:08:44 2019 @@ -12,44 +12,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package xmlobject.detailed; +package xmlobject.detailed; -import xmlcursor.common.BasicCursorTestCase; -import xmlcursor.detailed.*; -import junit.framework.Test; -import junit.framework.TestSuite; -import junit.framework.TestCase; -import com.easypo.XmlPurchaseOrderDocumentBean; import com.easypo.XmlCustomerBean; +import com.easypo.XmlPurchaseOrderDocumentBean; import org.apache.xmlbeans.XmlCursor; +import org.junit.Test; -public class TypedObjectCursor extends TestCase{ - public TypedObjectCursor(String name){ - super(name); - } - public static Test suite() { - return new TestSuite(TypedObjectCursor.class); - } +import static org.junit.Assert.assertEquals; - public void testObjectCursor(){ - XmlPurchaseOrderDocumentBean.PurchaseOrder po= XmlPurchaseOrderDocumentBean.PurchaseOrder.Factory.newInstance(); - XmlCursor cur=po.newCursor(); - XmlCustomerBean cust=po.addNewCustomer(); - cust.setAddress("123 Fake Street"); - cust.setAge(23); - cust.setName("Lisa Simpson"); - cur.toFirstContentToken(); - assertEquals(XmlCursor.TokenType.START, cur.currentTokenType()); - assertEquals(XmlCursor.TokenType.ATTR,cur.toNextToken()); +public class TypedObjectCursor { + + @Test + public void testObjectCursor() { + XmlPurchaseOrderDocumentBean.PurchaseOrder po = XmlPurchaseOrderDocumentBean.PurchaseOrder.Factory.newInstance(); + XmlCursor cur = po.newCursor(); + XmlCustomerBean cust = po.addNewCustomer(); + cust.setAddress("123 Fake Street"); + cust.setAge(23); + cust.setName("Lisa Simpson"); + cur.toFirstContentToken(); + assertEquals(XmlCursor.TokenType.START, cur.currentTokenType()); + assertEquals(XmlCursor.TokenType.ATTR, cur.toNextToken()); assertEquals("<xml-fragment age=\"23\"/>", cur.xmlText()); - assertEquals(XmlCursor.TokenType.START,cur.toNextToken()); - assertEquals(XmlCursor.TokenType.TEXT,cur.toNextToken()); + assertEquals(XmlCursor.TokenType.START, cur.toNextToken()); + assertEquals(XmlCursor.TokenType.TEXT, cur.toNextToken()); assertEquals("<xml-fragment>Lisa Simpson</xml-fragment>", cur.xmlText()); - assertEquals(XmlCursor.TokenType.END,cur.toNextToken()); - assertEquals(XmlCursor.TokenType.START,cur.toNextToken()); - assertEquals(XmlCursor.TokenType.TEXT,cur.toNextToken()); + assertEquals(XmlCursor.TokenType.END, cur.toNextToken()); + assertEquals(XmlCursor.TokenType.START, cur.toNextToken()); + assertEquals(XmlCursor.TokenType.TEXT, cur.toNextToken()); assertEquals("<xml-fragment>123 Fake Street</xml-fragment>", cur.xmlText()); cur.toPrevToken(); - cur.setTextValue("456".toCharArray(),0,3); -} + cur.setTextValue("456".toCharArray(), 0, 3); + } } Modified: xmlbeans/trunk/test/src/xmlobject/detailed/TypedSettersTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/detailed/TypedSettersTests.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/detailed/TypedSettersTests.java (original) +++ xmlbeans/trunk/test/src/xmlobject/detailed/TypedSettersTests.java Fri Jan 18 23:08:44 2019 @@ -15,122 +15,90 @@ package xmlobject.detailed; -import org.apache.xmlbeans.XmlCursor.TokenType; -import org.apache.xmlbeans.XmlCursor.XmlBookmark; +import org.junit.Assert; import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlSaxHandler; -import org.apache.xmlbeans.XmlLineNumber; -import org.apache.xmlbeans.XmlBeans; +import org.apache.xmlbeans.XmlInt; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; -import org.apache.xmlbeans.XmlInt; -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.io.StringReader; -import java.lang.Comparable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Random; -import java.util.Iterator; -import java.util.TreeSet; -import javax.xml.namespace.QName; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import junit.framework.Assert; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - - -public class TypedSettersTests extends TestCase -{ - public TypedSettersTests(String name) { super(name); } - public static Test suite() { return new TestSuite(TypedSettersTests.class); } +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + - private static final String schemaNs ="xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""; +public class TypedSettersTests { + private static final String schemaNs = "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""; private static final String instanceNs = "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""; - private static final String fmt ( String s ) - { - StringBuffer sb = new StringBuffer(); - - for ( int i = 0 ; i < s.length() ; i++ ) - { - char ch = s.charAt( i ); - - if (ch != '$') - { - sb.append( ch ); + private static String fmt(String s) { + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < s.length(); i++) { + char ch = s.charAt(i); + + if (ch != '$') { + sb.append(ch); continue; } - - ch = s.charAt( ++i ); + + ch = s.charAt(++i); String id = ""; - while ( (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) - { + while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { id = id + ch; - ch = s.charAt( ++i ); + ch = s.charAt(++i); } String arg = ""; - if (ch == '(') - { - ch = s.charAt( ++i ); + if (ch == '(') { + ch = s.charAt(++i); - while ( ch != ')' ) - { + while (ch != ')') { arg += ch; - ch = s.charAt( ++i ); + ch = s.charAt(++i); } - } - else + } else i--; - if (id.equals( "schema" )) - sb.append( schemaNs ); - else if (id.equals( "xsi" )) - sb.append( instanceNs ); - else if (id.equals( "type" )) - { - Assert.assertTrue( arg.length() > 0 ); - sb.append( "xsi:type=\"" + arg + "\"" ); - } - else - Assert.assertTrue( false ); + if (id.equals("schema")) + sb.append(schemaNs); + else if (id.equals("xsi")) + sb.append(instanceNs); + else if (id.equals("type")) { + Assert.assertTrue(arg.length() > 0); + sb.append("xsi:type=\"" + arg + "\""); + } else + Assert.fail(); } return sb.toString(); } private static final String nses = schemaNs + " " + instanceNs; - - public void testJavaNoTypeSingletonElement ( ) - throws Exception - { - XmlObject x = XmlObject.Factory.parse( "<xyzzy/>" ); - XmlObject x2 = XmlObject.Factory.parse( "<bubba>moo</bubba>" ); + + @Test + public void testJavaNoTypeSingletonElement() + throws Exception { + XmlObject x = XmlObject.Factory.parse("<xyzzy/>"); + XmlObject x2 = XmlObject.Factory.parse("<bubba>moo</bubba>"); XmlCursor c = x.newCursor(); XmlCursor c2 = x2.newCursor(); c.toNextToken(); c2.toNextToken(); - c.getObject().set( c2.getObject() ); + c.getObject().set(c2.getObject()); - Assert.assertTrue( x.xmlText().equals( "<xyzzy>moo</xyzzy>" ) ); + assertEquals("<xyzzy>moo</xyzzy>", x.xmlText()); } - - public void testJavaNoTypeSingletonAttribute ( ) - throws Exception - { - XmlObject x = XmlObject.Factory.parse( "<xyzzy a=''/>" ); - XmlObject x2 = XmlObject.Factory.parse( "<bubba b='moo'/>" ); + + @Test + public void testJavaNoTypeSingletonAttribute() + throws Exception { + XmlObject x = XmlObject.Factory.parse("<xyzzy a=''/>"); + XmlObject x2 = XmlObject.Factory.parse("<bubba b='moo'/>"); XmlCursor c = x.newCursor(); XmlCursor c2 = x2.newCursor(); @@ -139,26 +107,24 @@ public class TypedSettersTests extends T c2.toNextToken(); c2.toNextToken(); - c.getObject().set( c2.getObject() ); + c.getObject().set(c2.getObject()); - Assert.assertTrue( x.xmlText().equals( "<xyzzy a=\"moo\"/>" ) ); + assertEquals("<xyzzy a=\"moo\"/>", x.xmlText()); } - - public void testJavaNoTypeSingletonElementWithXsiType ( ) - throws Exception - { - XmlObject x = XmlObject.Factory.parse( "<xyzzy/>", new XmlOptions() - .setDocumentType( XmlObject.type ) ); - String input= fmt( "<xml-fragment $type(xs:int) $xsi $schema>" + - "69</xml-fragment>" ); + + @Test + public void testJavaNoTypeSingletonElementWithXsiType() + throws Exception { + XmlObject x = XmlObject.Factory.parse("<xyzzy/>", new XmlOptions() + .setDocumentType(XmlObject.type)); + String input = fmt("<xml-fragment $type(xs:int) $xsi $schema>" + + "69</xml-fragment>"); //String input= - XmlObject x2 = XmlObject.Factory - .parse( input ); + XmlObject x2 = XmlObject.Factory.parse(input); + assertSame(x2.schemaType(), XmlInt.type); - Assert.assertTrue(x2.schemaType() == XmlInt.type ); + } - } - } Modified: xmlbeans/trunk/test/src/xmlobject/detailed/TypesTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/detailed/TypesTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/detailed/TypesTest.java (original) +++ xmlbeans/trunk/test/src/xmlobject/detailed/TypesTest.java Fri Jan 18 23:08:44 2019 @@ -16,41 +16,22 @@ package xmlobject.detailed; -import junit.framework.*; - -import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.SchemaType; import org.apache.xmlbeans.SimpleValue; - -import javax.xml.namespace.QName; - -import xmlcursor.common.*; - +import org.apache.xmlbeans.XmlObject; +import org.junit.Test; import test.xbean.xmlcursor.purchaseOrder.PurchaseOrderDocument; import tools.util.JarUtil; +import xmlcursor.common.BasicCursorTestCase; +import xmlcursor.common.Common; +import javax.xml.namespace.QName; -/** - * - * - */ -public class TypesTest extends BasicCursorTestCase { - public TypesTest(String sName) { - super(sName); - } - - public static Test suite() { - return new TestSuite(TypesTest.class); - } +import static org.junit.Assert.*; - public void testClassPath() throws Exception { - String sClassPath = System.getProperty("java.class.path"); - int i = sClassPath.indexOf(Common.CARLOCATIONMESSAGE_JAR); - assertTrue(i >= 0); - i = sClassPath.indexOf(Common.XMLCURSOR_JAR); - assertTrue(i >= 0); - } +public class TypesTest extends BasicCursorTestCase { + @Test public void testSchemaTypeFromStronglyTypedBuiltIn() throws Exception { m_xo = XmlObject.Factory.parse( JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM)); @@ -66,6 +47,7 @@ public class TypesTest extends BasicCurs q.toString()); } + @Test public void testSchemaTypeFromStronglyTyped() throws Exception { m_xo = XmlObject.Factory.parse( JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM)); @@ -83,6 +65,7 @@ public class TypesTest extends BasicCurs } + @Test public void testSchemaTypeFromNonTyped() throws Exception { m_xo = XmlObject.Factory.parse(Common.XML_FOO_BAR_TEXT); m_xc = m_xo.newCursor(); @@ -94,7 +77,7 @@ public class TypesTest extends BasicCurs //assertEquals("TanyType@" + Common.XML_SCHEMA_TYPE_SUFFIX, st.toString()); } - + @Test public void testInstanceTypeNotNillable() throws Exception { m_xo = XmlObject.Factory.parse( JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM)); @@ -105,6 +88,7 @@ public class TypesTest extends BasicCurs assertEquals(xo.schemaType(), ((SimpleValue) xo).instanceType()); } + @Test public void testInstanceTypeNil() throws Exception { PurchaseOrderDocument pod = (PurchaseOrderDocument) XmlObject.Factory.parse( JarUtil.getResourceFromJar("xbean/xmlcursor/po.xml")); Modified: xmlbeans/trunk/test/src/xmlobject/detailed/ValueEqualsTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/detailed/ValueEqualsTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/detailed/ValueEqualsTest.java (original) +++ xmlbeans/trunk/test/src/xmlobject/detailed/ValueEqualsTest.java Fri Jan 18 23:08:44 2019 @@ -16,56 +16,18 @@ package xmlobject.detailed; -import junit.framework.*; -import junit.framework.Assert.*; - -import java.io.*; - import org.apache.xmlbeans.XmlObject; -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlBeans; -import org.apache.xmlbeans.SchemaTypeSystem; -import org.apache.xmlbeans.SchemaType; -import org.apache.xmlbeans.SchemaTypeLoader; -import org.apache.xmlbeans.XmlCursor.TokenType; -import org.apache.xmlbeans.XmlOptions; - -import java.util.*; -import javax.xml.namespace.QName; - - -import java.util.Vector; - -import xmlcursor.common.*; - -import java.net.URL; - -import org.apache.xmlbeans.xml.stream.XMLInputStream; +import org.junit.Test; import org.tranxml.tranXML.version40.CarLocationMessageDocument; -import org.tranxml.tranXML.version40.FleetIDDocument; -import tools.util.Util; import tools.util.JarUtil; +import xmlcursor.common.BasicCursorTestCase; +import xmlcursor.common.Common; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -/** - * - * - */ public class ValueEqualsTest extends BasicCursorTestCase { - public ValueEqualsTest(String sName) { - super(sName); - } - - public static Test suite() { - return new TestSuite(ValueEqualsTest.class); - } - - public void testClassPath() throws Exception { - String sClassPath = System.getProperty("java.class.path"); - int i = sClassPath.indexOf(Common.CARLOCATIONMESSAGE_JAR); - assertTrue(i >= 0); - } - + @Test public void testValueEqualsTrue() throws Exception { CarLocationMessageDocument clmDoc = (CarLocationMessageDocument) XmlObject.Factory.parse( Modified: xmlbeans/trunk/test/src/xmlobject/detailed/XmlObjectAbstractClassTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/detailed/XmlObjectAbstractClassTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/detailed/XmlObjectAbstractClassTest.java (original) +++ xmlbeans/trunk/test/src/xmlobject/detailed/XmlObjectAbstractClassTest.java Fri Jan 18 23:08:44 2019 @@ -14,44 +14,35 @@ */ package xmlobject.detailed; +import org.apache.xmlbeans.impl.tool.CodeGenUtil; +import org.junit.Test; +import tools.util.JarUtil; + import java.io.*; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; -import org.apache.xmlbeans.impl.tool.CodeGenUtil; -import tools.util.JarUtil; -import xmlcursor.common.Common; +import static org.junit.Assert.assertTrue; /** * JUnit Test file to test XmlObject Abstract base class - * - * @author: Raju Subramanian. - * - * */ -public class XmlObjectAbstractClassTest - extends TestCase { - - public XmlObjectAbstractClassTest(String name) { - super(name); - } +public class XmlObjectAbstractClassTest { /** * The test entry point. */ + @Test public void testAbstractBaseClass() throws Exception { // create the source file //String src = JarUtil.getResourceFromJarasStream(Common.XMLCASES_JAR, "xbean/xmlobject/SimpleXmlObject.java.txt"); - File to = new File("SimpleXmlObject.java"); - InputStreamReader r=new InputStreamReader( - JarUtil.getResourceFromJarasStream( - "xbean/xmlobject/SimpleXmlObject.java.txt")); - assertTrue("Could not create source file", - copyTo(r , to)); - assertTrue("Could not compile SimpleXmlObject.java", - compileFile(to)); + File to = new File("build/SimpleXmlObject.java"); + InputStreamReader r = new InputStreamReader( + JarUtil.getResourceFromJarasStream( + "xbean/xmlobject/SimpleXmlObject.java.txt")); + assertTrue("Could not create source file", copyTo(r, to)); + assertTrue("Could not compile SimpleXmlObject.java", compileFile(to)); to.deleteOnExit(); } @@ -62,17 +53,14 @@ public class XmlObjectAbstractClassTest */ private boolean compileFile(File source) { // the location for the compiled file - File dir = new File(System.getProperty("user.dir")); + File dir = new File("build"); File[] classpath = CodeGenUtil.systemClasspath(); - List srcFiles = new ArrayList(); + List<File> srcFiles = new ArrayList<File>(); srcFiles.add(source); - if (!CodeGenUtil.externalCompile(srcFiles, dir, classpath, false, - CodeGenUtil.DEFAULT_COMPILER, null, CodeGenUtil.DEFAULT_MEM_START, - CodeGenUtil.DEFAULT_MEM_MAX, false, false)){ - return false; - } - return true; + return CodeGenUtil.externalCompile(srcFiles, dir, classpath, false, + CodeGenUtil.DEFAULT_COMPILER, null, CodeGenUtil.DEFAULT_MEM_START, + CodeGenUtil.DEFAULT_MEM_MAX, false, false); } /** @@ -96,8 +84,7 @@ public class XmlObjectAbstractClassTest in.close(); fos.close(); - } - catch (Exception ioe) { + } catch (Exception ioe) { System.out.println("Could not create source file: " + ioe); ioe.printStackTrace(); return false; @@ -126,19 +113,11 @@ public class XmlObjectAbstractClassTest } fis.close(); fos.close(); - } - catch (Exception ioe) { + } catch (Exception ioe) { System.out.println("Could not create source file: " + ioe); return false; } return true; } - - /** - * - */ - public static void main(String args[]) throws Exception { - new XmlObjectAbstractClassTest("test").testAbstractBaseClass(); - } } Modified: xmlbeans/trunk/test/src/xmlobject/schematypes/checkin/EnumTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/schematypes/checkin/EnumTests.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/schematypes/checkin/EnumTests.java (original) +++ xmlbeans/trunk/test/src/xmlobject/schematypes/checkin/EnumTests.java Fri Jan 18 23:08:44 2019 @@ -15,36 +15,29 @@ package xmlobject.schematypes.checkin; -import junit.framework.Test; -import junit.framework.TestSuite; -import junit.framework.Assert; -import junit.framework.TestCase; +import com.enumtest.Data; +import com.enumtest.Quantity; +import com.enumtest.SalesreportDocument; +import com.enumtest.SalesreportDocument.Salesreport.Unit; +import com.enumtest.StatusreportDocument; import org.apache.xmlbeans.XmlBeans; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; -import com.enumtest.StatusreportDocument; -import com.enumtest.SalesreportDocument; -import com.enumtest.SalesreportDocument.Salesreport.Unit; -import com.enumtest.Quantity; -import com.enumtest.Data; +import org.junit.Test; +import tools.util.JarUtil; -import tools.util.*; +import static org.junit.Assert.assertEquals; -public class EnumTests extends TestCase -{ - public EnumTests(String name) { super(name); } - public static Test suite() { return new TestSuite(EnumTests.class); } - - public static void testReport1() throws Exception - { +public class EnumTests { + @Test + public void testReport1() throws Exception { StatusreportDocument doc = (StatusreportDocument) - XmlObject.Factory.parse( - JarUtil.getResourceFromJarasFile( - "xbean/xmlobject/enumtest.xml")); + XmlObject.Factory.parse( + JarUtil.getResourceFromJarasFile( + "xbean/xmlobject/enumtest.xml")); - Quantity.Enum[] contents = new Quantity.Enum[] - { + Quantity.Enum[] contents = { Quantity.ALL, Quantity.ALL, Quantity.FEW, @@ -56,16 +49,15 @@ public class EnumTests extends TestCase }; Data[] data = doc.getStatusreport().getStatusArray(); int t = 0; - for (int i = 0; i < data.length; i++) - { - Assert.assertEquals(contents[t++], data[i].enumValue()); + for (int i = 0; i < data.length; i++) { + assertEquals(contents[t++], data[i].enumValue()); // System.out.println("Target: " + data[i].getTarget() + ", value: " + data[i].enumValue()); - Assert.assertEquals(contents[t++], data[i].getTarget()); + assertEquals(contents[t++], data[i].getTarget()); } } - public static void testReport2() throws Exception - { + @Test + public void testReport2() throws Exception { StatusreportDocument doc = StatusreportDocument.Factory.newInstance(); StatusreportDocument.Statusreport report = doc.addNewStatusreport(); @@ -85,8 +77,7 @@ public class EnumTests extends TestCase d.set(Quantity.NONE); d.setTarget(Quantity.NONE); - Quantity.Enum[] contents = new Quantity.Enum[] - { + Quantity.Enum[] contents = { Quantity.ALL, Quantity.ALL, Quantity.FEW, @@ -98,16 +89,15 @@ public class EnumTests extends TestCase }; Data[] data = doc.getStatusreport().getStatusArray(); int t = 0; - for (int i = 0; i < data.length; i++) - { - Assert.assertEquals(contents[t++], data[i].enumValue()); + for (int i = 0; i < data.length; i++) { + assertEquals(contents[t++], data[i].enumValue()); // System.out.println("Target: " + data[i].getTarget() + ", value: " + data[i].enumValue()); - Assert.assertEquals(contents[t++], data[i].getTarget()); + assertEquals(contents[t++], data[i].getTarget()); } } - public static void testReport3() throws Exception - { + @Test + public void testReport3() throws Exception { SalesreportDocument doc = SalesreportDocument.Factory.newInstance(); SalesreportDocument.Salesreport report = doc.addNewSalesreport(); @@ -116,8 +106,7 @@ public class EnumTests extends TestCase report.addUnit(Unit.NINETY_NINE); report.addUnit(Unit.ONE_HUNDRED); - Unit.Enum[] contents = new Unit.Enum[] - { + Unit.Enum[] contents = { Unit.ONE, Unit.TWO, Unit.NINETY_NINE, @@ -125,20 +114,18 @@ public class EnumTests extends TestCase }; Unit[] xunits = report.xgetUnitArray(); - for (int i = 0; i < xunits.length; i++) - { - Assert.assertEquals(contents[i], xunits[i].enumValue()); + for (int i = 0; i < xunits.length; i++) { + assertEquals(contents[i], xunits[i].enumValue()); } Unit.Enum[] units = report.getUnitArray(); - for (int i = 0; i < units.length; i++) - { - Assert.assertEquals(contents[i], units[i]); + for (int i = 0; i < units.length; i++) { + assertEquals(contents[i], units[i]); } } - public static void testEnumRestriction() throws Exception - { + @Test(expected = XmlException.class) + public void testEnumRestriction() throws Exception { String schema = "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" + " xmlns:tns=\"foo\" targetNamespace=\"foo\">\n" + @@ -154,7 +141,7 @@ public class EnumTests extends TestCase " <xs:restriction base=\"tns:parent\">\n" + " <xs:enumeration value=\"abc\"/>\n" + " <xs:enumeration value=\"123\"/>\n" + - // 'xyz' is an invalid enumeration value + // 'xyz' is an invalid enumeration value " <xs:enumeration value=\"xyz\"/>\n" + " </xs:restriction>\n" + " </xs:simpleType>\n" + @@ -162,19 +149,8 @@ public class EnumTests extends TestCase "</xs:schema>\n"; XmlObject xobj = XmlObject.Factory.parse(schema); - //ArrayList errors = new ArrayList(); - //XmlOptions opts = new XmlOptions().setErrorListener(errors); - try - { - XmlBeans.loadXsd(new XmlObject[]{xobj}); - fail("Expected loadXsd() to throw an exception."); - } - catch (XmlException xe) - { - // - System.out.println("caught: " + xe); - } + XmlBeans.loadXsd(new XmlObject[]{xobj}); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
