Modified: xmlbeans/trunk/test/src/xmlobject/schematypes/detailed/QNameSetTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/schematypes/detailed/QNameSetTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/schematypes/detailed/QNameSetTest.java (original) +++ xmlbeans/trunk/test/src/xmlobject/schematypes/detailed/QNameSetTest.java Fri Jan 18 23:08:44 2019 @@ -15,45 +15,26 @@ package xmlobject.schematypes.detailed; -import javax.xml.namespace.QName; +import org.apache.xmlbeans.QNameSetBuilder; +import org.junit.Test; -import java.text.DecimalFormat; +import javax.xml.namespace.QName; import java.util.Random; import java.util.Stack; -import org.apache.xmlbeans.QNameSetBuilder; -import org.apache.xmlbeans.QNameSetSpecification; -import junit.framework.TestCase; -import junit.framework.Assert; -import junit.framework.Test; -import junit.framework.TestSuite; - -public class QNameSetTest extends TestCase -{ - public QNameSetTest(String name) { super(name); } - public static Test suite() { return new TestSuite(QNameSetTest.class); } - - public static String format(int indent, int iter, String p, QNameSetBuilder set) - { - /* - System.err.print(new DecimalFormat("00000 ").format(iter)); - while (indent-- > 0) - System.err.print(' '); - System.err.print(p); - System.err.print(" = "); - System.err.println(set.dump()); - */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; - return "case# " + iter + " " + p + " " + set.toString(); +public class QNameSetTest { + private static String format(int iter, String p, QNameSetBuilder set) { + return "case# " + iter + " " + p + " " + set.toString(); } - - public void testQNameSets() - { + @Test + public void testQNameSets() { int iterations = 10000; int seed = 0; - int stopat = -1; Random rnd = new Random(seed); String[] localname = {"a", "b", "c", "d", "e"}; @@ -61,16 +42,14 @@ public class QNameSetTest extends TestCa int width = localname.length; QName[] name = new QName[width * namespace.length]; - for (int i = 0; i < width; i++) - { - for (int j = 0; j < namespace.length; j++) - { + for (int i = 0; i < width; i++) { + for (int j = 0; j < namespace.length; j++) { name[i + width * j] = new QName(namespace[j], localname[i]); } } - Stack teststack = new Stack(); // stack of sets - Stack trackstack = new Stack(); // stack of boolean arrays + Stack<QNameSetBuilder> teststack = new Stack<QNameSetBuilder>(); // stack of sets + Stack<boolean[]> trackstack = new Stack<boolean[]>(); // stack of boolean arrays QNameSetBuilder current = new QNameSetBuilder(); boolean[] contents = new boolean[width * namespace.length]; @@ -78,170 +57,152 @@ public class QNameSetTest extends TestCa int i = 0; int j = 0; - for (int l = 0; l < iterations; l++) - { - // for debugging - - if (l == stopat) - System.err.println("We're here"); - + for (int l = 0; l < iterations; l++) { // apply a random operation - if (rnd.nextInt(3) != 0) - { + if (rnd.nextInt(3) != 0) { i = rnd.nextInt(width - 1); // don't do the last one for isAll test j = rnd.nextInt(namespace.length - 1); // don't do the last one for isAll test } - String label; - - switch (teststack.size() < 1 ? 24 : rnd.nextInt(iterations - l > teststack.size() ? 24 : 5)) - { + switch (teststack.size() < 1 ? 24 : rnd.nextInt(iterations - l > teststack.size() ? 24 : 5)) { default: + // new teststack.push(current); trackstack.push(contents); current = new QNameSetBuilder(); contents = new boolean[width * namespace.length]; - label = "new"; break; case 19: case 20: case 22: + // random teststack.push(current); trackstack.push(contents); current = new QNameSetBuilder(); contents = new boolean[width * namespace.length]; - if (rnd.nextInt(2) == 0) - { + if (rnd.nextInt(2) == 0) { current.invert(); - for (int k = 0; k < width; k++) - { + for (int k = 0; k < width; k++) { contents[k + width * (namespace.length - 1)] = true; } } - for (int h = 0; h < namespace.length - 1; h++) - { + for (int h = 0; h < namespace.length - 1; h++) { if (rnd.nextInt(2) == 0) current.removeNamespace(namespace[h]); - else - { + else { current.addNamespace(namespace[h]); contents[width - 1 + width * h] = true; } - for (int k = 0; k < width - 1; k++) - { + for (int k = 0; k < width - 1; k++) { if (rnd.nextInt(2) == 0) current.remove(name[k + width * h]); - else - { + else { current.add(name[k + width * h]); contents[k + width * h] = true; } } } - label = "random"; break; case 0: - current.addAll((QNameSetSpecification)teststack.pop()); - temp = (boolean[])trackstack.pop(); + // add set + current.addAll(teststack.pop()); + temp = trackstack.pop(); for (int k = 0; k < width * namespace.length; k++) if (temp[k]) contents[k] = true; - label = "add set"; break; case 1: - current.removeAll((QNameSetSpecification)teststack.pop()); - temp = (boolean[])trackstack.pop(); + // remove set + current.removeAll(teststack.pop()); + temp = trackstack.pop(); for (int k = 0; k < width * namespace.length; k++) if (temp[k]) contents[k] = false; - label = "remove set"; break; case 2: - current.restrict((QNameSetSpecification)teststack.pop()); - temp = (boolean[])trackstack.pop(); + // restrict set + current.restrict(teststack.pop()); + temp = trackstack.pop(); for (int k = 0; k < width * namespace.length; k++) if (!temp[k]) contents[k] = false; - label = "restrict set"; break; case 3: - label = "union"; - current = new QNameSetBuilder(current.union((QNameSetSpecification)teststack.pop())); - temp = (boolean[])trackstack.pop(); + // union + current = new QNameSetBuilder(current.union(teststack.pop())); + temp = trackstack.pop(); for (int k = 0; k < width * namespace.length; k++) if (temp[k]) contents[k] = true; - label = "union"; break; case 4: - label = "intersect"; - current = new QNameSetBuilder(current.intersect((QNameSetSpecification)teststack.pop())); - temp = (boolean[])trackstack.pop(); + // intersect + current = new QNameSetBuilder(current.intersect(teststack.pop())); + temp = trackstack.pop(); for (int k = 0; k < width * namespace.length; k++) if (!temp[k]) contents[k] = false; - label = "intersect"; break; case 5: + // copy current = new QNameSetBuilder(current); - label = "copy"; break; case 6: case 7: case 8: + // add one + name[i + width * j]; current.add(name[i + width * j]); contents[i + width * j] = true; - label = "add one " + name[i + width * j]; break; case 9: case 10: case 11: + // remove one + name[i + width * j]; current.remove(name[i + width * j]); contents[i + width * j] = false; - label = "remove one " + name[i + width * j]; break; case 12: case 13: + // add namespace + namespace[j]; current.addNamespace(namespace[j]); for (int k = 0; k < width; k++) contents[k + width * j] = true; - label = "add namespace " + namespace[j]; break; case 14: case 15: + // remove namespace + namespace[j]; current.removeNamespace(namespace[j]); for (int k = 0; k < width; k++) contents[k + width * j] = false; - label = "remove namespace " + namespace[j]; break; case 16: case 17: + // invert current.invert(); for (int k = 0; k < width * namespace.length; k++) contents[k] = !contents[k]; - label = "invert"; break; case 18: + // inverse current = new QNameSetBuilder(current.inverse()); for (int k = 0; k < width * namespace.length; k++) contents[k] = !contents[k]; - label = "inverse"; break; } @@ -250,65 +211,37 @@ public class QNameSetTest extends TestCa // then, verify current matches contents int count = 0; - for (int k = 0; k < width * namespace.length; k++) - { - Assert.assertTrue(format(0, l, "Content mismatch " + name[k], current), (current.contains(name[k]) == contents[k])); - { - // testprint(0, l, "ERROR ON " + name[k], current); - // testprint(0, l, "expected " + contents[k] + ", got " + !contents[k], current); - // System.exit(1); - } + for (int k = 0; k < width * namespace.length; k++) { + assertTrue(format(l, "Content mismatch " + name[k], current), (current.contains(name[k]) == contents[k])); if (contents[k]) count++; } - Assert.assertTrue(format(0, l, "ERROR: isEmpty is wrong", current), ((count == 0) == current.isEmpty())); - { - // testprint(0, l, "ERROR: isEmpty is wrong", current); - // testprint(0, l, "expected " + (count == 0) + ", got " + !(count == 0), current); - // System.exit(1); - } + assertTrue(format(l, "ERROR: isEmpty is wrong", current), ((count == 0) == current.isEmpty())); - Assert.assertTrue(format(0, l, "ERROR: isAll is wrong", current), (count == width * namespace.length) == current.isAll()); - { - // testprint(0, l, "ERROR: isAll is wrong", current); - // testprint(0, l, "expected " + (count == width * namespace.length) + ", got " + !(count == width * namespace.length), current); - // System.exit(1); - } + assertEquals(format(l, "ERROR: isAll is wrong", current), (count == width * namespace.length), current.isAll()); // test isDisjoint and containsAll - if (teststack.size() >= 1) - { + if (teststack.size() >= 1) { boolean disjoint = true; - temp = (boolean[])trackstack.peek(); - for (int k = 0; k < width * namespace.length; k++) - { - if (temp[k] && contents[k]) - { + temp = trackstack.peek(); + for (int k = 0; k < width * namespace.length; k++) { + if (temp[k] && contents[k]) { disjoint = false; break; } } - Assert.assertTrue(format(0, l, "ERROR: disjoint is wrong", current), disjoint == current.isDisjoint((QNameSetSpecification)teststack.peek())); - { - // testprint(0, l, "ERROR: disjoint is wrong", current); - // testprint(0, l, "expected " + disjoint + ", got " + !disjoint, (QNameSetBuilder)teststack.peek()); - // System.exit(1); - } - - + assertEquals(format(l, "ERROR: disjoint is wrong", current), disjoint, current.isDisjoint(teststack.peek())); + boolean containsAll = true; - for (int k = 0; k < width * namespace.length; k++) - { - if (temp[k] && !contents[k]) - { + for (int k = 0; k < width * namespace.length; k++) { + if (temp[k] && !contents[k]) { containsAll = false; break; } } - Assert.assertTrue(format(0, l, "ERROR: containsAll is wrong", current), containsAll == current.containsAll((QNameSetSpecification)teststack.peek())); + assertEquals(format(l, "ERROR: containsAll is wrong", current), containsAll, current.containsAll(teststack.peek())); } - } } }
Modified: xmlbeans/trunk/test/src/xmlobject/usertype/averageCase/checkin/AverageTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/usertype/averageCase/checkin/AverageTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/usertype/averageCase/checkin/AverageTest.java (original) +++ xmlbeans/trunk/test/src/xmlobject/usertype/averageCase/checkin/AverageTest.java Fri Jan 18 23:08:44 2019 @@ -15,33 +15,24 @@ package xmlobject.usertype.averageCase.checkin; -import java.math.BigDecimal; - -import javax.xml.stream.XMLOutputFactory; - -import junit.framework.TestCase; - import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException; - +import org.junit.Test; import usertype.xbean.averageCase.purchaseOrder.Items; import usertype.xbean.averageCase.purchaseOrder.PurchaseOrderDocument; import usertype.xbean.averageCase.purchaseOrder.PurchaseOrderType; import xmlobject.usertype.averageCase.existing.SKU; +import java.math.BigDecimal; -public class AverageTest extends TestCase -{ +import static org.junit.Assert.assertEquals; - public AverageTest(String s){ - super(s); - } - public void test(){ +public class AverageTest { - PurchaseOrderDocument poDoc ; - - poDoc= PurchaseOrderDocument.Factory.newInstance(); + @Test + public void test(){ + PurchaseOrderDocument poDoc = PurchaseOrderDocument.Factory.newInstance(); PurchaseOrderType po=poDoc.addNewPurchaseOrder(); int LEN=20; @@ -54,25 +45,21 @@ public class AverageTest extends TestCas Items items= Items.Factory.newInstance(); items.setItemArray(it); po.setItems(items); - // System.out.println("poDoc: " + poDoc); for (int i=0; i< LEN; i++){ assertEquals(i, it[i].getPartNum().getDigits()); assertEquals("AB", it[i].getPartNum().getLetters()); } - - } + @Test(expected = XmlValueOutOfRangeException.class) public void testBadInput() throws XmlException{ - - StringBuffer sb = new StringBuffer(); - sb.append("<purchaseOrder xmlns=\"http://xbean.usertype/averageCase/PurchaseOrder\">"); - sb.append("<items><item partNum=\"000-AB\"><USPrice>2</USPrice></item>"); - sb.append("<item partNum=\"0013-AB\"><USPrice>2</USPrice></item>"); - sb.append("</items></purchaseOrder>"); - - PurchaseOrderDocument poDocument = PurchaseOrderDocument.Factory.parse(sb.toString()); + String sb = + "<purchaseOrder xmlns=\"http://xbean.usertype/averageCase/PurchaseOrder\">" + + "<items><item partNum=\"000-AB\"><USPrice>2</USPrice></item>" + + "<item partNum=\"0013-AB\"><USPrice>2</USPrice></item>" + + "</items></purchaseOrder>"; + PurchaseOrderDocument poDocument = PurchaseOrderDocument.Factory.parse(sb); PurchaseOrderType po = poDocument.getPurchaseOrder(); @@ -85,16 +72,7 @@ public class AverageTest extends TestCas assertEquals(0, sku.getDigits()); assertEquals("AB", sku.getLetters()); - try { - - sku = it[1].getPartNum(); - fail("Invalid SKU format should have failed"); - - } catch (XmlValueOutOfRangeException e) { - - // test passed - } - - + it[1].getPartNum(); + // Invalid SKU format should fail } } Modified: xmlbeans/trunk/test/src/xmlobject/usertype/multipleItems/checkin/AverageTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/usertype/multipleItems/checkin/AverageTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/usertype/multipleItems/checkin/AverageTest.java (original) +++ xmlbeans/trunk/test/src/xmlobject/usertype/multipleItems/checkin/AverageTest.java Fri Jan 18 23:08:44 2019 @@ -16,37 +16,28 @@ package xmlobject.usertype.multipleItems.checkin; -import java.math.BigInteger; - -import junit.framework.TestCase; - import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException; - +import org.junit.Test; import usertype.xbean.multipleItems.company.CompanyDocument; import usertype.xbean.multipleItems.company.CompanyType; import usertype.xbean.multipleItems.company.ConsultantType; import usertype.xbean.multipleItems.company.DepartmentType; import xmlobject.usertype.multipleItems.existing.Room; +import java.math.BigInteger; -public class AverageTest extends TestCase{ - - public AverageTest(String s){ - super(s); - } - - public void test() { +import static org.junit.Assert.assertEquals; - CompanyDocument doc; - doc = CompanyDocument.Factory.newInstance(); +public class AverageTest { + @Test + public void test() { + CompanyDocument doc = CompanyDocument.Factory.newInstance(); CompanyType company = doc.addNewCompany(); - DepartmentType dept = company.addNewDepartments(); - ConsultantType cons = dept.addNewConsultant(); cons.setName("Joe Smith"); @@ -69,17 +60,13 @@ public class AverageTest extends TestCas } + @Test public void testArrayGetSet() { - CompanyDocument doc; - - doc = CompanyDocument.Factory.newInstance(); - + CompanyDocument doc = CompanyDocument.Factory.newInstance(); CompanyType company = doc.addNewCompany(); - DepartmentType dept = company.addNewDepartments(); - ConsultantType cons = dept.addNewConsultant(); cons.setName("Joe Smith"); @@ -104,17 +91,13 @@ public class AverageTest extends TestCas } + @Test public void testIthGetSet() { - CompanyDocument doc; - - doc = CompanyDocument.Factory.newInstance(); - + CompanyDocument doc = CompanyDocument.Factory.newInstance(); CompanyType company = doc.addNewCompany(); - DepartmentType dept = company.addNewDepartments(); - ConsultantType cons = dept.addNewConsultant(); cons.setName("Joe Smith"); @@ -140,7 +123,7 @@ public class AverageTest extends TestCas } - + @Test(expected = XmlValueOutOfRangeException.class) public void testBadInput() throws XmlException{ StringBuffer sb = new StringBuffer(); @@ -156,56 +139,35 @@ public class AverageTest extends TestCas ConsultantType cons = company.getDepartmentsArray(0).getConsultantArray(0); assertEquals(3, cons.xgetRoomArray().length); - try - { - cons.getRoomArray(); - fail("Invalid Room format should have failed"); - - } catch (XmlValueOutOfRangeException e) { - - // test passed - } - + cons.getRoomArray(); } - - + @Test(expected = XmlValueOutOfRangeException.class) public void testBadInputGetIthBad() throws XmlException{ - StringBuffer sb = new StringBuffer(); - sb.append("<com:company xmlns:com=\"http://xbean.usertype/multipleItems/company\">"); - sb.append("<departments><consultant name=\"Joe Smith\" age=\"100\">"); - sb.append("<room>000-AB</room><room>0001-AB</room><room>002-AB</room>"); - sb.append("</consultant></departments></com:company>"); - - CompanyDocument doc = CompanyDocument.Factory.parse(sb.toString()); + String sb = + "<com:company xmlns:com=\"http://xbean.usertype/multipleItems/company\">" + + "<departments><consultant name=\"Joe Smith\" age=\"100\">" + + "<room>000-AB</room><room>0001-AB</room><room>002-AB</room>" + + "</consultant></departments></com:company>"; + CompanyDocument doc = CompanyDocument.Factory.parse(sb); CompanyType company = doc.getCompany(); ConsultantType cons = company.getDepartmentsArray(0).getConsultantArray(0); assertEquals(3, cons.xgetRoomArray().length); - try - { - cons.getRoomArray(1); - fail("Invalid Room format should have failed"); - } catch (XmlValueOutOfRangeException e) { - - // test passed - } - + cons.getRoomArray(1); } - + @Test public void testBadInputGetIthGood() throws XmlException{ - - StringBuffer sb = new StringBuffer(); - sb.append("<com:company xmlns:com=\"http://xbean.usertype/multipleItems/company\">"); - sb.append("<departments><consultant name=\"Joe Smith\" age=\"100\">"); - sb.append("<room>000-AB</room><room>0001-AB</room><room>002-AB</room>"); - sb.append("</consultant></departments></com:company>"); - - CompanyDocument doc = CompanyDocument.Factory.parse(sb.toString()); + String sb = + "<com:company xmlns:com=\"http://xbean.usertype/multipleItems/company\">" + + "<departments><consultant name=\"Joe Smith\" age=\"100\">" + + "<room>000-AB</room><room>0001-AB</room><room>002-AB</room>" + + "</consultant></departments></com:company>"; + CompanyDocument doc = CompanyDocument.Factory.parse(sb); CompanyType company = doc.getCompany(); @@ -216,7 +178,5 @@ public class AverageTest extends TestCas assertEquals("AB", cons.getRoomArray(0).getLetters()); assertEquals(2, cons.getRoomArray(2).getDigits()); assertEquals("AB", cons.getRoomArray(2).getLetters()); - } - } Modified: xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/JapaneseTextTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/JapaneseTextTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/JapaneseTextTest.java (original) +++ xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/JapaneseTextTest.java Fri Jan 18 23:08:44 2019 @@ -14,62 +14,80 @@ */ package xmlobject.xmlloader.detailed; -import junit.framework.TestCase; import org.apache.xmlbeans.XmlObject; +import org.junit.Test; import tools.util.JarUtil; -public class JapaneseTextTest extends TestCase { +public class JapaneseTextTest { - public void testEucJp() throws Exception{ + @Test + public void testEucJp() throws Exception { loadFile("pr-xml-euc-jp.xml"); } - public void testIso2022Jp()throws Exception{ - loadFile("pr-xml-iso-2022-jp.xml"); + + @Test + public void testIso2022Jp() throws Exception { + loadFile("pr-xml-iso-2022-jp.xml"); + } + + @Test + public void testLittleEndian() throws Exception { + loadFile("pr-xml-little-endian.xml"); + } + + @Test + public void testShift_jis() throws Exception { + loadFile("pr-xml-shift_jis.xml"); + } + + @Test + public void testUtf8() throws Exception { + loadFile("pr-xml-utf-8.xml"); + } + + @Test + public void testUtf16() throws Exception { + loadFile("pr-xml-utf-16.xml"); } - public void testLittleEndian()throws Exception{ - loadFile("pr-xml-little-endian.xml"); - } - public void testShift_jis()throws Exception{ - loadFile("pr-xml-shift_jis.xml"); - } - public void testUtf8()throws Exception{ - loadFile("pr-xml-utf-8.xml"); - } - public void testUtf16()throws Exception{ - loadFile("pr-xml-utf-16.xml"); - } - public void testWeeklyEucJp()throws Exception{ + @Test + public void testWeeklyEucJp() throws Exception { loadFile("weekly-euc-jp.xml"); } - public void testWeeklyIso2022Jp()throws Exception{ + + @Test + public void testWeeklyIso2022Jp() throws Exception { loadFile("weekly-iso-2022-jp.xml"); } - public void testWeeklyLittleEndian()throws Exception{ - loadFile("weekly-little-endian.xml"); - } - public void testWeeklyShift_jis()throws Exception{ - loadFile("weekly-shift_jis.xml"); - } - public void testWeeklyUtf8()throws Exception{ - loadFile("weekly-utf-8.xml"); - } - public void testWeeklyUtf16()throws Exception{ - loadFile("weekly-utf-16.xml"); - } - - public void testPrefixLocalName()throws Exception{ - loadFile("prefix_test.xml"); - } + @Test + public void testWeeklyLittleEndian() throws Exception { + loadFile("weekly-little-endian.xml"); + } - public void loadFile(String file) throws Exception{ + @Test + public void testWeeklyShift_jis() throws Exception { + loadFile("weekly-shift_jis.xml"); + } - XmlObject.Factory.parse(JarUtil. - getResourceFromJarasStream("xbean/xmlobject/japanese/"+file)); + @Test + public void testWeeklyUtf8() throws Exception { + loadFile("weekly-utf-8.xml"); + } + @Test + public void testWeeklyUtf16() throws Exception { + loadFile("weekly-utf-16.xml"); } + @Test + public void testPrefixLocalName() throws Exception { + loadFile("prefix_test.xml"); + } + private void loadFile(String file) throws Exception { + XmlObject.Factory.parse(JarUtil. + getResourceFromJarasStream("xbean/xmlobject/japanese/" + file)); + } } Modified: xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/ParseTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/ParseTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/ParseTest.java (original) +++ xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/ParseTest.java Fri Jan 18 23:08:44 2019 @@ -15,68 +15,48 @@ package xmlobject.xmlloader.detailed; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; +import org.junit.Test; import xmlcursor.common.BasicCursorTestCase; import javax.xml.namespace.QName; import java.util.Vector; +import static org.junit.Assert.assertEquals; + public class ParseTest extends BasicCursorTestCase { private XmlOptions m_map = new XmlOptions(); - public ParseTest(String sName) { - super(sName); - } - - public static Test suite() { - return new TestSuite(ParseTest.class); - } - + @Test public void testLoadStripWhitespace() throws Exception { m_map.put(XmlOptions.LOAD_STRIP_WHITESPACE, ""); m_xo = XmlObject.Factory.parse("<foo>01234 <bar>text</bar> chars \r\n</foo> ", - m_map); + m_map); m_xc = m_xo.newCursor(); assertEquals("<foo>01234<bar>text</bar>chars</foo>", m_xc.xmlText()); } + + @Test public void testLoadDiscardDocumentElement() throws Exception { QName name = new QName(""); - m_map.put(XmlOptions.LOAD_REPLACE_DOCUMENT_ELEMENT, name); - System.out.println("here"); - - try { - m_xo = XmlObject.Factory.parse("<foo>01234 <bar>text</bar> chars </foo> ", - m_map); - } catch (IllegalArgumentException e) { - } - + XmlObject.Factory.parse("<foo>01234 <bar>text</bar> chars </foo> ", m_map); } + @Test(expected = XmlException.class) public void testPrefixNotDefined() throws Exception { String sXml = "<Person xmlns=\"person\"><pre1:Name>steve</pre1:Name></Person>"; - try { - XmlObject.Factory.parse(sXml); - fail("Expected XmlException"); - } catch (org.apache.xmlbeans.XmlException e) { - } + XmlObject.Factory.parse(sXml); } + @Test(expected = XmlException.class) public void testErrorListener() throws Exception { Vector vErrors = new Vector(); m_map.setErrorListener(vErrors); - try { - m_xo = XmlObject.Factory.parse("<foo>text<foo>", m_map); // improper end tag - fail("Expected parsing exception!"); - } catch (org.apache.xmlbeans.XmlException xe) { - - } + XmlObject.Factory.parse("<foo>text<foo>", m_map); // improper end tag } - - } Modified: xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/PiccoloParseTests.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/PiccoloParseTests.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/PiccoloParseTests.java (original) +++ xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/PiccoloParseTests.java Fri Jan 18 23:08:44 2019 @@ -14,33 +14,38 @@ */ package xmlobject.xmlloader.detailed; -import junit.framework.TestCase; +import org.apache.xmlbeans.XmlObject; +import org.junit.Ignore; +import org.junit.Test; import tools.util.JarUtil; import java.io.InputStream; -import org.apache.xmlbeans.XmlObject; +import static org.junit.Assert.assertTrue; -public class PiccoloParseTests extends TestCase{ +@Ignore("Piccolo is not anymore used") +public class PiccoloParseTests { String filename="xbean/xmlobject/japanese/core_generated_wsdl_src.xml"; String temp="xbean/xmlobject/japanese/UCS2Encoding.xml"; + @Test public void testParseInputStream() throws Exception{ InputStream is=JarUtil.getResourceFromJarasStream(filename); assertTrue (is != null ); XmlObject obj=XmlObject.Factory.parse(is); } + @Test public void testParseString() throws Exception{ String str=JarUtil.getResourceFromJar(filename); assertTrue (str != null ); XmlObject obj=XmlObject.Factory.parse(str); } - public void testParseInputStreamUCS2() throws Exception{ - InputStream is=JarUtil.getResourceFromJarasStream(temp); - assertTrue (is != null ); - XmlObject obj=XmlObject.Factory.parse(is); - } - + @Test + public void testParseInputStreamUCS2() throws Exception { + InputStream is = JarUtil.getResourceFromJarasStream(temp); + assertTrue(is != null); + XmlObject obj = XmlObject.Factory.parse(is); + } } Modified: xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/XmlLoaderBvtTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/XmlLoaderBvtTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/XmlLoaderBvtTest.java (original) +++ xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/XmlLoaderBvtTest.java Fri Jan 18 23:08:44 2019 @@ -15,39 +15,25 @@ package xmlobject.xmlloader.detailed; -import junit.framework.Test; -import junit.framework.TestSuite; import org.apache.xmlbeans.XmlObject; +import org.junit.Test; import org.tranxml.tranXML.version40.CarLocationMessageDocument; import tools.util.JarUtil; import xmlcursor.common.BasicCursorTestCase; import xmlcursor.common.Common; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class XmlLoaderBvtTest extends BasicCursorTestCase { - public XmlLoaderBvtTest(String sName) { - super(sName); - } - - public static Test suite() { - return new TestSuite(XmlLoaderBvtTest.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 testCastDocument() throws Exception { CarLocationMessageDocument clm = - (CarLocationMessageDocument) XmlObject.Factory.parse( - JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM)); + (CarLocationMessageDocument) XmlObject.Factory.parse( + JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM)); assertNotNull(clm); } - } - Modified: xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/XmlLoaderMiscTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/XmlLoaderMiscTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/XmlLoaderMiscTest.java (original) +++ xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/XmlLoaderMiscTest.java Fri Jan 18 23:08:44 2019 @@ -16,10 +16,9 @@ package xmlobject.xmlloader.detailed; -import junit.framework.Test; -import junit.framework.TestSuite; import org.apache.xmlbeans.*; import org.apache.xmlbeans.XmlCursor.TokenType; +import org.junit.Test; import org.tranxml.tranXML.version40.CarLocationMessageDocument; import org.tranxml.tranXML.version40.GeographicLocationDocument.GeographicLocation; import tools.util.JarUtil; @@ -28,26 +27,15 @@ import xmlcursor.common.Common; import javax.xml.namespace.QName; import java.util.Collections; -import java.util.Set; import java.util.HashSet; +import java.util.Set; import java.util.Vector; +import static org.junit.Assert.*; -public class XmlLoaderMiscTest extends BasicCursorTestCase { - public XmlLoaderMiscTest(String sName) { - super(sName); - } - - public static Test suite() { - return new TestSuite(XmlLoaderMiscTest.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 XmlLoaderMiscTest extends BasicCursorTestCase { + @Test public void testNewInstance() throws Exception { m_xo = XmlObject.Factory.newInstance(); m_xc = m_xo.newCursor(); @@ -56,6 +44,7 @@ public class XmlLoaderMiscTest extends B assertEquals(TokenType.ENDDOC, m_xc.currentTokenType()); } + @Test public void testTypeForClass() throws Exception { m_xc = XmlObject.Factory.parse(JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM)).newCursor(); m_xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT + "$this//GeographicLocation"); @@ -65,7 +54,8 @@ public class XmlLoaderMiscTest extends B assertEquals(gl.schemaType(), XmlBeans.typeForClass(GeographicLocation.class)); } - public void testGetBuiltInTypeSystem() throws Exception { + @Test + public void testGetBuiltInTypeSystem() { SchemaTypeSystem sts = XmlBeans.getBuiltinTypeSystem(); if (sts == null) { fail("XmlBeans.getBuiltinTypeSystem() returned null"); @@ -76,11 +66,13 @@ public class XmlLoaderMiscTest extends B assertEquals(14, stDateTime.getBuiltinTypeCode()); } - public void testTypeLoaderUnion() throws Exception { + @Test + public void testTypeLoaderUnion() { System.out.println("testTypeLoaderUnion not implemented"); // TODO } + @Test public void testTypeLoaderForClassLoader() throws Exception { SchemaTypeLoader stl = XmlBeans.typeLoaderForClassLoader(CarLocationMessageDocument.class.getClassLoader()); @@ -93,6 +85,7 @@ public class XmlLoaderMiscTest extends B assertEquals("FLEETNAME", m_xc.getTextValue()); } + @Test public void testGetContextTypeLoader() throws Exception { SchemaTypeLoader stl = XmlBeans.getContextTypeLoader(); if (stl == null) Modified: xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/XmlStreamBeanReader.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/XmlStreamBeanReader.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/XmlStreamBeanReader.java (original) +++ xmlbeans/trunk/test/src/xmlobject/xmlloader/detailed/XmlStreamBeanReader.java Fri Jan 18 23:08:44 2019 @@ -14,62 +14,56 @@ */ package xmlobject.xmlloader.detailed; -import junit.framework.TestCase; -import org.apache.xmlbeans.XmlOptions; -import org.apache.xmlbeans.XmlObject; -import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; +import org.apache.xmlbeans.XmlOptions; +import org.junit.Test; import org.openuri.bea.samples.workshop.CreditCardDataDocument; import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; import java.io.ByteArrayInputStream; -/** - * Date: Oct 29, 2004 - * Time: 11:43:06 AM - * - * @owner ykadiysk - */ -public class XmlStreamBeanReader extends TestCase{ +import static org.junit.Assert.assertEquals; - String creditCardXmlwPrefix = - " <cc:credit-card-data xmlns:cc=\"http://openuri.org/bea/samples/workshop\">\n" + - " <cc:customer id=\"1\">\n" + - " <cc:card name=\"MasterCard\" number=\"15385\">\n" + - " <cc:available-credit>0</cc:available-credit>\n" + - " <cc:credit-used>0</cc:credit-used>\n" + - " </cc:card>\n" + - " <cc:card name=\"Visa\" number=\"12346\">\n" + - " <cc:available-credit>0</cc:available-credit>\n" + - " <cc:credit-used>0</cc:credit-used>\n" + - " </cc:card>\n" + - " </cc:customer>\n" + - " <cc:customer id=\"2\">\n" + - " <cc:card name=\"MasterCard\" number=\"String\">\n" + - " <cc:available-credit>0</cc:available-credit>\n" + - " <cc:credit-used>0</cc:credit-used>\n" + - " </cc:card>\n" + - " <cc:card name=\"MasterCard\" number=\"String\">\n" + - " <cc:available-credit>0</cc:available-credit>\n" + - " <cc:credit-used>0</cc:credit-used>\n" + - " </cc:card>\n" + - " </cc:customer>\n" + - " </cc:credit-card-data>"; - - - public void testXMLStreamReaderLoader () throws XMLStreamException, XmlException { - XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(creditCardXmlwPrefix.getBytes())); - CreditCardDataDocument ccdoc = (CreditCardDataDocument) XmlObject.Factory.parse(reader, new XmlOptions().setDocumentType(CreditCardDataDocument.type)); - assertEquals(1,ccdoc.getCreditCardData().getCustomerArray(0).getId()); +public class XmlStreamBeanReader { - } + @Test + public void testXMLStreamReaderLoader() throws XMLStreamException, XmlException { + String creditCardXmlwPrefix = " <cc:credit-card-data xmlns:cc=\"http://openuri.org/bea/samples/workshop\">\n" + + " <cc:customer id=\"1\">\n" + + " <cc:card name=\"MasterCard\" number=\"15385\">\n" + + " <cc:available-credit>0</cc:available-credit>\n" + + " <cc:credit-used>0</cc:credit-used>\n" + + " </cc:card>\n" + + " <cc:card name=\"Visa\" number=\"12346\">\n" + + " <cc:available-credit>0</cc:available-credit>\n" + + " <cc:credit-used>0</cc:credit-used>\n" + + " </cc:card>\n" + + " </cc:customer>\n" + + " <cc:customer id=\"2\">\n" + + " <cc:card name=\"MasterCard\" number=\"String\">\n" + + " <cc:available-credit>0</cc:available-credit>\n" + + " <cc:credit-used>0</cc:credit-used>\n" + + " </cc:card>\n" + + " <cc:card name=\"MasterCard\" number=\"String\">\n" + + " <cc:available-credit>0</cc:available-credit>\n" + + " <cc:credit-used>0</cc:credit-used>\n" + + " </cc:card>\n" + + " </cc:customer>\n" + + " </cc:credit-card-data>"; + + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(creditCardXmlwPrefix.getBytes())); + CreditCardDataDocument ccdoc = (CreditCardDataDocument) XmlObject.Factory.parse(reader, new XmlOptions().setDocumentType(CreditCardDataDocument.type)); + assertEquals(1, ccdoc.getCreditCardData().getCustomerArray(0).getId()); + } // test for IllegalStateException thrown on using XmlStreamReader - public void testXmlStreamReaderException() { - + @Test + public void testXmlStreamReaderException() throws XMLStreamException { XmlObject xo = XmlObject.Factory.newInstance(); XmlCursor xc = xo.newCursor(); xc.toNextToken(); @@ -77,25 +71,10 @@ public class XmlStreamBeanReader extends xc.insertElementWithText("int", "http://openuri.org/testNumerals", "5"); xc.insertElementWithText("float", "http://openuri.org/testNumerals", "7.654321"); - try { + XMLStreamReader xsr = xo.newXMLStreamReader(); - XMLStreamReader xsr = xo.newXMLStreamReader(); - - while(xsr.hasNext()) - { - xsr.next(); - } - } - catch (XMLStreamException xse) - { - xse.printStackTrace(); - fail("XMLStreamException thrown with XMLStreamReader usage"); - } - catch (IllegalStateException ise) - { - ise.printStackTrace(); - fail("IllegalStateException thrown with XMLStreamReader usage"); + while (xsr.hasNext()) { + xsr.next(); } } - } Modified: xmlbeans/trunk/test/src/xmltokensource/detailed/NewDomNodeTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmltokensource/detailed/NewDomNodeTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmltokensource/detailed/NewDomNodeTest.java (original) +++ xmlbeans/trunk/test/src/xmltokensource/detailed/NewDomNodeTest.java Fri Jan 18 23:08:44 2019 @@ -19,26 +19,21 @@ package xmltokensource.detailed; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; -import xmlcursor.common.BasicCursorTestCase; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.Test; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import xmlcursor.common.BasicCursorTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; public class NewDomNodeTest extends BasicCursorTestCase { public static final String DOC_FRAGMENT = "#document-fragment"; - public static final String DOC = "#document"; + private static final String DOC = "#document"; private XmlOptions m_map = new XmlOptions(); - public NewDomNodeTest(String sName) { - super(sName); - } - - public static Test suite() { - return new TestSuite(NewDomNodeTest.class); - } - + @Test public void testNewDomNode() throws Exception { m_xo = XmlObject.Factory.parse("<foo>01234 <bar>text</bar> chars </foo>"); Node doc = m_xo.newDomNode(); @@ -67,6 +62,7 @@ public class NewDomNodeTest extends Basi assertEquals("text", node.getNodeValue()); } + @Test public void testNewDomNodeWithNamespace() throws Exception { m_xo = XmlObject.Factory.parse("<foo xmlns=\"ns\">01234 <bar>text</bar> chars </foo>"); Node doc = m_xo.newDomNode(); @@ -74,6 +70,7 @@ public class NewDomNodeTest extends Basi assertEquals(DOC, doc.getNodeName()); } + @Test public void testNewDomNodeWithOptions() throws Exception { m_xo = XmlObject.Factory.parse("<foo attr=\"val\" xmlns=\"ns\">01234 <bar>text</bar> chars </foo>"); XmlOptions map = new XmlOptions(); @@ -106,6 +103,7 @@ public class NewDomNodeTest extends Basi assertEquals("text", node.getNodeValue()); } + @Test public void testNewDomNodeRoundTrip() throws Exception { m_xo = XmlObject.Factory.parse("<foo>01234 <bar>text</bar> chars </foo>"); Node doc = m_xo.newDomNode(); Modified: xmlbeans/trunk/test/src/xmltokensource/detailed/PrettyPrintNamespaceTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmltokensource/detailed/PrettyPrintNamespaceTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmltokensource/detailed/PrettyPrintNamespaceTest.java (original) +++ xmlbeans/trunk/test/src/xmltokensource/detailed/PrettyPrintNamespaceTest.java Fri Jan 18 23:08:44 2019 @@ -15,19 +15,18 @@ package xmltokensource.detailed; -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlObject; import com.mtest.SubInfo; import com.mtest.TestDocument; -import junit.framework.TestCase; +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlObject; +import org.junit.Test; +import static org.junit.Assert.assertEquals; -public class PrettyPrintNamespaceTest extends TestCase { - public PrettyPrintNamespaceTest(String name) { - super(name); - } +public class PrettyPrintNamespaceTest { + @Test public void testWithNewInstance() throws Exception { XmlObject x = XmlObject.Factory.newInstance(); @@ -41,10 +40,11 @@ public class PrettyPrintNamespaceTest ex String str = "<a aaaa:a=\"\" xmlns=\"aaaa\" xmlns:aaaa=\"aaaa\"/>"; - assertTrue("XmlText() Failed.", x.xmlText().equals(str)); - assertTrue("toString() Failed.", x.toString().trim().equals(str)); + assertEquals("XmlText() Failed.", x.xmlText(), str); + assertEquals("toString() Failed.", x.toString().trim(), str); } + @Test public void testWithInstanceFromSchema() throws Exception { String xml = "<mt:Test xmlns:mt=\"http://www.mtest.com\"> <mt:desc/> </mt:Test>"; @@ -64,7 +64,7 @@ public class PrettyPrintNamespaceTest ex "<mtes:subdesc>there</mtes:subdesc>" + "</mtes:Test>"; - assertTrue("XmlText() Failed.", doc.xmlText().equals(str2)); - assertTrue("toString() Failed.", doc.toString().trim().equals(str1)); + assertEquals("XmlText() Failed.", doc.xmlText(), str2); + assertEquals("toString() Failed.", doc.toString().trim(), str1); } } Modified: xmlbeans/trunk/test/src/xmltokensource/detailed/RoundTripLoaderTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmltokensource/detailed/RoundTripLoaderTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmltokensource/detailed/RoundTripLoaderTest.java (original) +++ xmlbeans/trunk/test/src/xmltokensource/detailed/RoundTripLoaderTest.java Fri Jan 18 23:08:44 2019 @@ -19,31 +19,29 @@ package xmltokensource.detailed; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; +import org.apache.xmlbeans.xml.stream.XMLInputStream; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Node; import xmlcursor.common.BasicCursorTestCase; import xmlcursor.common.Common; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.w3c.dom.Node; -import org.apache.xmlbeans.xml.stream.XMLInputStream; import java.io.InputStream; import java.io.Reader; +import static org.junit.Assert.assertNotNull; + public class RoundTripLoaderTest extends BasicCursorTestCase { public static final String DOC_FRAGMENT = "#document-fragment"; private XmlOptions m_map = new XmlOptions(); - public RoundTripLoaderTest(String sName) { - super(sName); + @Before + public void setUp() { m_map.put(XmlOptions.CHARACTER_ENCODING, "Big5"); m_map.put(XmlOptions.SAVE_NAMESPACES_FIRST, ""); } - public static Test suite() { - return new TestSuite(RoundTripLoaderTest.class); - } - private void _newDomNodeRoundTrip(XmlOptions map) throws Exception { m_xo = XmlObject.Factory.parse(Common.XML_FOO_BAR_NESTED_SIBLINGS); Node doc = m_xo.newDomNode(map); @@ -58,10 +56,12 @@ public class RoundTripLoaderTest extends } } + @Test public void testNewDomNodeRoundTrip() throws Exception { _newDomNodeRoundTrip(null); } + @Test public void testNewDomNodeWithOptionsRoundTrip() throws Exception { _newDomNodeRoundTrip(m_map); } @@ -81,10 +81,12 @@ public class RoundTripLoaderTest extends } } + @Test public void testNewInputStreamRoundTrip() throws Exception { _newInputStreamRoundTrip(null); } + @Test public void testNewInputStreamWithOptionsRoundTrip() throws Exception { _newInputStreamRoundTrip(m_map); } @@ -103,21 +105,22 @@ public class RoundTripLoaderTest extends xc1.dispose(); } } - /** - * yana_kadiyska (3:25:15 PM): Eric, is this going to be impl - * on this release? Bug? store.Cursor._newXMLInputStream - * ericvasilik (3:26:01 PM): This is not a v2 feature. ... - * but otherwise, we should disable XMLInputStream tests - * - public void testNewReaderRoundTrip() throws Exception { - _newReaderRoundTrip(null); - } - public void testNewReaderWithOptionsRoundTrip() throws Exception { - _newReaderRoundTrip(m_map); - } + /** + * yana_kadiyska (3:25:15 PM): Eric, is this going to be impl + * on this release? Bug? store.Cursor._newXMLInputStream + * ericvasilik (3:26:01 PM): This is not a v2 feature. ... + * but otherwise, we should disable XMLInputStream tests + * + * public void testNewReaderRoundTrip() throws Exception { + * _newReaderRoundTrip(null); + * } + * + * public void testNewReaderWithOptionsRoundTrip() throws Exception { + * _newReaderRoundTrip(m_map); + * } + */ - */ private void _newXMLInputStreamRoundTrip(XmlOptions map) throws Exception { m_xo = XmlObject.Factory.parse(Common.XML_FOO_BAR_NESTED_SIBLINGS); XMLInputStream xmlIs = m_xo.newXMLInputStream(map); @@ -132,11 +135,8 @@ public class RoundTripLoaderTest extends } } - /** - * - * @throws Exception - */ - public void testNewXMLInputStreamRoundTrip() throws Exception { + @Test + public void testNewXMLInputStreamRoundTrip() throws Exception { _newXMLInputStreamRoundTrip(null); } @@ -159,6 +159,7 @@ public class RoundTripLoaderTest extends } } + @Test public void testXmlTextRoundTrip() throws Exception { _xmlTextRoundTrip(null); } @@ -166,7 +167,4 @@ public class RoundTripLoaderTest extends public void testXmlTextWithOptionsRoundTrip() throws Exception { _xmlTextRoundTrip(m_map); } - - } - Modified: xmlbeans/trunk/test/src/xmltokensource/detailed/XmlTextTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/xmltokensource/detailed/XmlTextTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/src/xmltokensource/detailed/XmlTextTest.java (original) +++ xmlbeans/trunk/test/src/xmltokensource/detailed/XmlTextTest.java Fri Jan 18 23:08:44 2019 @@ -20,27 +20,20 @@ import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlCursor.TokenType; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; +import org.junit.Test; +import tools.util.JarUtil; import xmlcursor.common.BasicCursorTestCase; import xmlcursor.common.Common; -import tools.util.JarUtil; -import junit.framework.Test; -import junit.framework.TestSuite; import javax.xml.namespace.QName; +import static org.junit.Assert.assertEquals; public class XmlTextTest extends BasicCursorTestCase { private XmlOptions m_map = new XmlOptions(); - public XmlTextTest(String sName) { - super(sName); - } - - public static Test suite() { - return new TestSuite(XmlTextTest.class); - } - + @Test public void testSAVENAMESPACESFIRST() throws Exception { m_xo = XmlObject.Factory.parse("<foo attr0=\"val0\" xmlns=\"http://www.foo.org\">01234</foo>"); m_xc = m_xo.newCursor(); @@ -49,6 +42,7 @@ public class XmlTextTest extends BasicCu m_xc.xmlText(m_map)); } + @Test public void testSAVENAMESPACESlast() throws Exception { m_xo = XmlObject.Factory.parse("<foo attr0=\"val0\" xmlns=\"http://www.foo.org\">01234</foo>"); m_xc = m_xo.newCursor(); @@ -56,6 +50,7 @@ public class XmlTextTest extends BasicCu m_xc.xmlText(m_map)); } + @Test public void testSaveSyntheticDocumentElement() throws Exception { m_xo = XmlObject.Factory.parse("<bar>text</bar>"); m_xc = m_xo.newCursor(); @@ -64,6 +59,7 @@ public class XmlTextTest extends BasicCu assertEquals("<foo><bar>text</bar></foo>", m_xc.xmlText(m_map)); } + @Test public void testSavePrettyPrint() throws Exception { m_xo = XmlObject.Factory.parse("<a><b><c> text </c></b></a>"); m_xc = m_xo.newCursor(); @@ -72,6 +68,7 @@ public class XmlTextTest extends BasicCu assertEquals("<a>" + lnSep + " <b>" + lnSep + " <c>text</c>" + lnSep + " </b>" + lnSep + "</a>", m_xc.xmlText(m_map)); } + @Test public void testSavePrettyPrintIndent3() throws Exception { m_xo = XmlObject.Factory.parse("<a><b><c> text </c></b></a>"); m_xc = m_xo.newCursor(); @@ -81,6 +78,7 @@ public class XmlTextTest extends BasicCu assertEquals("<a>" + lnSep + " <b>" + lnSep + " <c>text</c>" + lnSep + " </b>" + lnSep + "</a>", m_xc.xmlText(m_map)); } + @Test public void testSavePrettyPrintIndentNeg1() throws Exception { m_xc = XmlObject.Factory.parse("<a> \n <b> \n <c> text </c> \n </b> \n </a>").newCursor(); m_map.put(XmlOptions.SAVE_PRETTY_PRINT, ""); @@ -88,6 +86,7 @@ public class XmlTextTest extends BasicCu assertEquals("<a><b><c>text</c></b></a>", m_xc.xmlText(m_map)); } + @Test public void testDefaultNamespace() throws Exception { m_xo = XmlObject.Factory.parse( JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM)); @@ -101,6 +100,7 @@ public class XmlTextTest extends BasicCu m_xc.xmlText(m_map)); } + @Test public void testSTARTDOCvsFirstChild() throws Exception { m_xo = XmlObject.Factory.parse( JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM)); @@ -114,6 +114,7 @@ public class XmlTextTest extends BasicCu } } + @Test public void testXmlTextFromTEXT() throws Exception { m_xo = XmlObject.Factory.parse(Common.XML_FOO_1ATTR_TEXT); m_xc = m_xo.newCursor(); @@ -121,6 +122,7 @@ public class XmlTextTest extends BasicCu assertEquals("text", m_xc.getChars()); } + @Test public void testXmlTextFromTEXTafterEND() throws Exception { m_xo = XmlObject.Factory.parse("<foo><bar> text </bar> ws \\r\\n </foo>"); m_xc = m_xo.newCursor(); Modified: xmlbeans/trunk/test/tools/src/tools/ant/BuildFileTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/tools/src/tools/ant/BuildFileTest.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/tools/src/tools/ant/BuildFileTest.java (original) +++ xmlbeans/trunk/test/tools/src/tools/ant/BuildFileTest.java Fri Jan 18 23:08:44 2019 @@ -54,11 +54,12 @@ package tools.ant; -import junit.framework.*; import org.apache.tools.ant.*; import java.io.*; import java.net.URL; +import static org.junit.Assert.*; + /** * A BuildFileTest is a TestCase which executes targets from an Ant buildfile * for testing. @@ -69,7 +70,7 @@ import java.net.URL; * @author Nico Seessle <[email protected]> * @author Conor MacNeill */ -public abstract class BuildFileTest extends TestCase { +public abstract class BuildFileTest { protected Project project; @@ -79,14 +80,6 @@ public abstract class BuildFileTest exte private StringBuffer errBuffer; private BuildException buildException; - /** - * Constructor for the BuildFileTest object - * - *@param name string to pass up to TestCase constructor - */ - public BuildFileTest(String name) { - super(name); - } /** * run a target, expect for any build exception @@ -309,7 +302,6 @@ public abstract class BuildFileTest exte * *@param target target to run *@param cause information string to reader of report - *@param msg the message value of the build exception we are waiting for *@param contains substring of the build exception to look for */ protected void expectBuildExceptionContaining(String target, String cause, String contains) { @@ -391,7 +383,6 @@ public abstract class BuildFileTest exte * assuming a vm working directory. The resource path must be * relative to the package name or absolute from the root path. * @param resource the resource to retrieve its url. - * @throws AssertionFailureException if resource is not found. */ protected URL getResource(String resource){ URL url = getClass().getResource(resource); Modified: xmlbeans/trunk/test/tools/src/tools/util/JarUtil.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/tools/src/tools/util/JarUtil.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/tools/src/tools/util/JarUtil.java (original) +++ xmlbeans/trunk/test/tools/src/tools/util/JarUtil.java Fri Jan 18 23:08:44 2019 @@ -18,6 +18,8 @@ import java.io.BufferedReader; import java.io.*; import java.net.JarURLConnection; import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.Charset; import java.util.jar.JarFile; import java.util.jar.JarEntry; @@ -59,7 +61,7 @@ public class JarUtil { /** - * returns an item within the given jarFile as a String. jarFile must exist in classpath + * returns the resource as String * * @param pathToResource * @return String @@ -68,30 +70,21 @@ public class JarUtil { public static String getResourceFromJar(String pathToResource) throws IOException { - URL url = ClassLoader.getSystemClassLoader().getResource( - pathToResource); - if (url == null) { - throw new FileNotFoundException( - "Resource: " + pathToResource + " was not found "); - } - JarURLConnection jarConnection = (JarURLConnection) url.openConnection(); - JarFile jar = jarConnection.getJarFile(); - if (jar.getJarEntry(pathToResource) == null) { - throw new FileNotFoundException( - "Resource: " + pathToResource + " was not found "); - } - - JarEntry item = jar.getJarEntry(pathToResource); - BufferedReader in = new BufferedReader( - new InputStreamReader(jar.getInputStream(item))); - - StringBuffer stb = new StringBuffer(); - String buffer; - - while (!((buffer = in.readLine()) == null)) { - stb.append(buffer + EOL); + BufferedReader in = null; + try { + InputStream is = getResourceFromJarasStream(pathToResource); + in = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); + StringBuilder sb = new StringBuilder(); + char[] buf = new char[1024]; + for (int readChr; (readChr = in.read(buf)) > -1; ) { + sb.append(buf, 0, readChr); + } + return sb.toString(); + } finally { + if (in != null) { + in.close(); + } } - return stb.toString(); } /** @@ -111,33 +104,5 @@ public class JarUtil { } return resource; } - - /** - * Returns the classpath entry of a given item on the classpath. The item should be a jarFile reference - * - * @param jarFile - * @return String - * @throws FileNotFoundException - */ - - public static String getFilePath(String jarFile) - throws FileNotFoundException { - String sClassPath = System.getProperty("java.class.path"); - int jarIndex = sClassPath.indexOf(jarFile); - if (jarIndex <= 0) { - throw new FileNotFoundException( - "File: " + jarFile + " was not found on the classpath"); - } - - String P = File.pathSeparator; - String[] pathList = sClassPath.split(P); - for (int i = 0; i < pathList.length; i++) { - if (pathList[i].toLowerCase().endsWith(jarFile.toLowerCase())) { - return pathList[i]; - } - } - throw new FileNotFoundException( - "File: " + jarFile + " was not found when iterating classpath"); - } } Modified: xmlbeans/trunk/test/tools/src/tools/util/Util.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/tools/src/tools/util/Util.java?rev=1851656&r1=1851655&r2=1851656&view=diff ============================================================================== --- xmlbeans/trunk/test/tools/src/tools/util/Util.java (original) +++ xmlbeans/trunk/test/tools/src/tools/util/Util.java Fri Jan 18 23:08:44 2019 @@ -980,6 +980,7 @@ public class Util final String[] defaultFilters = new String[]{ "org.apache.xmlbeansbeans.test.tools.moosehead", "org.apache.xmlbeansbeans.test.tools.harness.Main", + "org.junit.Assert.", "junit.framework.TestCase", "junit.framework.TestResult", "junit.framework.TestSuite", --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
