You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2022/02/06 01:52:00 UTC
svn commit: r1897795 [36/39] - in /xmlbeans: site/src/documentation/content/xdocs/ trunk/ trunk/src/main/java/org/apache/xmlbeans/impl/store/ trunk/src/test/java/ValidatingXSRTests/checkin/ trunk/src/test/java/ValidatingXSRTests/detailed/ trunk/src/tes...
Modified: xmlbeans/trunk/src/test/java/xmlcursor/xquery/detailed/XQueryVariableBindingTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/xquery/detailed/XQueryVariableBindingTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/xquery/detailed/XQueryVariableBindingTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/xquery/detailed/XQueryVariableBindingTest.java Sun Feb 6 01:51:55 2022
@@ -17,7 +17,7 @@ package xmlcursor.xquery.detailed;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.HashMap;
@@ -25,30 +25,25 @@ import java.util.Map;
import static common.Common.P;
import static common.Common.XBEAN_CASE_ROOT;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static xmlcursor.common.BasicCursorTestCase.cur;
/** This class tests the use of XmlOptions in binding XQuery variables */
public class XQueryVariableBindingTest
{
- public static final String XQUERY_CASE_DIR = XBEAN_CASE_ROOT + P + "xmlcursor" + P + "xquery";
- public static File dir = new File(XQUERY_CASE_DIR);
-
- private XmlCursor _testDocCursor1() throws Exception {
- String xml =
- "<elem1>" +
- "<elem11 id=\"123\">text11</elem11>" +
- "<elem21 id=\"456\">text11</elem21>" +
- "<elem12 idRef=\"123\"/>" +
- "<elem13 idRef=\"456\"/>" +
- "<elem14 idRef=\"123\"/>" +
- "<elem15 idRef=\"456\"/>" +
- "<elem16 idRef=\"123\"/>" +
- "<elem17 idRef=\"789\"/>" +
- "</elem1>";
- XmlObject doc = XmlObject.Factory.parse(xml);
- XmlCursor xc = doc.newCursor();
- return xc;
- }
+ private static final String XQUERY_CASE_DIR = XBEAN_CASE_ROOT + P + "xmlcursor" + P + "xquery";
+ private static final File DIR = new File(XQUERY_CASE_DIR);
+ private static final String XML =
+ "<elem1>" +
+ "<elem11 id=\"123\">text11</elem11>" +
+ "<elem21 id=\"456\">text11</elem21>" +
+ "<elem12 idRef=\"123\"/>" +
+ "<elem13 idRef=\"456\"/>" +
+ "<elem14 idRef=\"123\"/>" +
+ "<elem15 idRef=\"456\"/>" +
+ "<elem16 idRef=\"123\"/>" +
+ "<elem17 idRef=\"789\"/>" +
+ "</elem1>";
private void _verifySelection(XmlCursor xc) {
assertEquals(3, xc.getSelectionCount());
@@ -62,8 +57,8 @@ public class XQueryVariableBindingTest
/** test the automatic binding of $this to the current node: selectPath() */
@Test
- public void testThisVariable1() throws Exception {
- try (XmlCursor xc = _testDocCursor1()) {
+ void testThisVariable1() throws Exception {
+ try (XmlCursor xc = cur(XML)) {
xc.toFirstChild(); //<elem1>
xc.toFirstChild(); //<elem11>
xc.selectPath("//*[@idRef=$this/@id]");
@@ -75,8 +70,8 @@ public class XQueryVariableBindingTest
// this fails: see JIRA issue XMLBEANS-276
/** test the binding of a variable to the current node: selectPath() */
@Test
- public void testCurrentNodeVariable1() throws Exception {
- try (XmlCursor xc = _testDocCursor1()) {
+ void testCurrentNodeVariable1() throws Exception {
+ try (XmlCursor xc = cur(XML)) {
xc.toFirstChild();
xc.toFirstChild();
XmlOptions opts = new XmlOptions();
@@ -90,7 +85,7 @@ public class XQueryVariableBindingTest
}
private XmlCursor _testDocCursor2() throws Exception {
- File f = new File(dir, "employees.xml");
+ File f = new File(DIR, "employees.xml");
XmlObject doc = XmlObject.Factory.parse(f);
return doc.newCursor();
}
@@ -106,7 +101,7 @@ public class XQueryVariableBindingTest
/** test the automatic binding of $this to the current node: execQuery() */
@Test
- public void testThisVariable2() throws Exception
+ void testThisVariable2() throws Exception
{
String q =
"for $e in $this/employees/employee " +
@@ -121,7 +116,7 @@ public class XQueryVariableBindingTest
/** test the binding of a variable to the current node: execQuery() */
@Test
- public void testCurrentNodeVariable2() throws Exception {
+ void testCurrentNodeVariable2() throws Exception {
String q =
"for $e in $cur/employees/employee " +
"let $s := $e/address/state " +
@@ -135,7 +130,7 @@ public class XQueryVariableBindingTest
}
}
- private XmlObject[] _execute(XmlObject xo, Map m, String q) {
+ private XmlObject[] _execute(XmlObject xo, Map<String,Object> m, String q) {
XmlOptions opts = new XmlOptions();
opts.setXqueryVariables(m);
return xo.execQuery(q, opts);
@@ -143,8 +138,8 @@ public class XQueryVariableBindingTest
/** test the binding of a variable to an XmlTokenSource using a map */
@Test
- public void testOneVariable() throws Exception {
- File f = new File(dir, "bookstore.xml");
+ void testOneVariable() throws Exception {
+ File f = new File(DIR, "bookstore.xml");
XmlObject doc = XmlObject.Factory.parse(f);
String q =
"declare variable $rt external; " +
@@ -164,8 +159,8 @@ public class XQueryVariableBindingTest
at the same time, test the binding of a variable to a String
*/
@Test
- public void testMultipleVariables() throws Exception {
- File f = new File(dir, "bookstore.xml");
+ void testMultipleVariables() throws Exception {
+ File f = new File(DIR, "bookstore.xml");
XmlObject doc = XmlObject.Factory.parse(f);
String q =
"declare variable $rt external; " +
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/AssortedTests.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/AssortedTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/AssortedTests.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/AssortedTests.java Sun Feb 6 01:51:55 2022
@@ -23,18 +23,18 @@ import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlTime;
import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import xint.test.PositionDocument;
import java.math.BigInteger;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public class AssortedTests {
// bug 27489
@Test
- public void testSaverCharEscaping() throws XmlException {
+ void testSaverCharEscaping() throws XmlException {
XmlObject xdoc = XmlObject.Factory.parse("<test>something</test>");
try (XmlCursor cur = xdoc.newCursor()) {
cur.toFirstChild();
@@ -55,17 +55,17 @@ public class AssortedTests {
// bug 26140/26104
@Test
- public void testNoTypeInvalid() throws XmlException {
+ void testNoTypeInvalid() throws XmlException {
XmlObject xdoc = XmlObject.Factory.parse("<test-no-type>something</test-no-type>");
- assertTrue("Untyped document should be invalid", !xdoc.validate());
+ assertFalse(xdoc.validate(), "Untyped document should be invalid");
xdoc = XmlObject.Factory.parse("<x:blah xmlns:x=\"http://no-type.com/\"/>");
- assertTrue("Untyped document should be invalid", !xdoc.validate());
+ assertFalse(xdoc.validate(), "Untyped document should be invalid");
}
// bug 26790
@Test
- public void testComplexSetter() throws XmlException {
+ void testComplexSetter() throws XmlException {
XmlPurchaseOrderDocumentBean xdoc = XmlPurchaseOrderDocumentBean.Factory.parse(
"<purchase-order xmlns='http://openuri.org/easypo'>" +
"<customer>" +
@@ -117,7 +117,7 @@ public class AssortedTests {
// bug 45338
@Test
- public void testComplexGetter() throws Exception {
+ void testComplexGetter() throws Exception {
XmlPurchaseOrderDocumentBean xdoc =
XmlPurchaseOrderDocumentBean.Factory.parse(
"<purchase-order xmlns='http://openuri.org/easypo'" +
@@ -146,7 +146,7 @@ public class AssortedTests {
}
@Test
- @Ignore
+ @Disabled
public void testPrettyPrint() throws Exception {
XmlObject xobj = XmlObject.Factory.parse("<test xmlns:x='foo'><SHOULDNOTBEATAG><a>simple<b/></a><ALSOSHOULDNOTBEATAG></test>");
// System.out.println(xobj);
@@ -168,7 +168,7 @@ public class AssortedTests {
}
@Test
- @Ignore
+ @Disabled
public void testQNameCopy() throws Exception {
SchemaDocument xobj = SchemaDocument.Factory.parse(
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
@@ -176,12 +176,11 @@ public class AssortedTests {
SchemaDocument xobj2 = SchemaDocument.Factory.parse(
"<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'/>");
xobj2.getSchema().addNewElement().set(xobj.getSchema().getElementArray(0));
- System.out.println(xobj2);
}
// don't run on normal drt because it's too slow: about 20-30 secs
@Test
- @Ignore
+ @Disabled
public void testCursorFinalize() {
XmlObject obj = XmlObject.Factory.newInstance();
int i = 0;
@@ -198,7 +197,7 @@ public class AssortedTests {
}
@Test
- public void testOutOfRange() throws Exception {
+ void testOutOfRange() throws Exception {
PositionDocument doc = PositionDocument.Factory.parse("<position xmlns='java:int.test'><lat>43</lat><lon>037</lon></position>");
assertEquals(43, doc.getPosition().getLat());
assertEquals(37, doc.getPosition().getLon());
@@ -207,13 +206,13 @@ public class AssortedTests {
doc = PositionDocument.Factory.parse("<position xmlns='java:int.test'><lat>443</lat><lon>737</lon></position>");
assertEquals(443, doc.getPosition().getLat());
assertEquals(737, doc.getPosition().getLon());
- assertTrue(!doc.validate());
+ assertFalse(doc.validate());
doc.getPosition().setLat((short) -300);
doc.getPosition().setLon((short) 32767);
assertEquals(-300, doc.getPosition().getLat());
assertEquals(32767, doc.getPosition().getLon());
- assertTrue(!doc.validate());
+ assertFalse(doc.validate());
doc.getPosition().setLat((short) 43);
doc.getPosition().setLon((short) 127);
@@ -223,7 +222,7 @@ public class AssortedTests {
}
@Test
- public void testParse() throws Exception {
+ void testParse() throws Exception {
XmlTime xt = XmlTime.Factory.parse("<xml-fragment>12:00:00</xml-fragment>");
assertEquals("12:00:00", xt.getCalendarValue().toString());
}
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/CDataTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/CDataTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/CDataTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/CDataTest.java Sun Feb 6 01:51:55 2022
@@ -19,95 +19,51 @@ import org.apache.xmlbeans.SystemPropert
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
-import static org.junit.Assert.assertEquals;
+import java.util.Objects;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for finner CData control feature.
*/
public class CDataTest {
- private static final String NL = SystemProperties.getProperty("line.separator") != null ?
- SystemProperties.getProperty("line.separator") :
- (System.getProperty("line.separator") != null ? System.getProperty("line.separator") : "\n");
-
- @Test
- public void testCData1() throws Exception {
- String xmlText = "<a><![CDATA[cdata text]]></a>";
- checkCData(xmlText, xmlText, xmlText);
- }
-
- @Test
- @Ignore("Bookmark doesn't seem to keep the length of the CDATA")
- public void testCData2() throws Exception {
- String xmlText =
- "<a>" + NL +
- "<b><![CDATA[cdata text]]> regular text</b>" + NL +
- "</a>";
- String expected1 =
- "<a>\n" +
- "<b>cdata text regular text</b>\n" +
- "</a>";
- String expected2 =
- "<a>" + NL +
- " <b>cdata text regular text</b>" + NL +
- "</a>";
-
- checkCData(xmlText, expected1, expected2);
- }
- @Test
- public void testCData3() throws Exception {
- String xmlText =
- "<a>\n" +
- "<c>text <![CDATA[cdata text]]></c>\n" +
- "</a>";
- String expected1 =
- "<a>\n" +
- "<c>text cdata text</c>\n" +
- "</a>";
- String expected2 =
- "<a>" + NL +
- " <c>text cdata text</c>" + NL +
- "</a>";
-
- checkCData(xmlText, expected1, expected2);
- }
-
- // https://issues.apache.org/jira/browse/XMLBEANS-404
- @Test
- public void testXmlBeans404()
- throws Exception {
- String xmlText =
- "<a>\n" +
- "<c>text <![CDATA[cdata text]]]]></c>\n" +
- "</a>";
- String expected1 =
- "<a>\n" +
- "<c>text cdata text]]</c>\n" +
- "</a>";
- String expected2 =
- "<a>" + NL +
- " <c>text cdata text]]</c>" + NL +
- "</a>";
-
- checkCData(xmlText, expected1, expected2);
- }
+ @ParameterizedTest
+ @CsvSource(value = {
+ "'<a><![CDATA[cdata text]]></a>'," +
+ "'<a><![CDATA[cdata text]]></a>'," +
+ "'<a><![CDATA[cdata text]]></a>'",
+ // Bookmark doesn't seem to keep the length of the CDATA
+ // "<a>NL<b><![CDATA[cdata text]]> regular text</b>NL</a>," +
+ // "<a>\n<b>cdata text regular text</b>\n</a>," +
+ // "<a>NL <b>cdata text regular text</b>NL</a>"
+ "'<a>\n<c>text <![CDATA[cdata text]]></c>\n</a>'," +
+ "'<a>\n<c>text cdata text</c>\n</a>'," +
+ "'<a>NL <c>text cdata text</c>NL</a>'",
+ // https://issues.apache.org/jira/browse/XMLBEANS-404
+ "'<a>\n<c>text <![CDATA[cdata text]]]]></c>\n</a>'," +
+ "'<a>\n<c>text cdata text]]</c>\n</a>'," +
+ "'<a>NL <c>text cdata text]]</c>NL</a>'"
+ })
+ void checkCData(String xmlText, String expected1, String expected2) throws XmlException {
+ String NL = Stream.of(SystemProperties.getProperty("line.separator"),System.getProperty("line.separator"),"\n")
+ .filter(Objects::nonNull).findFirst().get();
- private void checkCData(String xmlText, String expected1, String expected2)
- throws XmlException {
XmlOptions opts = new XmlOptions();
opts.setUseCDataBookmarks();
- XmlObject xo = XmlObject.Factory.parse(xmlText, opts);
+ XmlObject xo = XmlObject.Factory.parse(xmlText.replace("NL", NL), opts);
String result1 = xo.xmlText(opts);
- assertEquals("xmlText", expected1, result1);
+ assertEquals(expected1.replace("NL", NL), result1, "xmlText");
opts.setSavePrettyPrint();
String result2 = xo.xmlText(opts);
- assertEquals("prettyPrint", expected2, result2);
+ assertEquals(expected2.replace("NL", NL), result2, "prettyPrint");
}
}
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/CreationTests.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/CreationTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/CreationTests.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/CreationTests.java Sun Feb 6 01:51:55 2022
@@ -19,19 +19,18 @@ import com.easypo.XmlLineItemBean;
import com.easypo.XmlPurchaseOrderDocumentBean;
import com.easypo.XmlPurchaseOrderDocumentBean.PurchaseOrder;
import com.easypo.XmlShipperBean;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.math.BigInteger;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class CreationTests {
@Test
- public void testCreatePo() {
- XmlPurchaseOrderDocumentBean doc =
- XmlPurchaseOrderDocumentBean.Factory.newInstance();
+ void testCreatePo() {
+ XmlPurchaseOrderDocumentBean doc = XmlPurchaseOrderDocumentBean.Factory.newInstance();
PurchaseOrder order = doc.addNewPurchaseOrder();
order.addNewCustomer().setName("David Bau");
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/DumbTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/DumbTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/DumbTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/DumbTest.java Sun Feb 6 01:51:55 2022
@@ -17,33 +17,17 @@ package xmlobject.checkin;
import dumbNS.RootDocument;
import dumbNS.RootDocument.Root;
-import org.apache.xmlbeans.XmlObject;
-import org.junit.Before;
-import org.junit.Test;
-import tools.util.JarUtil;
+import org.junit.jupiter.api.Test;
-import java.io.IOException;
-
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static xmlcursor.common.BasicCursorTestCase.jobj;
public class DumbTest {
- private String instance;
-
- @Before
- public void setUp() throws IOException {
- instance = JarUtil.getResourceFromJar("xbean/simple/dumb/dumb.xml");
- }
-
@Test
- public void testGetB2()
- throws Exception {
- RootDocument rootDoc = (RootDocument) XmlObject.Factory
- .parse(instance);
+ void testGetB2() throws Exception {
+ RootDocument rootDoc = (RootDocument) jobj("xbean/simple/dumb/dumb.xml");
Root root = rootDoc.getRoot();
-
- System.out.println("root.xmlText() = " + root.xmlText());
-
- assertEquals("bar:b attribute != 4", 4, root.getB2().intValue());
+ assertEquals(4, root.getB2().intValue(), "bar:b attribute != 4");
}
}
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/EasyPoTests.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/EasyPoTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/EasyPoTests.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/EasyPoTests.java Sun Feb 6 01:51:55 2022
@@ -18,21 +18,21 @@ package xmlobject.checkin;
import com.easypo.XmlPurchaseOrderDocumentBean;
import com.easypo.XmlPurchaseOrderDocumentBean.PurchaseOrder;
import org.apache.xmlbeans.XmlException;
-import org.apache.xmlbeans.XmlObject;
-import org.junit.Test;
-import tools.util.JarUtil;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import java.math.BigDecimal;
import java.math.BigInteger;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static xmlcursor.common.BasicCursorTestCase.jobj;
public class EasyPoTests {
@Test
- public void testEasyPo() throws Exception {
- XmlPurchaseOrderDocumentBean doc = (XmlPurchaseOrderDocumentBean)
- XmlObject.Factory.parse(JarUtil.getResourceFromJarasFile(
- "xbean/xmlobject/easypo1.xml"));
+ void testEasyPo() throws Exception {
+ XmlPurchaseOrderDocumentBean doc = (XmlPurchaseOrderDocumentBean) jobj("xbean/xmlobject/easypo1.xml");
assertFalse(doc.isNil());
PurchaseOrder order = doc.getPurchaseOrder();
assertEquals("David Bau", order.getCustomer().getName());
@@ -62,43 +62,20 @@ public class EasyPoTests {
}
@Test
- public void testSimpleAutoValidaiton() throws Exception {
- XmlPurchaseOrderDocumentBean.Factory.parse(
- "<purchase-order xmlns='http://openuri.org/easypo'/>");
-
- try {
- XmlPurchaseOrderDocumentBean.Factory.parse(
- "<purchase-orde xmlns='http://openuri.org/easypo'/>");
- fail();
- } catch (XmlException e) {
- }
-
- try {
- XmlPurchaseOrderDocumentBean.Factory.parse(
- "<purchase-order xmlns='http://openuri.org/easyp'/>");
- fail();
- } catch (XmlException e) {
- }
-
- try {
- XmlPurchaseOrderDocumentBean.Factory.parse(
- "<f:fragment xmlns:f='http://www.openuri.org/fragment'/>");
- fail();
- } catch (XmlException e) {
- }
-
- try {
- XmlPurchaseOrderDocumentBean.Factory.parse(
- "<f:fragment xmlns:f='http://www.openuri.org/fragment'><a/></f:fragment>");
- fail();
- } catch (XmlException e) {
- }
-
- try {
- XmlPurchaseOrderDocumentBean.Factory.parse(
- "<f:fragment xmlns:f='http://www.openuri.org/fragment'><a/><a/></f:fragment>");
- fail();
- } catch (XmlException e) {
- }
+ void testAutoValidationOk() {
+ Assertions.assertDoesNotThrow(() -> XmlPurchaseOrderDocumentBean.Factory.parse(
+ "<purchase-order xmlns='http://openuri.org/easypo'/>"));
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {
+ "<purchase-orde xmlns='http://openuri.org/easypo'/>",
+ "<purchase-order xmlns='http://openuri.org/easyp'/>",
+ "<f:fragment xmlns:f='http://www.openuri.org/fragment'/>",
+ "<f:fragment xmlns:f='http://www.openuri.org/fragment'><a/></f:fragment>",
+ "<f:fragment xmlns:f='http://www.openuri.org/fragment'><a/><a/></f:fragment>"
+ })
+ void testSimpleAutoValidationNok(String xml) {
+ assertThrows(XmlException.class, () -> XmlPurchaseOrderDocumentBean.Factory.parse(xml));
}
}
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/InstanceValidationTests.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/InstanceValidationTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/InstanceValidationTests.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/InstanceValidationTests.java Sun Feb 6 01:51:55 2022
@@ -17,7 +17,7 @@ package xmlobject.checkin;
import org.apache.xmlbeans.*;
import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import tools.util.JarUtil;
import javax.xml.namespace.QName;
@@ -27,13 +27,9 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public class InstanceValidationTests {
- static String[] _args;
- static String _test;
-
-
private SchemaTypeLoader makeSchemaTypeLoader(String[] schemas) throws XmlException {
XmlObject[] schemaDocs = new XmlObject[schemas.length];
@@ -55,14 +51,14 @@ public class InstanceValidationTests {
}
- private List performValidation(String[] schemas, String instances) throws XmlException {
+ private List<XmlError> performValidation(String[] schemas, String instances) throws XmlException {
SchemaTypeLoader stl = makeSchemaTypeLoader(schemas);
XmlOptions options = new XmlOptions();
XmlObject x = stl.parse(instances, null, options);
- List xel = new ArrayList();
+ List<XmlError> xel = new ArrayList<>();
options.setErrorListener(xel);
x.validate(options);
@@ -71,16 +67,14 @@ public class InstanceValidationTests {
}
@Test
- public void testValidationElementError() throws XmlException {
+ void testValidationElementError() throws XmlException {
String bobSchema = "<xs:schema\n" + " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" + " xmlns:bob='http://openuri.org/bobschema'\n" + " targetNamespace='http://openuri.org/bobschema'\n" + " elementFormDefault='qualified'>\n" + "\n" + " <xs:complexType name='biff'>\n" + " <xs:complexContent>\n" + " <xs:extension base='bob:foo'>\n" + " <xs:sequence>\n" + " <xs:element name='a' minOccurs='0' maxOccurs='unbounded'/>\n" + " </xs:sequence>\n" + " </xs:extension>\n" + " </xs:complexContent>\n" + " </xs:complexType>\n" + "" + " <xs:complexType name='foo'>\n" + " </xs:complexType>\n" + "" + " <xs:element name='foo' type='bob:foo'>\n" + " </xs:element>\n" + "" + "</xs:schema>\n";
String invalid = "<bob:foo xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:bob='http://openuri.org/bobschema' " + "xsi:type='bob:biff'><bob:q/></bob:foo>";
String[] schemas = {bobSchema};
- List errors = null;
-
- errors = performValidation(schemas, invalid);
+ List<XmlError> errors = performValidation(schemas, invalid);
assertNotNull(errors);
assertTrue(errors.size() > 0);
@@ -94,7 +88,7 @@ public class InstanceValidationTests {
}
@Test
- public void testValidationAttributeError() throws XmlException {
+ void testValidationAttributeError() throws XmlException {
String empSchema =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n" +
@@ -131,8 +125,6 @@ public class InstanceValidationTests {
"</xs:schema>\n";
String[] schemas = {empSchema};
- List errors = null;
-
String xmlInstance = "<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >" +
"<person employee='past'>" +
"<name>joe blow</name>" +
@@ -143,7 +135,7 @@ public class InstanceValidationTests {
"<age>29</age>" +
"</person>" +
"</empRecords>";
- errors = performValidation(schemas, xmlInstance);
+ List<XmlError> errors = performValidation(schemas, xmlInstance);
assertNotNull(errors);
assertTrue(errors.size() > 0);
@@ -157,7 +149,7 @@ public class InstanceValidationTests {
}
@Test
- public void testValidationIncorrectElementError() throws XmlException {
+ void testValidationIncorrectElementError() throws XmlException {
String empSchema =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n" +
@@ -194,8 +186,6 @@ public class InstanceValidationTests {
"</xs:schema>\n";
String[] schemas = {empSchema};
- List errors = null;
-
String xmlInstance =
"<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >" +
"<person employee='past'>" +
@@ -207,11 +197,11 @@ public class InstanceValidationTests {
"</person>" +
"</empRecords>";
- errors = performValidation(schemas, xmlInstance);
+ List<XmlError> errors = performValidation(schemas, xmlInstance);
assertNotNull(errors);
assertTrue(errors.size() > 0);
- Iterator it = errors.iterator();
+ Iterator<XmlError> it = errors.iterator();
assertTrue(it.hasNext());
XmlValidationError xmlValError = (XmlValidationError) it.next();
@@ -230,7 +220,7 @@ public class InstanceValidationTests {
}
@Test
- public void testValidationElementNotAllowedError() throws XmlException {
+ void testValidationElementNotAllowedError() throws XmlException {
String empSchema =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n" +
@@ -267,8 +257,6 @@ public class InstanceValidationTests {
"</xs:schema>\n";
String[] schemas = {empSchema};
- List errors = null;
-
String xmlInstance =
"<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >" +
"<person employee='past'>" +
@@ -280,7 +268,7 @@ public class InstanceValidationTests {
"<age>29</age>" +
"</person>" +
"</empRecords>";
- errors = performValidation(schemas, xmlInstance);
+ List<XmlError> errors = performValidation(schemas, xmlInstance);
assertNotNull(errors);
// todo: enable this assert Assert.assertTrue(errors.size()>0);
@@ -294,7 +282,7 @@ public class InstanceValidationTests {
}
@Test
- public void testValidationAttributeTypeError() throws XmlException {
+ void testValidationAttributeTypeError() throws XmlException {
String empSchema =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n" +
@@ -331,8 +319,6 @@ public class InstanceValidationTests {
"</xs:schema>\n";
String[] schemas = {empSchema};
- List errors = null;
-
String xmlInstance = "<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >" +
"<person employee='past'>" +
"<name>joe blow</name>" +
@@ -343,7 +329,7 @@ public class InstanceValidationTests {
"<age>junk</age>" +
"</person>" +
"</empRecords>";
- errors = performValidation(schemas, xmlInstance);
+ List<XmlError> errors = performValidation(schemas, xmlInstance);
assertNotNull(errors);
assertTrue(errors.size() > 0);
@@ -355,7 +341,7 @@ public class InstanceValidationTests {
}
@Test
- public void testElementError() throws XmlException {
+ void testElementError() throws XmlException {
String bobSchema =
"<xs:schema\n" +
" xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
@@ -384,19 +370,18 @@ public class InstanceValidationTests {
String[] schemas = {bobSchema};
- List errors = performValidation(schemas, invalid);
+ List<XmlError> errors = performValidation(schemas, invalid);
assertNotNull(errors);
assertTrue(errors.size() > 0);
- for (Object error : errors) {
- XmlError xmlError = (XmlError) error;
- assertEquals(xmlError.getMessage(), "Expected element 'a@http://openuri.org/bobschema' instead of 'q@http://openuri.org/bobschema' here in element foo@http://openuri.org/bobschema");
+ for (XmlError error : errors) {
+ assertEquals(error.getMessage(), "Expected element 'a@http://openuri.org/bobschema' instead of 'q@http://openuri.org/bobschema' here in element foo@http://openuri.org/bobschema");
// todo check XmlValidationError
}
}
@Test
- public void testAttributeError() throws XmlException {
+ void testAttributeError() throws XmlException {
String empSchema =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>\n" +
@@ -433,8 +418,6 @@ public class InstanceValidationTests {
"</xs:schema>\n";
String[] schemas = {empSchema};
- List errors = null;
-
String xmlInstance =
"<empRecords xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >" +
"<person employee='past'>" +
@@ -446,27 +429,25 @@ public class InstanceValidationTests {
"<age>29</age>" +
"</person>" +
"</empRecords>";
- errors = performValidation(schemas, xmlInstance);
+ List<XmlError> errors = performValidation(schemas, xmlInstance);
assertNotNull(errors);
assertTrue(errors.size() > 0);
- for (Object error : errors) {
- XmlError xmlError = (XmlError) error;
- assertEquals(xmlError.getMessage(), "Expected attribute: employee in element person");
+ for (XmlError error : errors) {
+ assertEquals(error.getMessage(), "Expected attribute: employee in element person");
// todo check XmlValidationError
}
}
@Test
- public void testValidate0() throws Exception {
+ void testValidate0() throws Exception {
//
// The most basic schema
//
String schema =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
- "</xs:schema>" +
- "";
+ "</xs:schema>";
String[] schemas = {schema};
@@ -483,8 +464,7 @@ public class InstanceValidationTests {
" <xs:any namespace='##targetNamespace'/>\n" +
" </xs:sequence>\n" +
" </xs:complexType>\n" +
- "</xs:schema>" +
- "";
+ "</xs:schema>";
String[] schemas99 = {schema};
@@ -494,16 +474,14 @@ public class InstanceValidationTests {
// A big, nasty schema :-)
//
- File schemeFile =
- JarUtil.getResourceFromJarasFile("xbean/xmlobject/store/XMLSchema.xsd");
+ File schemeFile = JarUtil.getResourceFromJarasFile("xbean/xmlobject/store/XMLSchema.xsd");
File xmlFile = JarUtil.getResourceFromJarasFile("xbean/xmlobject/store/XML.xsd");
File[] schemasF = {schemeFile, xmlFile};
stl = makeSchemaTypeLoader(schemasF);
- SchemaType type =
- stl.findDocumentType(
+ SchemaType type = stl.findDocumentType(
new QName("http://www.w3.org/2001/XMLSchema", "schema"));
assertNotNull(type);
@@ -537,12 +515,7 @@ public class InstanceValidationTests {
schema = "<foo/>";
String[] schemas2 = {schema};
-
- try {
- stl = makeSchemaTypeLoader(schemas2);
- fail();
- } catch (Exception e) {
- }
+ assertThrows(Exception.class, () -> makeSchemaTypeLoader(schemas2));
//
// A bad schema
@@ -550,21 +523,14 @@ public class InstanceValidationTests {
schema =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
" <foo/>\n" +
- "</xs:schema>" +
- "";
+ "</xs:schema>";
String[] schemas3 = {schema};
-
- try {
- makeSchemaTypeLoader(schemas3);
-
- fail();
- } catch (XmlException e) {
- }
+ assertThrows(Exception.class, () -> makeSchemaTypeLoader(schemas3));
}
@Test
- public void testValidate1() throws Exception {
+ void testValidate1() throws Exception {
String ericSchema =
"<xs:schema\n" +
" xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
@@ -654,7 +620,7 @@ public class InstanceValidationTests {
}
@Test
- public void testValidate2() throws Exception {
+ void testValidate2() throws Exception {
String bobSchema =
"<xs:schema\n" +
" xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
@@ -698,7 +664,7 @@ public class InstanceValidationTests {
}
@Test
- public void testValidate3() throws Exception {
+ void testValidate3() throws Exception {
String schema =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
"" +
@@ -1167,7 +1133,7 @@ public class InstanceValidationTests {
@Test
- public void testValidate5() throws Exception {
+ void testValidate5() throws Exception {
String schema =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
"\n" +
@@ -1223,13 +1189,13 @@ public class InstanceValidationTests {
"<hee yee='five'><haw>66</haw></hee>",
null, null);
- assertTrue(!x.validate());
+ assertFalse(x.validate());
try (XmlCursor c = x.newCursor()) {
c.toNextToken();
c.toNextToken();
- assertTrue(!c.getObject().validate());
+ assertFalse(c.getObject().validate());
}
// No schema
@@ -1248,8 +1214,8 @@ public class InstanceValidationTests {
}
}
- @Test(expected = XmlException.class)
- public void testValidate6() throws Exception {
+ @Test
+ void testValidate6() throws Exception {
String schema =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
" <xs:element name='hee'>\n" +
@@ -1261,11 +1227,11 @@ public class InstanceValidationTests {
// Should get a schema compile error
- makeSchemaTypeLoader(schemas);
+ assertThrows(XmlException.class, () -> makeSchemaTypeLoader(schemas));
}
@Test
- public void testValidate7() throws Exception {
+ void testValidate7() throws Exception {
String schema =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
"" +
@@ -1308,7 +1274,7 @@ public class InstanceValidationTests {
c.toEndToken();
c.insertElement("bar");
- assertTrue(!x.validate());
+ assertFalse(x.validate());
c.toPrevSibling();
@@ -1326,7 +1292,7 @@ public class InstanceValidationTests {
// Tests abstract & block attributes on ComplexType
@Test
- public void testValidate8() throws Exception {
+ void testValidate8() throws Exception {
String[] schemas = {
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
"" +
@@ -1375,7 +1341,7 @@ public class InstanceValidationTests {
}
@Test
- public void testValidate9() throws Exception {
+ void testValidate9() throws Exception {
String[] schemas = {
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
@@ -1664,7 +1630,7 @@ public class InstanceValidationTests {
// Test validation of setting with the ValidateOnSet option
@Test
- public void testValidate10() throws Exception {
+ void testValidate10() throws Exception {
String schema =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
" <xs:simpleType name='dec-restriction'>" +
@@ -1683,22 +1649,16 @@ public class InstanceValidationTests {
SchemaType st = stl.findType(new QName("", "dec-restriction"));
- XmlDecimal dec = (XmlDecimal) stl.newInstance(st, validate);
-
- try {
- dec.setStringValue("200");
- fail("Expected XmlValueOutOfRangeException");
- } catch (XmlValueOutOfRangeException e) {
- }
-
- dec = (XmlDecimal) stl.newInstance(st, noValidate);
+ XmlDecimal dec1 = (XmlDecimal) stl.newInstance(st, validate);
+ assertThrows(XmlValueOutOfRangeException.class, () -> dec1.setStringValue("200"));
- dec.setStringValue("200");
+ XmlDecimal dec2 = (XmlDecimal) stl.newInstance(st, noValidate);
+ dec2.setStringValue("200");
}
// tests numeral validation
@Test
- public void testValidate11() throws Exception {
+ void testValidate11() throws Exception {
String schema =
"<xs:schema\n" +
" xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" +
@@ -1760,7 +1720,7 @@ public class InstanceValidationTests {
// Bugzilla bug #26105: validate derived type from base type enumeration
@Test
- public void testValidate12() throws Exception {
+ void testValidate12() throws Exception {
String[] schemas = {
"<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>\n" +
@@ -1791,7 +1751,7 @@ public class InstanceValidationTests {
}
@Test
- public void testValidateNestedGroups() throws Exception {
+ void testValidateNestedGroups() throws Exception {
// This is a weird Schema, inspired from JIRA bug XMLBEANS-35
// Make sure we compile it and then validate correctly
String[] schemas = {
@@ -1903,7 +1863,7 @@ public class InstanceValidationTests {
XmlObject x;
try {
- x = stl.parse((String) invalidInstances[i], null, options);
+ x = stl.parse(invalidInstances[i], null, options);
if (!startOnDocument) {
try (XmlCursor c = x.newCursor()) {
@@ -1922,7 +1882,7 @@ public class InstanceValidationTests {
}
assertFalse(isValid);
- } catch (XmlException e) {
+ } catch (XmlException ignored) {
}
}
}
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/NameworldTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/NameworldTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/NameworldTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/NameworldTest.java Sun Feb 6 01:51:55 2022
@@ -15,29 +15,26 @@
package xmlobject.checkin;
-import org.apache.xmlbeans.XmlObject;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.openuri.nameworld.Loc;
import org.openuri.nameworld.NameworldDocument;
-import org.openuri.nameworld.NameworldDocument.Nameworld;
-import tools.util.JarUtil;
import javax.xml.namespace.QName;
+import java.util.stream.Stream;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static xmlcursor.common.BasicCursorTestCase.jobj;
public class NameworldTest {
@Test
- public void testWorld1() throws Exception {
- NameworldDocument doc = (NameworldDocument)
- XmlObject.Factory.parse(
- JarUtil.getResourceFromJarasFile(
- "xbean/xmlobject/nameworld.xml"));
+ void testWorld1() throws Exception {
+ NameworldDocument doc = (NameworldDocument) jobj("xbean/xmlobject/nameworld.xml");
+ QName expected = new QName("http://openuri.org/nameworld", "nameworld");
+ assertEquals(expected, doc.schemaType().getDocumentElementName());
- assertEquals(new QName("http://openuri.org/nameworld", "nameworld"), doc.schemaType().getDocumentElementName());
-
- QName[] contents = {
+ QName[] exp = {
new QName("http://bar.com/", "barcity"),
new QName("http://foo.com/", "footown"),
new QName("http://bar.com/", "barvillage"),
@@ -51,18 +48,13 @@ public class NameworldTest {
new QName("http://bar.com/", "barvillage"),
new QName("http://foo.com/", "foovillage"),
};
- int t = 0;
- Nameworld world = doc.getNameworld();
- Nameworld.Island[] islands = world.getIslandArray();
- for (int i = 0; i < islands.length; i++) {
- Loc[] locs = islands[i].getLocationArray();
- for (int j = 0; j < locs.length; j++) {
- Loc.Reference[] refs = locs[j].getReferenceArray();
- for (int k = 0; k < refs.length; k++) {
- assertEquals(contents[t++], refs[k].getTo());
- }
- }
- }
+ QName[] act = Stream.of(doc.getNameworld().getIslandArray())
+ .flatMap(island -> Stream.of(island.getLocationArray()))
+ .flatMap(loc -> Stream.of(loc.getReferenceArray()))
+ .map(Loc.Reference::getTo)
+ .toArray(QName[]::new);
+
+ assertArrayEquals(exp, act);
}
}
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/RedefineTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/RedefineTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/RedefineTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/RedefineTest.java Sun Feb 6 01:51:55 2022
@@ -14,10 +14,11 @@
*/
package xmlobject.checkin;
+import org.apache.xmlbeans.XmlError;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
import org.example.prod.NewSizeDocument;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.openuri.versionstest.ElementDocument;
import org.openuri.versionstest.Type;
import org.openuri.versionstest.TypeX;
@@ -25,11 +26,11 @@ import org.openuri.versionstest.TypeX;
import java.util.ArrayList;
import java.util.List;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public class RedefineTest {
@Test
- public void testRedefine() throws XmlException {
+ void testRedefine() throws XmlException {
String xml = "<newSize xmlns='http://example.org/prod'>7</newSize>";
NewSizeDocument nsDoc = NewSizeDocument.Factory.parse(xml);
@@ -41,7 +42,7 @@ public class RedefineTest {
nsDoc.setNewSize(20);
- List errors = new ArrayList();
+ List<XmlError> errors = new ArrayList<>();
XmlOptions options = new XmlOptions();
options.setErrorListener(errors);
@@ -53,7 +54,7 @@ public class RedefineTest {
}
@Test
- public void testMultipleRedefine() throws XmlException {
+ void testMultipleRedefine() throws XmlException {
String xml = "<v:element xmlns:v='http://openuri.org/versionstest'>" +
"<aa>AA</aa><a>A</a><b>B</b><c>C</c>" + "</v:element>";
ElementDocument doc = ElementDocument.Factory.parse(xml);
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/SelectChldAttTests.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/SelectChldAttTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/SelectChldAttTests.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/SelectChldAttTests.java Sun Feb 6 01:51:55 2022
@@ -18,125 +18,121 @@ package xmlobject.checkin;
import org.apache.xml.test.selectChldAtt.DocDocument;
import org.apache.xml.test.selectChldAtt.TypeExtendedC;
import org.apache.xmlbeans.*;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
+import java.util.stream.Stream;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
public class SelectChldAttTests {
private static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
- @Test
- public void testSelect() throws XmlException {
- String uri = "http://xml.apache.org/test/selectChldAtt";
+ private static final String URI = "http://xml.apache.org/test/selectChldAtt";
- String xml = "<doc xmlns='" + uri + "'>\n" +
- " <int>7</int>\n" +
- " <string> ... some text ... </string>\n" +
-
- " <elemA price='4.321'>\n" +
- " <topLevelElement> this is wildcard bucket </topLevelElement>\n" +
- " </elemA>\n" +
-
- " <elemB xmlns:p='uri:other_namespace' \n" +
- " p:att='attribute in #other namespace'>\n" +
- " <someElement>2</someElement>\n" +
- " <p:otherElement> element in #other namespace </p:otherElement>\n" +
- " </elemB>\n" +
-
- " <elemC xmlns:xsi='" + XSI_URI + "' \n" +
- " xmlns:p='uri_other_namespace' \n" +
- " xsi:type='typeExtendedC' \n" +
- " att1='attribute from typeC' \n" +
- " aditionalAtt='attribute added in type extension' \n" +
- " p:validAtt='attribute in any bucket' >\n" +
- " <someElement> element from typeC </someElement>\n" +
- " <p:validElement> element in the 'any' bucket for typeExtendedC </p:validElement>\n" +
- " <aditionalElement> element from typeExtendedC </aditionalElement>\n" +
- " </elemC>\n" +
- "</doc>";
+ private static final String XML =
+ "<doc xmlns='" + URI + "'>\n" +
+ " <int>7</int>\n" +
+ " <string> ... some text ... </string>\n" +
+
+ " <elemA price='4.321'>\n" +
+ " <topLevelElement> this is wildcard bucket </topLevelElement>\n" +
+ " </elemA>\n" +
+
+ " <elemB xmlns:p='uri:other_namespace' \n" +
+ " p:att='attribute in #other namespace'>\n" +
+ " <someElement>2</someElement>\n" +
+ " <p:otherElement> element in #other namespace </p:otherElement>\n" +
+ " </elemB>\n" +
+
+ " <elemC xmlns:xsi='" + XSI_URI + "' \n" +
+ " xmlns:p='uri_other_namespace' \n" +
+ " xsi:type='typeExtendedC' \n" +
+ " att1='attribute from typeC' \n" +
+ " aditionalAtt='attribute added in type extension' \n" +
+ " p:validAtt='attribute in any bucket' >\n" +
+ " <someElement> element from typeC </someElement>\n" +
+ " <p:validElement> element in the 'any' bucket for typeExtendedC </p:validElement>\n" +
+ " <aditionalElement> element from typeExtendedC </aditionalElement>\n" +
+ " </elemC>\n" +
+ "</doc>";
- DocDocument document = DocDocument.Factory.parse(xml);
- DocDocument.Doc doc = document.getDoc();
- Collection errors = new ArrayList();
- assertTrue("Valid instance", doc.validate(new XmlOptions().setErrorListener(errors)));
- printErrors(errors);
- XmlObject xo;
- XmlObject[] xos;
+ @Test
+ void testSelect() throws XmlException {
+ DocDocument document = DocDocument.Factory.parse(XML);
+ DocDocument.Doc doc = document.getDoc();
+ Collection<XmlError> errors = new ArrayList<>();
+ assertTrue(doc.validate(new XmlOptions().setErrorListener(errors)), "Valid instance");
// select a known element
- xos = doc.selectChildren(new QName(uri, "int"));
- //print("1 selectChildren 'int' : ", xos);
- assertTrue("1 selectChildren 'int' : ", verifyResult(xos, new String[]{"<xml-fragment>7</xml-fragment>"}));
-
- xos = doc.selectChildren(uri, "string");
- //print("2 selectChildren 'string' : ", xos);
- assertTrue("2 selectChildren 'string' : ", verifyResult(xos, new String[]{"<xml-fragment> ... some text ... </xml-fragment>"}));
+ String[] act1 = toArray(doc.selectChildren(new QName(URI, "int")));
+ String[] exp1 = {"<xml-fragment>7</xml-fragment>"};
+ assertArrayEquals(exp1, act1, "1 selectChildren 'int'");
+
+ String[] act2 = toArray(doc.selectChildren(URI, "string"));
+ String[] exp2 = {"<xml-fragment> ... some text ... </xml-fragment>"};
+ assertArrayEquals(exp2, act2, "2 selectChildren 'string'");
// elemA
- xos = doc.selectChildren(new QName(uri, "elemA"));
- //print("3 selectChildren 'elemA' : ", xos);
- assertTrue("3 selectChildren 'elemA' : ",
- verifyResult(xos, new String[]{"<xml-fragment price=\"4.321\" xmlns:sel=\"" + uri + "\">\n" +
- " <sel:topLevelElement> this is wildcard bucket </sel:topLevelElement>\n" +
- "</xml-fragment>"}));
+ String[] act3 = toArray(doc.selectChildren(new QName(URI, "elemA")));
+ String[] exp3 = {
+ "<xml-fragment price=\"4.321\" xmlns:sel=\"" + URI + "\">" +
+ " <sel:topLevelElement> this is wildcard bucket </sel:topLevelElement>" +
+ "</xml-fragment>"
+ };
+ assertArrayEquals(exp3, act3, "3 selectChildren 'elemA'");
// select a known attribute
- xo = xos[0].selectAttribute(new QName("", "price"));
- //print("4 selectAttribute 'price' : ", xo);
- assertTrue("4 selectAttribute 'price' : ",
- verifyResult(xo, "<xml-fragment>4.321</xml-fragment>"));
+ final XmlObject xo1 = doc.selectChildren(new QName(URI, "elemA"))[0];
+ String[] act4 = toArray(xo1.selectAttribute(new QName("", "price")));
+ String[] exp4 = {"<xml-fragment>4.321</xml-fragment>"};
+ assertArrayEquals(exp4, act4, "4 selectAttribute 'price'");
// select all attributes
- QNameSet qns = QNameSet.forWildcardNamespaceString("##any", uri);
- xos = xos[0].selectAttributes(qns);
- //print("5 selectAttributes set'##any' :", xos);
- assertTrue("5 selectAttributes set'##any' :",
- verifyResult(xos, new String[]{"<xml-fragment>4.321</xml-fragment>"}));
+ String[] act5 = toArray(xo1.selectAttributes(QNameSet.forWildcardNamespaceString("##any", URI)));
+ String[] exp5 = {"<xml-fragment>4.321</xml-fragment>"};
+ assertArrayEquals(exp5, act5, "5 selectAttributes set'##any'");
// elemB
- xos = doc.selectChildren(new QName(uri, "elemB"));
- //print("6 selectChildren 'elemB' : ", xos);
+ final XmlObject xo6 = doc.selectChildren(new QName(URI, "elemB"))[0];
+ assertNotNull(xo6, "6 selectChildren 'elemB'");
- //print("7 selectChildren set'##other' : " , xos[0].selectChildren(QNameSet.forWildcardNamespaceString("##other", uri)));
- assertTrue("7 selectChildren set'##other' : ",
- verifyResult(xos[0].selectChildren(QNameSet.forWildcardNamespaceString("##other", uri))
- , new String[]{"<xml-fragment xmlns:p=\"uri:other_namespace\"> element in #other namespace </xml-fragment>"}));
- //print("8 selectAttributes set'##other' : ", xos[0].selectAttributes(QNameSet.forWildcardNamespaceString("##other", uri)));
- assertTrue("8 selectAttributes set'##other' : ",
- verifyResult(xos[0].selectAttributes(QNameSet.forWildcardNamespaceString("##other", uri)),
- new String[]{"<xml-fragment xmlns:p=\"uri:other_namespace\">attribute in #other namespace</xml-fragment>"}));
+ String[] act7 = toArray(xo6.selectChildren(QNameSet.forWildcardNamespaceString("##other", URI)));
+ String[] exp7 = {"<xml-fragment xmlns:p=\"uri:other_namespace\"> element in #other namespace </xml-fragment>"};
+ assertArrayEquals(exp7, act7, "7 selectChildren set'##other'");
+
+ String[] act8 = toArray(xo6.selectAttributes(QNameSet.forWildcardNamespaceString("##other", URI)));
+ String[] exp8 = {"<xml-fragment xmlns:p=\"uri:other_namespace\">attribute in #other namespace</xml-fragment>"};
+ assertArrayEquals(exp8, act8, "8 selectAttributes set'##other'");
// elemC
- xos = doc.selectChildren(new QName(uri, "elemC"));
- //print("9 selectChildren 'elemC' : ", xos);
- //print("10 selectChildren set'##any' : " , xos[0].selectChildren(QNameSet.forWildcardNamespaceString("##any", uri)));
- assertTrue("10 selectChildren set'##any' : ",
- verifyResult(xos[0].selectChildren(QNameSet.forWildcardNamespaceString("##any", uri))
- , new String[]{"<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\"> element from typeC </xml-fragment>",
- "<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\"> element in the 'any' bucket for typeExtendedC </xml-fragment>",
- "<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\"> element from typeExtendedC </xml-fragment>"}));
+ XmlObject xo9 = doc.selectChildren(new QName(URI, "elemC"))[0];
+ assertNotNull(xo9, "9 selectChildren 'elemC'");
+
+ String[] act10 = toArray(xo9.selectChildren(QNameSet.forWildcardNamespaceString("##any", URI)));
+ String[] exp10 = {
+ "<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\"> element from typeC </xml-fragment>",
+ "<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\"> element in the 'any' bucket for typeExtendedC </xml-fragment>",
+ "<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\"> element from typeExtendedC </xml-fragment>"
+ };
+ assertArrayEquals(exp10, act10, "10 selectChildren set'##any'");
// select elements in the any bucket by excluding the the known elements
QNameSetBuilder qnsb = new QNameSetBuilder();
- qnsb.add(new QName(uri, "someElement"));
- qnsb.add(new QName(uri, "aditionalElement"));
+ qnsb.add(new QName(URI, "someElement"));
+ qnsb.add(new QName(URI, "aditionalElement"));
qnsb.invert();
- //print("11a selectChildren in the any bucket for typeExtendedC: " , xos[0].selectChildren(qnsb.toQNameSet()));
- assertTrue("11a selectChildren in the any bucket for typeExtendedC: ",
- verifyResult(xos[0].selectChildren(qnsb.toQNameSet()),
- new String[]{"<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\"> element in the 'any' bucket for typeExtendedC </xml-fragment>"}));
-
- //print("11b selectChildren in the any bucket for typeExtendedC: " , xos[0].selectChildren(TypeExtendedC.type.qnameSetForWildcardElements()));
- assertTrue("11b selectChildren in the any bucket for typeExtendedC: ",
- verifyResult(xos[0].selectChildren(TypeExtendedC.type.qnameSetForWildcardElements()),
- new String[]{"<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\"> element in the 'any' bucket for typeExtendedC </xml-fragment>"}));
+ String[] act11a = toArray(xo9.selectChildren(qnsb.toQNameSet()));
+ String[] exp11a = {"<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\"> element in the 'any' bucket for typeExtendedC </xml-fragment>"};
+ assertArrayEquals(exp11a, act11a, "11a selectChildren in the any bucket for typeExtendedC");
+
+ String[] act11b = toArray(xo9.selectChildren(TypeExtendedC.type.qnameSetForWildcardElements()));
+ String[] exp11b = {"<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\"> element in the 'any' bucket for typeExtendedC </xml-fragment>"};
+ assertArrayEquals(exp11b, act11b, "11b selectChildren in the any bucket for typeExtendedC");
// select attributes in the any bucket by excluding the the known attributes
qnsb = new QNameSetBuilder();
@@ -145,83 +141,19 @@ public class SelectChldAttTests {
qnsb.add(new QName(XSI_URI, "type"));
qnsb.invert();
- //print("12a selectChildren in the any bucket for typeExtendedC: " , xos[0].selectAttributes(qnsb.toQNameSet()));
- assertTrue("12a selectChildren in the any bucket for typeExtendedC: ",
- verifyResult(xos[0].selectAttributes(qnsb.toQNameSet()),
- new String[]{"<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\">attribute in any bucket</xml-fragment>"}));
- //print("12b selectChildren in the any bucket for typeExtendedC: " , xos[0].selectAttributes(TypeExtendedC.type.qnameSetForWildcardAttributes()));
- assertTrue("12b selectChildren in the any bucket for typeExtendedC: ",
- verifyResult(xos[0].selectAttributes(TypeExtendedC.type.qnameSetForWildcardAttributes()),
- new String[]{"<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\">typeExtendedC</xml-fragment>",
- "<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\">attribute in any bucket</xml-fragment>"}));
- }
-
- private static void printErrors(Collection errors) {
- for (Iterator i = errors.iterator(); i.hasNext(); ) {
- System.out.println("ERROR: " + i.next());
- }
- }
-
- private static boolean verifyResult(XmlObject[] xos, String[] expected) {
- if (xos == null && expected == null)
- return true;
-
- if (xos == null || expected == null)
- return false;
-
- if (xos.length != expected.length)
- return false;
-
- for (int i = 0; i < xos.length; i++) {
- XmlObject xo = xos[i];
- if (!equalsIgnoreNewLine(xo.toString(), expected[i])) {
- System.out.println("ERROR:\n Actual:\n" + xo.toString() + "\n Expected:\n" + expected[i]);
- return false;
- }
- }
- return true;
+ String[] act12a = toArray(xo9.selectAttributes(qnsb.toQNameSet()));
+ String[] exp12a = {"<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\">attribute in any bucket</xml-fragment>"};
+ assertArrayEquals(exp12a, act12a, "12a selectChildren in the any bucket for typeExtendedC");
+
+ String[] act12b = toArray(xo9.selectAttributes(TypeExtendedC.type.qnameSetForWildcardAttributes()));
+ String[] exp12b = {
+ "<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\">typeExtendedC</xml-fragment>",
+ "<xml-fragment xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:p=\"uri_other_namespace\">attribute in any bucket</xml-fragment>"
+ };
+ assertArrayEquals(exp12b, act12b, "12b selectChildren in the any bucket for typeExtendedC");
}
- private static boolean verifyResult(XmlObject xo, String expected) {
- if (xo == null && expected == null)
- return true;
-
- if (xo == null || expected == null)
- return false;
-
- if (!xo.toString().equals(expected)) {
- System.out.println("ERROR:\n Actual:\n" + xo.toString() + "\n Expected:\n" + expected);
- return false;
- } else
- return true;
- }
-
- private static boolean equalsIgnoreNewLine(String s1, String s2) {
- if (s1 == null && s2 == null)
- return true;
-
- if (s1 == null || s2 == null)
- return false;
-
- int i1 = 0, i2 = 0;
- while (i1 < s1.length() || i2 < s2.length()) {
- if (s1.charAt(i1) == '\n' || s1.charAt(i1) == '\r') {
- i1++;
- continue;
- }
-
- if (s2.charAt(i2) == '\n' || s2.charAt(i2) == '\r') {
- i2++;
- continue;
- }
-
- if (s1.charAt(i1) != s2.charAt(i2))
- return false;
-
- i1++;
- i2++;
- }
-
- return (i1 == s1.length()) && (i2 == s2.length());
+ private static String[] toArray(XmlObject... xos) {
+ return Stream.of(xos).map(XmlObject::toString).map(s -> s.replaceAll("[\\r\\n]", "")).toArray(String[]::new);
}
}
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/SerializationTests.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/SerializationTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/SerializationTests.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/SerializationTests.java Sun Feb 6 01:51:55 2022
@@ -22,7 +22,7 @@ import com.easypo.XmlPurchaseOrderDocume
import com.easypo.XmlShipperBean;
import org.apache.xmlbeans.*;
import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.xml.sax.InputSource;
import tools.util.JarUtil;
@@ -32,12 +32,12 @@ import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class SerializationTests {
@Test
- public void testXmlObjectSerialization() throws Exception {
+ void testXmlObjectSerialization() throws Exception {
String simpleDocument = "<simpleDoc><nestedTag attr=\"sample\">43</nestedTag></simpleDoc>";
XmlObject doc = XmlObject.Factory.parse(simpleDocument);
@@ -59,7 +59,7 @@ public class SerializationTests {
}
@Test
- public void testXBeanSerialization() throws Exception {
+ void testXBeanSerialization() throws Exception {
XmlPurchaseOrderDocumentBean doc = XmlPurchaseOrderDocumentBean.Factory.newInstance();
PurchaseOrder order = doc.addNewPurchaseOrder();
order.addNewCustomer().setName("David Bau");
@@ -129,7 +129,7 @@ public class SerializationTests {
}
@Test
- public void testWsdlSerialization() throws IOException, XmlException {
+ void testWsdlSerialization() throws IOException, XmlException {
// test for TextSaver
File wsdlFile = JarUtil.getResourceFromJarasFile("xbean/xmlobject/wsdl.xml");
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/SetTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/SetTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/SetTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/SetTest.java Sun Feb 6 01:51:55 2022
@@ -14,57 +14,51 @@
*/
package xmlobject.checkin;
-import org.apache.xmlbeans.XmlCalendar;
+import org.apache.xmlbeans.*;
import org.apache.xmlbeans.XmlCursor.TokenType;
-import org.apache.xmlbeans.XmlDate;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import test.xbean.xmlcursor.purchaseOrder.PurchaseOrderDocument;
import test.xbean.xmlcursor.purchaseOrder.USAddress;
-import tools.util.JarUtil;
-import xmlcursor.common.BasicCursorTestCase;
import xmlcursor.common.Common;
import java.util.Calendar;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static xmlcursor.common.BasicCursorTestCase.*;
-public class SetTest extends BasicCursorTestCase {
+public class SetTest {
@Test
- public void testSetFromSTART() throws Exception {
- m_xo = XmlObject.Factory.parse(Common.XML_FOO_1ATTR_TEXT);
- m_xc = m_xo.newCursor();
- toNextTokenOfType(m_xc, TokenType.START);
- XmlObject xo = m_xc.getObject();
- xo.set(XmlString.Factory.newValue("newtext"));
- assertEquals("newtext", m_xc.getTextValue());
+ void testSetFromSTART() throws Exception {
+ try (XmlCursor m_xc = cur(Common.XML_FOO_1ATTR_TEXT)) {
+ toNextTokenOfType(m_xc, TokenType.START);
+ XmlObject xo = m_xc.getObject();
+ xo.set(XmlString.Factory.newValue("newtext"));
+ assertEquals("newtext", m_xc.getTextValue());
+ }
}
@Test
- public void testSetFromATTR() throws Exception {
- m_xo = XmlObject.Factory.parse(Common.XML_FOO_1ATTR_TEXT);
- m_xc = m_xo.newCursor();
- toNextTokenOfType(m_xc, TokenType.ATTR);
- XmlObject xo = m_xc.getObject();
- xo.set(XmlString.Factory.newValue(" new attr text "));
- assertEquals(" new attr text ", m_xc.getTextValue());
+ void testSetFromATTR() throws Exception {
+ try (XmlCursor m_xc = cur(Common.XML_FOO_1ATTR_TEXT)) {
+ toNextTokenOfType(m_xc, TokenType.ATTR);
+ XmlObject xo = m_xc.getObject();
+ xo.set(XmlString.Factory.newValue(" new attr text "));
+ assertEquals(" new attr text ", m_xc.getTextValue());
+ }
}
@Test
- public void testSetFromSTARTstronglyTyped() throws Exception {
- PurchaseOrderDocument pod = (PurchaseOrderDocument) XmlObject.Factory.parse(
- JarUtil.getResourceFromJar("xbean/xmlcursor/po.xml"));
+ void testSetFromSTARTstronglyTyped() throws Exception {
+ PurchaseOrderDocument pod = (PurchaseOrderDocument) jobj("xbean/xmlcursor/po.xml");
XmlString xcomment = pod.getPurchaseOrder().xgetComment();
xcomment.setStringValue("new comment text");
assertEquals("new comment text", pod.getPurchaseOrder().getComment());
}
@Test
- public void testSetFromATTRstronglyTyped() throws Exception {
- PurchaseOrderDocument pod = (PurchaseOrderDocument) XmlObject.Factory.parse(
- JarUtil.getResourceFromJar("xbean/xmlcursor/po.xml"));
+ void testSetFromATTRstronglyTyped() throws Exception {
+ PurchaseOrderDocument pod = (PurchaseOrderDocument) jobj("xbean/xmlcursor/po.xml");
XmlDate xorderDate = pod.getPurchaseOrder().xgetOrderDate();
assertNotNull(xorderDate);
@@ -73,20 +67,15 @@ public class SetTest extends BasicCursor
xorderDate.setCalendarValue(d);
// compare year, month, day of the xsd:date type
- assertEquals(d.get(Calendar.YEAR),
- pod.getPurchaseOrder().getOrderDate().get(Calendar.YEAR));
- assertEquals(d.get(Calendar.MONTH),
- pod.getPurchaseOrder().getOrderDate().get(Calendar.MONTH));
- assertEquals(d.get(Calendar.DAY_OF_MONTH),
- pod.getPurchaseOrder().getOrderDate().get(
- Calendar.DAY_OF_MONTH));
+ assertEquals(d.get(Calendar.YEAR), pod.getPurchaseOrder().getOrderDate().get(Calendar.YEAR));
+ assertEquals(d.get(Calendar.MONTH), pod.getPurchaseOrder().getOrderDate().get(Calendar.MONTH));
+ assertEquals(d.get(Calendar.DAY_OF_MONTH), pod.getPurchaseOrder().getOrderDate().get(Calendar.DAY_OF_MONTH));
}
@Test
- public void testSetFromFixedATTR() throws Exception {
+ void testSetFromFixedATTR() throws Exception {
- PurchaseOrderDocument pod = (PurchaseOrderDocument) XmlObject.Factory.parse(
- JarUtil.getResourceFromJar("xbean/xmlcursor/po.xml"));
+ PurchaseOrderDocument pod = (PurchaseOrderDocument) jobj("xbean/xmlcursor/po.xml");
USAddress usa = pod.getPurchaseOrder().getShipTo();
assertNotNull(usa);
@@ -98,15 +87,13 @@ public class SetTest extends BasicCursor
}
@Test
- public void testSetFromComplexType() throws Exception {
+ void testSetFromComplexType() throws Exception {
- PurchaseOrderDocument pod = (PurchaseOrderDocument) XmlObject.Factory.parse(
- JarUtil.getResourceFromJar("xbean/xmlcursor/po.xml"));
+ PurchaseOrderDocument pod = (PurchaseOrderDocument) jobj("xbean/xmlcursor/po.xml");
USAddress usa = pod.getPurchaseOrder().getShipTo();
assertNotNull(usa);
- usa.set(
- USAddress.Factory.parse(
- "<shipTo country=\"UK\"><name>Fred</name><street>paved</street><city>town</city><state>AK</state><zip>00000</zip></shipTo>"));
+ usa.set(USAddress.Factory.parse(
+ "<shipTo country=\"UK\"><name>Fred</name><street>paved</street><city>town</city><state>AK</state><zip>00000</zip></shipTo>"));
// assertTrue(true);
assertFalse(pod.validate());
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/SubstGroupTests.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/SubstGroupTests.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/SubstGroupTests.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/SubstGroupTests.java Sun Feb 6 01:51:55 2022
@@ -17,22 +17,23 @@ package xmlobject.checkin;
import org.apache.xmlbeans.*;
import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.openuri.sgs.ADocument;
import org.openuri.sgs.BDocument;
import org.openuri.sgs.CDocument;
import org.openuri.sgs.RootDocument;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
public class SubstGroupTests {
@Test
- public void test1() throws Exception {
+ void test1() throws Exception {
String xml1 = "<root xmlns='http://openuri.org/sgs'>" +
- "<A>\ta\ta\t</A>" +
- "<B>\tb\tb\t</B>" +
- "<C>\tc\tc\t</C>" +
- "</root>";
+ "<A>\ta\ta\t</A>" +
+ "<B>\tb\tb\t</B>" +
+ "<C>\tc\tc\t</C>" +
+ "</root>";
RootDocument doc1 = RootDocument.Factory.parse(xml1);
@@ -80,7 +81,7 @@ public class SubstGroupTests {
}
@Test
- public void test2() throws Exception {
+ void test2() throws Exception {
String xml1 = "<A xmlns='http://openuri.org/sgs'>\ta\ta\t</A>";
String xml2 = "<B xmlns='http://openuri.org/sgs'>\tb\tb\t</B>";
String xml3 = "<C xmlns='http://openuri.org/sgs'>\tc\tc\t</C>";
@@ -105,128 +106,118 @@ public class SubstGroupTests {
private static final String[] invalidSchemas = {
"<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
- " <xsd:element name='A' type='xsd:string'/> " +
- " <xsd:element name='B' type='xsd:int' substitutionGroup='A'/> " +
- "</xsd:schema>",
- "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
- " <xsd:complexType name='foo'> " +
- " <xsd:sequence> " +
- " <xsd:element name='bar' substitutionGroup='A'/>" +
- " </xsd:sequence> " +
- " </xsd:complexType>" +
- "</xsd:schema>",
- "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
- " <xsd:element name='A' type='xsd:string' final='#all'/> " +
- " <xsd:element name='B' type='xsd:string' substitutionGroup='A'/> " +
- "</xsd:schema>",
- "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
- " <xsd:element name='A' type='xsd:string' final='restriction'/> " +
- " <xsd:element name='B' type='xsd:token' substitutionGroup='A'/> " +
- "</xsd:schema>",
- "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
- " <xsd:element name='A' type='xsd:string' substitutionGroup='B'/> " +
- " <xsd:element name='B' type='xsd:string' substitutionGroup='C'/> " +
- " <xsd:element name='C' type='xsd:string' substitutionGroup='D'/> " +
- " <xsd:element name='D' type='xsd:string' substitutionGroup='E'/> " +
- " <xsd:element name='E' type='xsd:string' substitutionGroup='A'/> " +
- "</xsd:schema>",
- "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
- " <xsd:element name='A' type='xsd:token' substitutionGroup='B'/> " +
- "</xsd:schema>",
- "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
- " <xsd:element name='A' type='xsd:string'/> " +
- " <xsd:element name='B' type='xsd:string' substitutionGroup='A'/> " +
- " <xsd:element name='Complex'> " +
- " <xsd:complexType> " +
- " <xsd:choice> " +
- " <xsd:element ref='A'/>" +
- " <xsd:element ref='B'/>" +
- " </xsd:choice> " +
- " </xsd:complexType> " +
- " </xsd:element> " +
- "</xsd:schema>",
+ " <xsd:element name='A' type='xsd:string'/> " +
+ " <xsd:element name='B' type='xsd:int' substitutionGroup='A'/> " +
+ "</xsd:schema>",
+ "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
+ " <xsd:complexType name='foo'> " +
+ " <xsd:sequence> " +
+ " <xsd:element name='bar' substitutionGroup='A'/>" +
+ " </xsd:sequence> " +
+ " </xsd:complexType>" +
+ "</xsd:schema>",
+ "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
+ " <xsd:element name='A' type='xsd:string' final='#all'/> " +
+ " <xsd:element name='B' type='xsd:string' substitutionGroup='A'/> " +
+ "</xsd:schema>",
+ "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
+ " <xsd:element name='A' type='xsd:string' final='restriction'/> " +
+ " <xsd:element name='B' type='xsd:token' substitutionGroup='A'/> " +
+ "</xsd:schema>",
+ "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
+ " <xsd:element name='A' type='xsd:string' substitutionGroup='B'/> " +
+ " <xsd:element name='B' type='xsd:string' substitutionGroup='C'/> " +
+ " <xsd:element name='C' type='xsd:string' substitutionGroup='D'/> " +
+ " <xsd:element name='D' type='xsd:string' substitutionGroup='E'/> " +
+ " <xsd:element name='E' type='xsd:string' substitutionGroup='A'/> " +
+ "</xsd:schema>",
+ "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
+ " <xsd:element name='A' type='xsd:token' substitutionGroup='B'/> " +
+ "</xsd:schema>",
+ "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> " +
+ " <xsd:element name='A' type='xsd:string'/> " +
+ " <xsd:element name='B' type='xsd:string' substitutionGroup='A'/> " +
+ " <xsd:element name='Complex'> " +
+ " <xsd:complexType> " +
+ " <xsd:choice> " +
+ " <xsd:element ref='A'/>" +
+ " <xsd:element ref='B'/>" +
+ " </xsd:choice> " +
+ " </xsd:complexType> " +
+ " </xsd:element> " +
+ "</xsd:schema>",
};
public static final String[] validSchemas = {
"<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
- " <xsd:complexType name='base'>" +
- " <xsd:all>" +
- " <xsd:element ref='head'/>" +
- " </xsd:all>" +
- " </xsd:complexType>" +
- " <xsd:complexType name='restr'>" +
- " <xsd:complexContent>" +
- " <xsd:restriction base='base'>" +
- " <xsd:all>" +
- " <xsd:element ref='tail'/>" +
- " </xsd:all>" +
- " </xsd:restriction>" +
- " </xsd:complexContent>" +
- " </xsd:complexType>" +
- " <xsd:element name='head' type='xsd:string'/>" +
- " <xsd:element name='tail' substitutionGroup='head'/>" +
- "</xsd:schema>",
+ " <xsd:complexType name='base'>" +
+ " <xsd:all>" +
+ " <xsd:element ref='head'/>" +
+ " </xsd:all>" +
+ " </xsd:complexType>" +
+ " <xsd:complexType name='restr'>" +
+ " <xsd:complexContent>" +
+ " <xsd:restriction base='base'>" +
+ " <xsd:all>" +
+ " <xsd:element ref='tail'/>" +
+ " </xsd:all>" +
+ " </xsd:restriction>" +
+ " </xsd:complexContent>" +
+ " </xsd:complexType>" +
+ " <xsd:element name='head' type='xsd:string'/>" +
+ " <xsd:element name='tail' substitutionGroup='head'/>" +
+ "</xsd:schema>",
};
@Test
- public void test3() throws Exception {
- SchemaDocument[] schemas = new SchemaDocument[invalidSchemas.length];
+ void test3() throws Exception {
+ final SchemaDocument[] invaldXSD = new SchemaDocument[invalidSchemas.length];
// Parse the invalid schema files
- for (int i = 0; i < invalidSchemas.length; i++)
- schemas[i] = SchemaDocument.Factory.parse(invalidSchemas[i]);
+ for (int i = 0; i < invalidSchemas.length; i++) {
+ invaldXSD[i] = SchemaDocument.Factory.parse(invalidSchemas[i]);
+ }
// Now compile the invalid schemas, test that they fail
- for (int i = 0; i < schemas.length; i++) {
- try {
- XmlBeans.loadXsd(new XmlObject[]{schemas[i]});
- fail("Schema should have failed to compile:\n" + invalidSchemas[i]);
- } catch (XmlException success) { /* System.out.println(success); */ }
+ for (SchemaDocument schemaDocument : invaldXSD) {
+ assertThrows(XmlException.class, () -> XmlBeans.loadXsd(schemaDocument));
}
-
// Parse the valid schema files
- schemas = new SchemaDocument[validSchemas.length];
- for (int i = 0; i < validSchemas.length; i++)
- schemas[i] = SchemaDocument.Factory.parse(validSchemas[i]);
+ SchemaDocument[] validXSD = new SchemaDocument[validSchemas.length];
+ for (int i = 0; i < validSchemas.length; i++) {
+ validXSD[i] = SchemaDocument.Factory.parse(validSchemas[i]);
+ }
// Now compile the valid schemas, test that they succeed
- for (int i = 0; i < schemas.length; i++) {
- try {
- XmlBeans.loadXsd(new XmlObject[]{schemas[i]});
- } catch (XmlException fail) {
- fail("Failed to compile schema: " + schemas[i] + " with error: " + fail);
- }
+ for (SchemaDocument schema : validXSD) {
+ Assertions.assertDoesNotThrow(() -> XmlBeans.loadXsd(schema));
}
}
- private static String[] invalidDocs =
- {
- "<abstractTest xmlns='http://openuri.org/sgs'>" +
- " <abstract>content</abstract> " +
- "</abstractTest> ",
- };
-
- private static String[] validDocs =
- {
- "<abstractTest xmlns='http://openuri.org/sgs'>" +
- " <concrete>content</concrete> " +
- "</abstractTest> ",
- };
+ private static final String[] invalidDocs = {
+ "<abstractTest xmlns='http://openuri.org/sgs'>" +
+ " <abstract>content</abstract> " +
+ "</abstractTest> ",
+ };
+
+ private static final String[] validDocs = {
+ "<abstractTest xmlns='http://openuri.org/sgs'>" +
+ " <concrete>content</concrete> " +
+ "</abstractTest> ",
+ };
@Test
- public void test4() throws Exception {
+ void test4() throws Exception {
- for (int i = 0; i < invalidDocs.length; i++) {
- XmlObject xo = XmlObject.Factory.parse(invalidDocs[i]);
- assertTrue("Doc was valid. Should be invalid: " + invalidDocs[i],
- !xo.validate());
+ for (String invalidDoc : invalidDocs) {
+ XmlObject xo = XmlObject.Factory.parse(invalidDoc);
+ assertFalse(xo.validate(), "Doc was valid. Should be invalid: " + invalidDoc);
}
- for (int i = 0; i < validDocs.length; i++) {
- XmlObject xo = XmlObject.Factory.parse(validDocs[i]);
- assertTrue("Doc was invalid. Should be valid: " + validDocs[i],
- xo.validate());
+ for (String validDoc : validDocs) {
+ XmlObject xo = XmlObject.Factory.parse(validDoc);
+ assertTrue(xo.validate(), "Doc was invalid. Should be valid: " + validDoc);
}
}
Modified: xmlbeans/trunk/src/test/java/xmlobject/checkin/ValidateTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlobject/checkin/ValidateTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlobject/checkin/ValidateTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlobject/checkin/ValidateTest.java Sun Feb 6 01:51:55 2022
@@ -15,58 +15,52 @@
package xmlobject.checkin;
+import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import test.xbean.xmlcursor.purchaseOrder.PurchaseOrderDocument;
-import tools.util.JarUtil;
-import xmlcursor.common.BasicCursorTestCase;
import xmlcursor.common.Common;
import javax.xml.namespace.QName;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static xmlcursor.common.BasicCursorTestCase.jobj;
-public class ValidateTest extends BasicCursorTestCase {
+public class ValidateTest {
@Test
- public void testValidateTrue() throws Exception {
+ void testValidateTrue() throws Exception {
//m_xo = XmlObject.Factory.parse(Common.XML_PURCHASEORDER);
- m_xo = XmlObject.Factory.parse(
- JarUtil.getResourceFromJar("xbean/xmlcursor/po.xml"));
+ XmlObject m_xo = jobj("xbean/xmlcursor/po.xml");
assertTrue(m_xo.validate());
}
@Test
- public void testValidateTrueWithOptionDiscardDocElement() throws Exception {
+ void testValidateTrueWithOptionDiscardDocElement() throws Exception {
XmlOptions map = new XmlOptions();
map.setLoadReplaceDocumentElement(null);
- m_xo = XmlObject.Factory.parse(
- JarUtil.getResourceFromJar(Common.TRANXML_FILE_XMLCURSOR_PO)
- , map);
-
+ XmlObject m_xo = jobj(Common.TRANXML_FILE_XMLCURSOR_PO, map);
assertFalse(m_xo.validate(map));
}
@Test
- public void testValidateFalseFixedAttr() throws Exception {
- m_xo = XmlObject.Factory.parse(
- JarUtil.getResourceFromJar("xbean/xmlcursor/po.xml"));
+ void testValidateFalseFixedAttr() throws Exception {
String ns = "declare namespace po=\"http://xbean.test/xmlcursor/PurchaseOrder\";";
String exp_ns = "xmlns:po=\"http://xbean.test/xmlcursor/PurchaseOrder\"";
- m_xc = m_xo.newCursor();
- m_xc.selectPath(ns + " $this//po:shipTo");
- QName name = new QName("country");
- m_xc.setAttributeText(name, "UK");
- XmlObject xo = m_xc.getObject();
- assertEquals("UK", m_xc.getAttributeText(name));
- PurchaseOrderDocument pod = (PurchaseOrderDocument) m_xo;
-
- assertFalse(xo.validate());
- assertFalse(pod.validate());
- assertFalse(m_xo.validate());
+ XmlObject m_xo = jobj("xbean/xmlcursor/po.xml");
+ assertTrue(m_xo instanceof PurchaseOrderDocument);
- assertTrue(true);
+ try (XmlCursor m_xc = m_xo.newCursor()) {
+ m_xc.selectPath(ns + " $this//po:shipTo");
+ QName name = new QName("country");
+ m_xc.setAttributeText(name, "UK");
+ XmlObject xo = m_xc.getObject();
+ assertEquals("UK", m_xc.getAttributeText(name));
+
+ assertFalse(xo.validate());
+ assertFalse(m_xo.validate());
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org