You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2022/01/06 17:54:31 UTC
svn commit: r1896764 [5/7] - in /xmlbeans/trunk/src: main/java/org/apache/xmlbeans/ main/java/org/apache/xmlbeans/impl/inst2xsd/ main/java/org/apache/xmlbeans/impl/inst2xsd/util/ main/java/org/apache/xmlbeans/impl/schema/ main/java/org/apache/xmlbeans/...
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorGeneratedTypedObjectTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorGeneratedTypedObjectTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorGeneratedTypedObjectTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorGeneratedTypedObjectTest.java Thu Jan 6 17:54:30 2022
@@ -45,50 +45,47 @@ public class CursorGeneratedTypedObjectT
"<loc:StateCode>TX</loc:StateCode>" +
"</loc:Location>";
LocationDocument locDoc = LocationDocument.Factory.parse(sXml);
- XmlCursor xc = locDoc.newCursor();
- xc.toFirstChild();
- LocationDocument.Location loc = (LocationDocument.Location) xc.getObject();
- assertTrue(loc.validate());
- XmlCursor xc0 = xc.newCursor();
-
- xc0.toEndDoc();
- xc0.toPrevToken();
- // xc0.insertElementWithText("SubdivisionCode", "xyz");
- xc0.insertElementWithText(
- new QName("http://xbean.test/xmlcursor/Location", "SubdivisionCode", "loc"),
- "xyz");
- xc0.toCursor(xc);
-
-
- String sExpectedXML =
- "<loc:Location " + sNamespace + ">" +
- "<loc:CityName>DALLAS</loc:CityName>" +
- "<loc:StateCode>TX</loc:StateCode>" +
- "<loc:SubdivisionCode>xyz</loc:SubdivisionCode>" +
- "</loc:Location>";
-
- String sOExpectedXML =
- "<xml-fragment " + sNamespace + ">" +
- "<loc:CityName>DALLAS</loc:CityName>" +
- "<loc:StateCode>TX</loc:StateCode>" +
- "<loc:SubdivisionCode>xyz</loc:SubdivisionCode>" +
- "</xml-fragment>";
- XmlOptions map = new XmlOptions();
- //map.put(XmlOptions.SAVE_PRETTY_PRINT, "");
- //map.put(XmlOptions.SAVE_PRETTY_PRINT_INDENT, new Integer(-1));
- try {
- assertEquals(sExpectedXML, xc0.xmlText(map));
- loc = (LocationDocument.Location) xc0.getObject();
- assertEquals(sOExpectedXML, loc.xmlText());
+ try (XmlCursor xc = locDoc.newCursor()) {
+ xc.toFirstChild();
+ LocationDocument.Location loc = (LocationDocument.Location) xc.getObject();
assertTrue(loc.validate());
- assertEquals("DALLAS", loc.getCityName());
- assertEquals("TX", loc.getStateCode());
- assertEquals("xyz", loc.getSubdivisionCode());
- } finally {
- xc.dispose();
- xc0.dispose();
- }
+ try (XmlCursor xc0 = xc.newCursor()) {
+ xc0.toEndDoc();
+ xc0.toPrevToken();
+ // xc0.insertElementWithText("SubdivisionCode", "xyz");
+ xc0.insertElementWithText(
+ new QName("http://xbean.test/xmlcursor/Location", "SubdivisionCode", "loc"),
+ "xyz");
+ xc0.toCursor(xc);
+
+
+ String sExpectedXML =
+ "<loc:Location " + sNamespace + ">" +
+ "<loc:CityName>DALLAS</loc:CityName>" +
+ "<loc:StateCode>TX</loc:StateCode>" +
+ "<loc:SubdivisionCode>xyz</loc:SubdivisionCode>" +
+ "</loc:Location>";
+
+ String sOExpectedXML =
+ "<xml-fragment " + sNamespace + ">" +
+ "<loc:CityName>DALLAS</loc:CityName>" +
+ "<loc:StateCode>TX</loc:StateCode>" +
+ "<loc:SubdivisionCode>xyz</loc:SubdivisionCode>" +
+ "</xml-fragment>";
+ XmlOptions map = new XmlOptions();
+ //map.put(XmlOptions.SAVE_PRETTY_PRINT, "");
+ //map.put(XmlOptions.SAVE_PRETTY_PRINT_INDENT, new Integer(-1));
+
+ assertEquals(sExpectedXML, xc0.xmlText(map));
+ loc = (LocationDocument.Location) xc0.getObject();
+ assertEquals(sOExpectedXML, loc.xmlText());
+ assertTrue(loc.validate());
+ assertEquals("DALLAS", loc.getCityName());
+ assertEquals("TX", loc.getStateCode());
+ assertEquals("xyz", loc.getSubdivisionCode());
+ }
+ }
}
@Test
@@ -97,71 +94,68 @@ public class CursorGeneratedTypedObjectT
CarLocationMessageDocument clm = CarLocationMessageDocument.Factory.parse(
JarUtil.getResourceFromJar(
Common.TRANXML_FILE_CLM));
- XmlCursor xc = clm.newCursor();
- xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT +
- "$this//GeographicLocation");
- xc.toNextSelection();
-
- GeographicLocationDocument.GeographicLocation gl0 = (GeographicLocationDocument.GeographicLocation) xc.getObject();
- assertTrue(gl0.validate());
-
- XmlCursor xc0 = xc.newCursor();
- try {
- xc0.toLastChild();
- assertEquals("TX", xc0.getTextValue());
- xc0.toNextToken();
- xc0.toNextToken();
- xc0.toNextToken();
- xc0.toNextToken();
- assertEquals(TokenType.END, xc0.currentTokenType());
-
- xc0.beginElement("LocationIdentifier",
- "http://www.tranxml.org/TranXML/Version4.0");
- xc0.insertAttributeWithValue("Qualifier", "FR");
- xc0.toEndToken();
- xc0.toNextToken();//move past the end token
- xc0.insertElementWithText("CountrySubdivisionCode",
- "http://www.tranxml.org/TranXML/Version4.0", "xyz");
- xc0.toCursor(xc);
-
- String sExpectedXML =
- "<GeographicLocation " + sNamespace + ">\n" +
- "\t\t\t<CityName>DALLAS</CityName>\n" +
- "\t\t\t<StateOrProvinceCode>TX</StateOrProvinceCode>\n" +
- "\t\t<LocationIdentifier Qualifier=\"FR\"/><CountrySubdivisionCode>xyz</CountrySubdivisionCode>" +
- "</GeographicLocation>";
-
- XmlOptions map = new XmlOptions();
- // map.put(XmlOptions.SAVE_PRETTY_PRINT, "");
- // map.put(XmlOptions.SAVE_PRETTY_PRINT_INDENT, new Integer(-1));
- assertEquals(sExpectedXML, xc0.xmlText());
-
- String sOExpectedXML =
- "<xml-fragment xmlns:xsi=\"http://www.w3.org/2000/10/XMLSchema-instance\">\n" +
- "\t\t\t<ver:CityName xmlns:ver=\"http://www.tranxml.org/TranXML/Version4.0\">" +
- "DALLAS</ver:CityName>\n" +
- "\t\t\t<ver:StateOrProvinceCode xmlns:ver=\"http://www.tranxml.org/TranXML/Version4.0\">" +
- "TX</ver:StateOrProvinceCode>\n" +
- "\t\t<ver:LocationIdentifier Qualifier=\"FR\" " +
- "xmlns:ver=\"http://www.tranxml.org/TranXML/Version4.0\"/>" +
- "<ver:CountrySubdivisionCode xmlns:ver=\"http://www.tranxml.org/TranXML/Version4.0\">xyz" +
- "</ver:CountrySubdivisionCode></xml-fragment>";
-
- GeographicLocationDocument.GeographicLocation gl = (GeographicLocationDocument.GeographicLocation) xc0.getObject();
- assertEquals(sOExpectedXML, gl.xmlText(map));
- assertTrue(gl.validate());
-
-
- assertEquals("DALLAS", gl.getCityName().getStringValue());
- assertEquals("TX", gl.getStateOrProvinceCode());
- LocationIdentifierDocument.LocationIdentifier li = gl.getLocationIdentifier();
- assertNotNull("LocationIdentifier unexpectedly null", li);
- assertEquals(CodeList309.FR,
- gl.getLocationIdentifier().getQualifier());
- assertEquals("xyz", gl.getCountrySubdivisionCode());
- } finally {
- xc.dispose();
- xc0.dispose();
+ try (XmlCursor xc = clm.newCursor()) {
+ xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT +
+ "$this//GeographicLocation");
+ xc.toNextSelection();
+
+ GeographicLocationDocument.GeographicLocation gl0 = (GeographicLocationDocument.GeographicLocation) xc.getObject();
+ assertTrue(gl0.validate());
+
+ try (XmlCursor xc0 = xc.newCursor()) {
+ xc0.toLastChild();
+ assertEquals("TX", xc0.getTextValue());
+ xc0.toNextToken();
+ xc0.toNextToken();
+ xc0.toNextToken();
+ xc0.toNextToken();
+ assertEquals(TokenType.END, xc0.currentTokenType());
+
+ xc0.beginElement("LocationIdentifier",
+ "http://www.tranxml.org/TranXML/Version4.0");
+ xc0.insertAttributeWithValue("Qualifier", "FR");
+ xc0.toEndToken();
+ xc0.toNextToken();//move past the end token
+ xc0.insertElementWithText("CountrySubdivisionCode",
+ "http://www.tranxml.org/TranXML/Version4.0", "xyz");
+ xc0.toCursor(xc);
+
+ String sExpectedXML =
+ "<GeographicLocation " + sNamespace + ">\n" +
+ "\t\t\t<CityName>DALLAS</CityName>\n" +
+ "\t\t\t<StateOrProvinceCode>TX</StateOrProvinceCode>\n" +
+ "\t\t<LocationIdentifier Qualifier=\"FR\"/><CountrySubdivisionCode>xyz</CountrySubdivisionCode>" +
+ "</GeographicLocation>";
+
+ XmlOptions map = new XmlOptions();
+ // map.put(XmlOptions.SAVE_PRETTY_PRINT, "");
+ // map.put(XmlOptions.SAVE_PRETTY_PRINT_INDENT, new Integer(-1));
+ assertEquals(sExpectedXML, xc0.xmlText());
+
+ String sOExpectedXML =
+ "<xml-fragment xmlns:xsi=\"http://www.w3.org/2000/10/XMLSchema-instance\">\n" +
+ "\t\t\t<ver:CityName xmlns:ver=\"http://www.tranxml.org/TranXML/Version4.0\">" +
+ "DALLAS</ver:CityName>\n" +
+ "\t\t\t<ver:StateOrProvinceCode xmlns:ver=\"http://www.tranxml.org/TranXML/Version4.0\">" +
+ "TX</ver:StateOrProvinceCode>\n" +
+ "\t\t<ver:LocationIdentifier Qualifier=\"FR\" " +
+ "xmlns:ver=\"http://www.tranxml.org/TranXML/Version4.0\"/>" +
+ "<ver:CountrySubdivisionCode xmlns:ver=\"http://www.tranxml.org/TranXML/Version4.0\">xyz" +
+ "</ver:CountrySubdivisionCode></xml-fragment>";
+
+ GeographicLocationDocument.GeographicLocation gl = (GeographicLocationDocument.GeographicLocation) xc0.getObject();
+ assertEquals(sOExpectedXML, gl.xmlText(map));
+ assertTrue(gl.validate());
+
+
+ assertEquals("DALLAS", gl.getCityName().getStringValue());
+ assertEquals("TX", gl.getStateOrProvinceCode());
+ LocationIdentifierDocument.LocationIdentifier li = gl.getLocationIdentifier();
+ assertNotNull("LocationIdentifier unexpectedly null", li);
+ assertEquals(CodeList309.FR,
+ gl.getLocationIdentifier().getQualifier());
+ assertEquals("xyz", gl.getCountrySubdivisionCode());
+ }
}
}
@@ -171,37 +165,34 @@ public class CursorGeneratedTypedObjectT
String sFF = "<First>Fred</First><Last>Flintstone</Last>";
String sXml = "<Person xmlns=\"person\"><Name>" + sFF +
"</Name></Person>";
- XmlCursor xc = XmlObject.Factory.parse(sXml).newCursor();
- PersonDocument pdoc = (PersonDocument) xc.getObject();
+ try (XmlCursor xc = XmlObject.Factory.parse(sXml).newCursor()) {
+ PersonDocument pdoc = (PersonDocument) xc.getObject();
- xc.toFirstChild();
- XmlCursor xcPlaceHolder = xc.newCursor();
+ xc.toFirstChild();
- try {
- Person p = (Person) xc.getObject();
- assertTrue(p.validate());
- // move to </Person>
- xc.toEndToken();
-
- xc.insertElement("Sibling", "person");
- xc.toPrevToken();
- xc.insertElement("Name", "person");
- xc.toPrevToken();
- xc.insertElementWithText("First", "person", "Barney");
- xc.insertElementWithText("Last", "person", "Rubble");
-
- p = (Person) xcPlaceHolder.getObject();
- assertTrue(p.validate());
-
- assertEquals("Fred", p.getName().getFirst());
- assertEquals("Flintstone", p.getName().getLast());
- Person[] ap = p.getSiblingArray();
- assertEquals(1, ap.length);
- assertEquals("Barney", ap[0].getName().getFirst());
- assertEquals("Rubble", ap[0].getName().getLast());
- } finally {
- xc.dispose();
- xcPlaceHolder.dispose();
+ try (XmlCursor xcPlaceHolder = xc.newCursor()) {
+ Person p = (Person) xc.getObject();
+ assertTrue(p.validate());
+ // move to </Person>
+ xc.toEndToken();
+
+ xc.insertElement("Sibling", "person");
+ xc.toPrevToken();
+ xc.insertElement("Name", "person");
+ xc.toPrevToken();
+ xc.insertElementWithText("First", "person", "Barney");
+ xc.insertElementWithText("Last", "person", "Rubble");
+
+ p = (Person) xcPlaceHolder.getObject();
+ assertTrue(p.validate());
+
+ assertEquals("Fred", p.getName().getFirst());
+ assertEquals("Flintstone", p.getName().getLast());
+ Person[] ap = p.getSiblingArray();
+ assertEquals(1, ap.length);
+ assertEquals("Barney", ap[0].getName().getFirst());
+ assertEquals("Rubble", ap[0].getName().getLast());
+ }
}
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorLocations.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorLocations.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorLocations.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorLocations.java Thu Jan 6 17:54:30 2022
@@ -37,7 +37,6 @@ public class CursorLocations extends Bas
@Test(expected = IllegalArgumentException.class)
public void testLocation() throws Exception {
- XmlCursor xc1, xc2, xc3, xc4;
XmlObject m_xo1;
@@ -45,286 +44,257 @@ public class CursorLocations extends Bas
JarUtil.getResourceFromJar(Common.TRANXML_FILE_XMLCURSOR_PO));
m_xo1 = XmlObject.Factory.parse(Common.XML_FOO_BAR_TEXT);
+ try (XmlCursor xc1 = m_xo.newCursor();
+ XmlCursor xc2 = m_xo.newCursor();
+ XmlCursor xc3 = m_xo1.newCursor()) {
+ toNextTokenOfType(xc2, TokenType.END);
+ toNextTokenOfType(xc3, TokenType.START);
+
+
+ //start w/ xc1 at beg of doc
+ //xc2 at end of first elt (po:name)
+ while (xc1.isLeftOf(xc2)) {
+ assertFalse(xc1.isRightOf(xc2));
+ assertTrue(xc2.isRightOf(xc1));
+ assertTrue(xc1.isInSameDocument(xc2));
+ assertFalse(xc2.isAtSamePositionAs(xc1));
+ assertFalse(xc1.isAtSamePositionAs(xc2));
+ assertEquals(1, xc2.comparePosition(xc1));
+ assertEquals(-1, xc1.comparePosition(xc2));
+ // System.out.println(xc1.currentTokenType() + " " + xc2.currentTokenType());
+ xc1.toNextToken();
+ xc2.toPrevToken();
+ }
+ //xc1 & xc2 @ shipTo
+ toNextTokenOfType(xc1,TokenType.TEXT);
+ toNextTokenOfType(xc2,TokenType.TEXT);
+ assertEquals("Current Token Type ",
+ xc1.currentTokenType(),
+ xc2.currentTokenType());
+ //both @ Alice Smith
+ toNextTokenOfType(xc1,TokenType.TEXT);
+ toNextTokenOfType(xc2,TokenType.TEXT);
+ assertEquals(XmlCursor.TokenType.TEXT,
+ xc1.currentTokenType());
+ //these are only equivalent if the cursor is on a TEXT token
+ assertEquals(xc1.getChars(), xc1.getTextValue());
+ assertEquals(xc1.getChars(), xc2.getTextValue());
- xc1 = m_xo.newCursor();
- xc2 = m_xo.newCursor();
- xc3 = m_xo1.newCursor();
+ assertTrue(xc1.isAtSamePositionAs(xc2));
+ xc2.toNextChar(10);
- toNextTokenOfType(xc2, TokenType.END);
- toNextTokenOfType(xc3, TokenType.START);
+ //comparing two cursors in the middle of text
-
- //start w/ xc1 at beg of doc
- //xc2 at end of first elt (po:name)
- while (xc1.isLeftOf(xc2)) {
- assertFalse(xc1.isRightOf(xc2));
+ assertEquals(xc2.toPrevChar(4), xc1.toNextChar(4));
assertTrue(xc2.isRightOf(xc1));
- assertTrue(xc1.isInSameDocument(xc2));
- assertFalse(xc2.isAtSamePositionAs(xc1));
+ assertFalse(xc1.isRightOf(xc2));
+ assertFalse(xc2.isLeftOf(xc1));
assertFalse(xc1.isAtSamePositionAs(xc2));
assertEquals(1, xc2.comparePosition(xc1));
- assertEquals(-1, xc1.comparePosition(xc2));
- // System.out.println(xc1.currentTokenType() + " " + xc2.currentTokenType());
- xc1.toNextToken();
+ assertTrue(xc1.isInSameDocument(xc2));
+ xc1.toNextChar(2);
+ assertEquals(0, xc2.comparePosition(xc1));
+ assertEquals(xc1.currentTokenType(), xc2.currentTokenType());
+
+ //Comparing the same cursor to itself
+ xc1.toNextChar(1);
+ assertFalse(xc1.isRightOf(xc1));
+ assertEquals(0, xc2.comparePosition(xc2));
+ assertTrue(xc2.isInSameDocument(xc2));
+ assertTrue(xc2.isAtSamePositionAs(xc2));
+
xc2.toPrevToken();
- }
- //xc1 & xc2 @ shipTo
- toNextTokenOfType(xc1,TokenType.TEXT);
- toNextTokenOfType(xc2,TokenType.TEXT);
- assertEquals("Current Token Type ",
- xc1.currentTokenType(),
- xc2.currentTokenType());
- //both @ Alice Smith
- toNextTokenOfType(xc1,TokenType.TEXT);
- toNextTokenOfType(xc2,TokenType.TEXT);
- assertEquals(XmlCursor.TokenType.TEXT,
- xc1.currentTokenType());
- //these are only equivalent if the cursor is on a TEXT token
- assertEquals(xc1.getChars(), xc1.getTextValue());
- assertEquals(xc1.getChars(), xc2.getTextValue());
-
- assertTrue(xc1.isAtSamePositionAs(xc2));
- xc2.toNextChar(10);
-
-
-//comparing two cursors in the middle of text
-
- assertEquals(xc2.toPrevChar(4), xc1.toNextChar(4));
- assertTrue(xc2.isRightOf(xc1));
- assertFalse(xc1.isRightOf(xc2));
- assertFalse(xc2.isLeftOf(xc1));
- assertFalse(xc1.isAtSamePositionAs(xc2));
- assertEquals(1, xc2.comparePosition(xc1));
- assertTrue(xc1.isInSameDocument(xc2));
- xc1.toNextChar(2);
- assertEquals(0, xc2.comparePosition(xc1));
- assertEquals(xc1.currentTokenType(), xc2.currentTokenType());
-
- //Comparing the same cursor to itself
- xc1.toNextChar(1);
- assertFalse(xc1.isRightOf(xc1));
- assertEquals(0, xc2.comparePosition(xc2));
- assertTrue(xc2.isInSameDocument(xc2));
- assertTrue(xc2.isAtSamePositionAs(xc2));
-
- xc2.toPrevToken();
- //xc2 on Alice
- assertEquals(TokenType.TEXT, xc2.toPrevToken());
- //put the bookmark on S*mith
- xc1.setBookmark(_theBookmark0);
-
- //moving xml and bookmark to a
- // different location
- assertTrue(xc1.moveXml(xc3));
- xc4 = _theBookmark0.createCursor();
- assertNotNull(xc4);
-
- XmlCursor debug=xc4.newCursor();
- XmlCursor debug1=xc1.newCursor();
-
- toPrevTokenOfType(debug1,TokenType.START);
- assertTrue(xc4.isInSameDocument(xc3));
- assertEquals(-1, xc4.comparePosition(xc3));
- // assertEquals(TokenType.TEXT, xc3.toPrevToken());
- assertEquals(4,xc3.toPrevChar(4));
- assertEquals(0, xc4.comparePosition(xc3));
-
- //comparing in two different documents
- assertFalse(xc2.isInSameDocument(xc3));
-
-
- try {
- xc4.isLeftOf(xc2);
- } finally {
- xc1.dispose();
- xc2.dispose();
- xc3.dispose();
- xc4.dispose();
+ //xc2 on Alice
+ assertEquals(TokenType.TEXT, xc2.toPrevToken());
+ //put the bookmark on S*mith
+ xc1.setBookmark(_theBookmark0);
+
+ //moving xml and bookmark to a
+ // different location
+ assertTrue(xc1.moveXml(xc3));
+ try (XmlCursor xc4 = _theBookmark0.createCursor();
+ XmlCursor debug=xc1.newCursor()) {
+ assertNotNull(xc4);
+
+ toPrevTokenOfType(debug,TokenType.START);
+ assertTrue(xc4.isInSameDocument(xc3));
+ assertEquals(-1, xc4.comparePosition(xc3));
+ // assertEquals(TokenType.TEXT, xc3.toPrevToken());
+ assertEquals(4,xc3.toPrevChar(4));
+ assertEquals(0, xc4.comparePosition(xc3));
+
+ //comparing in two different documents
+ assertFalse(xc2.isInSameDocument(xc3));
+
+ xc4.isLeftOf(xc2);
+ }
}
}
@Test
public void testLocationATTR() throws Exception {
- XmlCursor xc1, xc2;
m_xo = XmlObject.Factory.parse(Common.XML_FOO_5ATTR_TEXT);
- xc1 = m_xo.newCursor();
- xc2 = m_xo.newCursor();
+ try (XmlCursor xc1 = m_xo.newCursor();
+ XmlCursor xc2 = m_xo.newCursor()) {
+ toNextTokenOfType(xc1, TokenType.ATTR);
+ toNextTokenOfType(xc2, TokenType.ATTR);
+
+ int i = 0;
+ while (xc2.currentTokenType() == TokenType.ATTR) {
+ xc2.toNextToken();
+ ++i;
+ }
- toNextTokenOfType(xc1, TokenType.ATTR);
- toNextTokenOfType(xc2, TokenType.ATTR);
-
- int i = 0;
- while (xc2.currentTokenType() == TokenType.ATTR) {
- xc2.toNextToken();
- ++i;
- }
+ assertEquals(5, i);
+ xc2.toPrevToken();
- assertEquals(5, i);
- xc2.toPrevToken();
+ //moving betweenAttributes. one cursor is at the last ATTR and other is at first ATTR.
+ while (xc1.isLeftOf(xc2)) {
+ assertFalse(xc1.isRightOf(xc2));
+ assertTrue(xc2.isRightOf(xc1));
+ assertTrue(xc1.isInSameDocument(xc2));
+ assertFalse(xc2.isAtSamePositionAs(xc1));
+ assertFalse(xc1.isAtSamePositionAs(xc2));
+ assertEquals(1, xc2.comparePosition(xc1));
+ assertEquals(-1, xc1.comparePosition(xc2));
+ // System.out.println(xc1.currentTokenType() + " " + xc2.currentTokenType());
+ xc1.toNextToken();
+ xc2.toPrevToken();
+ }
+ assertTrue(xc1.isAtSamePositionAs(xc2));
+
+ //inserting and then comparing to make sure cursors move properly.
+ xc2.insertAttributeWithValue("attr5", "val5");
+ assertEquals(0, xc1.comparePosition(xc2));
- //moving betweenAttributes. one cursor is at the last ATTR and other is at first ATTR.
- while (xc1.isLeftOf(xc2)) {
- assertFalse(xc1.isRightOf(xc2));
- assertTrue(xc2.isRightOf(xc1));
- assertTrue(xc1.isInSameDocument(xc2));
- assertFalse(xc2.isAtSamePositionAs(xc1));
- assertFalse(xc1.isAtSamePositionAs(xc2));
- assertEquals(1, xc2.comparePosition(xc1));
- assertEquals(-1, xc1.comparePosition(xc2));
- // System.out.println(xc1.currentTokenType() + " " + xc2.currentTokenType());
- xc1.toNextToken();
xc2.toPrevToken();
+ assertEquals("val5", xc2.getTextValue());
}
- assertTrue(xc1.isAtSamePositionAs(xc2));
-
- //inserting and then comparing to make sure cursors move properly.
- xc2.insertAttributeWithValue("attr5", "val5");
- assertEquals(0, xc1.comparePosition(xc2));
-
- xc2.toPrevToken();
- assertEquals("val5", xc2.getTextValue());
-
- xc1.dispose();
- xc2.dispose();
-
}
@Test
public void testLocationTEXTMiddle() throws Exception {
- XmlCursor xc1, xc2, xc3;
m_xo = XmlObject.Factory.parse(Common.XML_TEXT_MIDDLE);
- xc1 = m_xo.newCursor();
- xc2 = m_xo.newCursor();
- xc3 = m_xo.newCursor();
-
-
- // while(xc2.currentTokenType() != TokenType.ENDDOC)
- // {
- // System.out.println(xc2.currentTokenType());
- // xc2.toNextToken();
- // }
-
- // moving cursor to right locations. one is in middle of mixed content.
- // the others is in middle of text of first node and last node
-
- toNextTokenOfType(xc1, TokenType.TEXT);
- toNextTokenOfType(xc2, TokenType.TEXT);
- toNextTokenOfType(xc3, TokenType.START);
- toNextTokenOfType(xc2, TokenType.TEXT);
- xc1.toNextChar(4);
- xc2.toNextChar(5);
- xc3.toEndToken();
- xc3.toPrevToken();
- xc3.toPrevChar(3);
-
- //comparing positions
- assertEquals(-1, xc2.comparePosition(xc3));
- assertTrue(xc2.isRightOf(xc1));
- assertTrue(xc1.isInSameDocument(xc2));
- assertFalse(xc2.isAtSamePositionAs(xc3));
-
- //moving cursors
- xc3.toPrevChar(2);
- xc2.toNextChar(1);
-
- //comparing position once again
- assertEquals(-1, xc2.comparePosition(xc3));
- assertTrue(xc2.isRightOf(xc1));
- assertTrue(xc1.isInSameDocument(xc2));
- assertFalse(xc2.isAtSamePositionAs(xc3));
-
- //moving and bringing them to identical positions
- xc3.toPrevToken();
- xc2.toNextChar(2);
- assertTrue(xc2.isAtSamePositionAs(xc3));
-
- xc1.dispose();
- xc2.dispose();
- xc3.dispose();
+ try (XmlCursor xc1 = m_xo.newCursor();
+ XmlCursor xc2 = m_xo.newCursor();
+ XmlCursor xc3 = m_xo.newCursor()) {
+ // while(xc2.currentTokenType() != TokenType.ENDDOC)
+ // {
+ // System.out.println(xc2.currentTokenType());
+ // xc2.toNextToken();
+ // }
+
+ // moving cursor to right locations. one is in middle of mixed content.
+ // the others is in middle of text of first node and last node
+
+ toNextTokenOfType(xc1, TokenType.TEXT);
+ toNextTokenOfType(xc2, TokenType.TEXT);
+ toNextTokenOfType(xc3, TokenType.START);
+ toNextTokenOfType(xc2, TokenType.TEXT);
+ xc1.toNextChar(4);
+ xc2.toNextChar(5);
+ xc3.toEndToken();
+ xc3.toPrevToken();
+ xc3.toPrevChar(3);
+
+ //comparing positions
+ assertEquals(-1, xc2.comparePosition(xc3));
+ assertTrue(xc2.isRightOf(xc1));
+ assertTrue(xc1.isInSameDocument(xc2));
+ assertFalse(xc2.isAtSamePositionAs(xc3));
+
+ //moving cursors
+ xc3.toPrevChar(2);
+ xc2.toNextChar(1);
+
+ //comparing position once again
+ assertEquals(-1, xc2.comparePosition(xc3));
+ assertTrue(xc2.isRightOf(xc1));
+ assertTrue(xc1.isInSameDocument(xc2));
+ assertFalse(xc2.isAtSamePositionAs(xc3));
+
+ //moving and bringing them to identical positions
+ xc3.toPrevToken();
+ xc2.toNextChar(2);
+ assertTrue(xc2.isAtSamePositionAs(xc3));
+ }
}
@Test
public void testXmlObjectUsingCursor() throws Exception {
- XmlCursor xc1, xc2, xc3;
-
- PurchaseOrderDocument pod = PurchaseOrderDocument.Factory.parse(
+ PurchaseOrderDocument pod = PurchaseOrderDocument.Factory.parse(
JarUtil.getResourceFromJar(Common.TRANXML_FILE_XMLCURSOR_PO));
- xc1 = pod.newCursor();
- xc2 = pod.newCursor();
- xc3 = pod.newCursor();
-
-
- //moving cursor location so that it comes to zip under shipto
-
- toNextTokenOfType(xc1, TokenType.START);
- toNextTokenOfType(xc1, TokenType.START);
- toNextTokenOfType(xc2, TokenType.START);
- toNextTokenOfType(xc2, TokenType.START);
- toNextTokenOfType(xc3, TokenType.START);
- toNextTokenOfType(xc3, TokenType.START);
-
- xc1.toEndToken();
- xc2.toEndToken();
- xc3.toEndToken();
-
- toPrevTokenOfType(xc1, TokenType.TEXT);
- toPrevTokenOfType(xc1, TokenType.TEXT);
- toPrevTokenOfType(xc2, TokenType.TEXT);
- toPrevTokenOfType(xc2, TokenType.TEXT);
- toPrevTokenOfType(xc3, TokenType.TEXT);
- toPrevTokenOfType(xc3, TokenType.TEXT);
- //all cursors are now at: 90952
- assertEquals(xc1.getChars(), xc2.getChars(), xc3.getChars());
- //at 52
- xc2.toNextChar(3);
- //after 90952
- xc3.toNextChar(5);
- assertFalse(xc2.isAtSamePositionAs(xc3));
- assertFalse(xc3.isAtSamePositionAs(xc1));
-
-
- //setting zip value through the object .
- // once the set occurs comparing postions of cursors.
- PurchaseOrderType pt = pod.getPurchaseOrder();
- USAddress usa = pt.getShipTo();
- usa.setZip(new BigDecimal(500));
-
- assertEquals(500,usa.getZip().intValue());
- //Any cursors in the value of an Element/attr should be positioned
- // at the end of the elem/attr after the strong setter
- assertTrue(xc2.isAtSamePositionAs(xc3));
- assertTrue(xc3.isAtSamePositionAs(xc1));
-
- assertEquals(TokenType.END,xc1.currentTokenType());
-
-
- // inserting an element through the cursor under zip and then doing
- // a set of a valid value through object..
-
- xc1.insertElementWithText("foo", "text");
- toPrevTokenOfType(xc1, TokenType.START);
- toPrevTokenOfType(xc1, TokenType.START);
- //System.out.println("here" + xc1.getTextValue());
-
- toNextTokenOfType(xc1, TokenType.START);
-
- xc1.toNextChar(2);
- usa.setZip(new BigDecimal(90852));
-
- assertTrue(xc2.isAtSamePositionAs(xc3));
- assertTrue(xc3.isAtSamePositionAs(xc1));
- //cursors at the end of element
- xc1.toPrevToken();
- //assertEquals(5,xc1.toPrevChar(5));
- assertEquals("90852", xc1.getChars());
-
-
- xc1.dispose();
- xc2.dispose();
- xc3.dispose();
+
+ try (XmlCursor xc1 = pod.newCursor();
+ XmlCursor xc2 = pod.newCursor();
+ XmlCursor xc3 = pod.newCursor()) {
+ //moving cursor location so that it comes to zip under shipto
+
+ toNextTokenOfType(xc1, TokenType.START);
+ toNextTokenOfType(xc1, TokenType.START);
+ toNextTokenOfType(xc2, TokenType.START);
+ toNextTokenOfType(xc2, TokenType.START);
+ toNextTokenOfType(xc3, TokenType.START);
+ toNextTokenOfType(xc3, TokenType.START);
+
+ xc1.toEndToken();
+ xc2.toEndToken();
+ xc3.toEndToken();
+
+ toPrevTokenOfType(xc1, TokenType.TEXT);
+ toPrevTokenOfType(xc1, TokenType.TEXT);
+ toPrevTokenOfType(xc2, TokenType.TEXT);
+ toPrevTokenOfType(xc2, TokenType.TEXT);
+ toPrevTokenOfType(xc3, TokenType.TEXT);
+ toPrevTokenOfType(xc3, TokenType.TEXT);
+ //all cursors are now at: 90952
+ assertEquals(xc1.getChars(), xc2.getChars(), xc3.getChars());
+ //at 52
+ xc2.toNextChar(3);
+ //after 90952
+ xc3.toNextChar(5);
+ assertFalse(xc2.isAtSamePositionAs(xc3));
+ assertFalse(xc3.isAtSamePositionAs(xc1));
+
+
+ //setting zip value through the object .
+ // once the set occurs comparing postions of cursors.
+ PurchaseOrderType pt = pod.getPurchaseOrder();
+ USAddress usa = pt.getShipTo();
+ usa.setZip(new BigDecimal(500));
+
+ assertEquals(500,usa.getZip().intValue());
+ //Any cursors in the value of an Element/attr should be positioned
+ // at the end of the elem/attr after the strong setter
+ assertTrue(xc2.isAtSamePositionAs(xc3));
+ assertTrue(xc3.isAtSamePositionAs(xc1));
+
+ assertEquals(TokenType.END,xc1.currentTokenType());
+
+
+ // inserting an element through the cursor under zip and then doing
+ // a set of a valid value through object..
+
+ xc1.insertElementWithText("foo", "text");
+ toPrevTokenOfType(xc1, TokenType.START);
+ toPrevTokenOfType(xc1, TokenType.START);
+ //System.out.println("here" + xc1.getTextValue());
+
+ toNextTokenOfType(xc1, TokenType.START);
+
+ xc1.toNextChar(2);
+ usa.setZip(new BigDecimal(90852));
+
+ assertTrue(xc2.isAtSamePositionAs(xc3));
+ assertTrue(xc3.isAtSamePositionAs(xc1));
+ //cursors at the end of element
+ xc1.toPrevToken();
+ //assertEquals(5,xc1.toPrevChar(5));
+ assertEquals("90852", xc1.getChars());
+ }
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorVsObjectAttributeTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorVsObjectAttributeTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorVsObjectAttributeTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorVsObjectAttributeTest.java Thu Jan 6 17:54:30 2022
@@ -37,15 +37,16 @@ public class CursorVsObjectAttributeTest
public void testAttributeSet() throws Exception {
CarLocationMessageDocument clmDoc = CarLocationMessageDocument.Factory.parse(
JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM));
- XmlCursor xc = clmDoc.newCursor();
- xc.toFirstChild();
- CarLocationMessage clm = (CarLocationMessage) xc.getObject();
+ try (XmlCursor xc = clmDoc.newCursor()) {
+ xc.toFirstChild();
+ CarLocationMessage clm = (CarLocationMessage) xc.getObject();
- clm.setVersion("XyZ");
- QName name = new QName("Version");
- assertEquals("XyZ", xc.getAttributeText(name));
- xc.setAttributeText(name, "012");
- assertEquals("012", clm.getVersion());
+ clm.setVersion("XyZ");
+ QName name = new QName("Version");
+ assertEquals("XyZ", xc.getAttributeText(name));
+ xc.setAttributeText(name, "012");
+ assertEquals("012", clm.getVersion());
+ }
}
@Test
@@ -53,17 +54,18 @@ public class CursorVsObjectAttributeTest
CarLocationMessageDocument clmDoc =
(CarLocationMessageDocument) XmlObject.Factory.parse(
JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM));
- XmlCursor xc = clmDoc.newCursor();
- xc.toFirstChild();
- CarLocationMessage clm = (CarLocationMessage) xc.getObject();
- QName name = new QName("Version");
- assertEquals("CLM", xc.getAttributeText(name));
- clm.unsetVersion();
- assertNull(xc.getAttributeText(name));
- xc.setAttributeText(name, "012");
- assertEquals("012", clm.getVersion());
- xc.removeAttribute(name);
- assertNull(clm.getVersion());
+ try (XmlCursor xc = clmDoc.newCursor()) {
+ xc.toFirstChild();
+ CarLocationMessage clm = (CarLocationMessage) xc.getObject();
+ QName name = new QName("Version");
+ assertEquals("CLM", xc.getAttributeText(name));
+ clm.unsetVersion();
+ assertNull(xc.getAttributeText(name));
+ xc.setAttributeText(name, "012");
+ assertEquals("012", clm.getVersion());
+ xc.removeAttribute(name);
+ assertNull(clm.getVersion());
+ }
}
@Test
@@ -74,16 +76,17 @@ public class CursorVsObjectAttributeTest
CarLocationMessageDocument clmDoc =
(CarLocationMessageDocument) XmlObject.Factory.parse(
JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM), map);
- XmlCursor xc = clmDoc.newCursor();
- xc.toFirstChild();
- CarLocationMessage clm = (CarLocationMessage) xc.getObject();
- QName name = new QName("Version");
- assertEquals("CLM", xc.getAttributeText(name));
- clm.unsetVersion();
- assertNull(xc.getAttributeText(name));
- xc.toFirstChild();
- assertEquals(TokenType.START, xc.currentTokenType());
- xc.insertAttributeWithValue(name, "012");
- assertEquals("012", clm.getVersion());
+ try (XmlCursor xc = clmDoc.newCursor()) {
+ xc.toFirstChild();
+ CarLocationMessage clm = (CarLocationMessage) xc.getObject();
+ QName name = new QName("Version");
+ assertEquals("CLM", xc.getAttributeText(name));
+ clm.unsetVersion();
+ assertNull(xc.getAttributeText(name));
+ xc.toFirstChild();
+ assertEquals(TokenType.START, xc.currentTokenType());
+ xc.insertAttributeWithValue(name, "012");
+ assertEquals("012", clm.getVersion());
+ }
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorVsObjectInsertRemoveTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorVsObjectInsertRemoveTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorVsObjectInsertRemoveTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorVsObjectInsertRemoveTest.java Thu Jan 6 17:54:30 2022
@@ -35,35 +35,35 @@ public class CursorVsObjectInsertRemoveT
(CarLocationMessageDocument) XmlObject.Factory.parse(
JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM));
assertNotNull(clm);
- XmlCursor xc = clm.newCursor();
- xc.toFirstChild();
- xc.toFirstChild();
- xc.toNextSibling();
- xc.toNextSibling();
- assertEquals("EventStatus", xc.getName().getLocalPart());
- EventStatus eventStatus = (EventStatus) xc.getObject();
- assertNotNull("Expected non-null EventStatus object", eventStatus);
- String sEventStatusText = xc.getTextValue();
- GeographicLocation glDest = eventStatus.getDestination().getGeographicLocation();
- assertNotNull("Expected non-null GeographicLocation object", glDest);
- glDest.setPostalCode("90210");
- glDest.setCountryCode("US");
- XmlCursor xcPostalCode = glDest.xgetPostalCode().newCursor();
- XmlCursor xcCountryCode = glDest.xgetCountryCode().newCursor();
- try {
- assertEquals("90210", xcPostalCode.getTextValue());
- assertEquals("US", xcCountryCode.getTextValue());
- xcPostalCode.setTextValue("90310");
- xcPostalCode.toNextChar(2);
- assertEquals("90310", glDest.getPostalCode());
- eventStatus.getDestination().getGeographicLocation().unsetPostalCode();
- assertEquals(TokenType.START, xcPostalCode.currentTokenType());
- assertEquals("CountryCode", xcPostalCode.getName().getLocalPart());
- xcCountryCode.removeXml();
- assertEquals(sEventStatusText, xc.getTextValue());
- } finally {
- xcPostalCode.dispose();
- xcCountryCode.dispose();
+ try (XmlCursor xc = clm.newCursor()) {
+ xc.toFirstChild();
+ xc.toFirstChild();
+ xc.toNextSibling();
+ xc.toNextSibling();
+ assertEquals("EventStatus", xc.getName().getLocalPart());
+ EventStatus eventStatus;
+ eventStatus = (EventStatus) xc.getObject();
+ assertNotNull("Expected non-null EventStatus object", eventStatus);
+ String sEventStatusText;
+ sEventStatusText = xc.getTextValue();
+
+ GeographicLocation glDest = eventStatus.getDestination().getGeographicLocation();
+ assertNotNull("Expected non-null GeographicLocation object", glDest);
+ glDest.setPostalCode("90210");
+ glDest.setCountryCode("US");
+ try (XmlCursor xcPostalCode = glDest.xgetPostalCode().newCursor();
+ XmlCursor xcCountryCode = glDest.xgetCountryCode().newCursor()) {
+ assertEquals("90210", xcPostalCode.getTextValue());
+ assertEquals("US", xcCountryCode.getTextValue());
+ xcPostalCode.setTextValue("90310");
+ xcPostalCode.toNextChar(2);
+ assertEquals("90310", glDest.getPostalCode());
+ eventStatus.getDestination().getGeographicLocation().unsetPostalCode();
+ assertEquals(TokenType.START, xcPostalCode.currentTokenType());
+ assertEquals("CountryCode", xcPostalCode.getName().getLocalPart());
+ xcCountryCode.removeXml();
+ assertEquals(sEventStatusText, xc.getTextValue());
+ }
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorVsObjectSetGetTextTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorVsObjectSetGetTextTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorVsObjectSetGetTextTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/CursorVsObjectSetGetTextTest.java Thu Jan 6 17:54:30 2022
@@ -35,10 +35,9 @@ public class CursorVsObjectSetGetTextTes
(CarLocationMessageDocument) XmlObject.Factory.parse(
JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM));
assertNotNull(clm);
- XmlCursor xc = clm.newCursor();
GeographicLocation[] aGL = new GeographicLocation[3];
- try {
+ try (XmlCursor xc = clm.newCursor()) {
xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT +
"$this//GeographicLocation");
xc.toNextSelection();
@@ -67,8 +66,6 @@ public class CursorVsObjectSetGetTextTes
for (int i = 0; i < 3; i++) {
assertEquals("PORTLAND", aGL[i].getCityName().getStringValue());
}
- } finally {
- xc.dispose();
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/MoveXmlTest2.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/MoveXmlTest2.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/MoveXmlTest2.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/MoveXmlTest2.java Thu Jan 6 17:54:30 2022
@@ -112,21 +112,21 @@ public class MoveXmlTest2 extends BasicC
public void testMovedAttrNameCollision() throws Exception
{
- m_xc1 = XmlObject.Factory.parse(sTestXml).newCursor();
- toNextTokenOfType(m_xc, TokenType.START);//m_xc on book at0
- toNextTokenOfType(m_xc1, TokenType.START);
- toNextTokenOfType(m_xc1, TokenType.START);
- //toNextTokenOfType(m_xc1,TokenType.END);//to author
- assertTrue(m_xc1.toFirstAttribute());
- assertTrue(m_xc.toFirstAttribute()); //at0 in book
- if (m_xc.moveXml(m_xc1)) {
- toPrevTokenOfType(m_xc1, TokenType.START);
- m_xc1.toFirstAttribute();
- assertEquals(m_xc1.getName().getLocalPart(), "at0");
- assertTrue(m_xc1.toNextAttribute());
- assertEquals(m_xc1.getName().getLocalPart(), "at0");
+ try (XmlCursor m_xc2 = XmlObject.Factory.parse(sTestXml).newCursor()) {
+ toNextTokenOfType(m_xc, TokenType.START);//m_xc on book at0
+ toNextTokenOfType(m_xc2, TokenType.START);
+ toNextTokenOfType(m_xc2, TokenType.START);
+ //toNextTokenOfType(m_xc2,TokenType.END);//to author
+ assertTrue(m_xc2.toFirstAttribute());
+ assertTrue(m_xc.toFirstAttribute()); //at0 in book
+ if (m_xc.moveXml(m_xc2)) {
+ toPrevTokenOfType(m_xc2, TokenType.START);
+ m_xc2.toFirstAttribute();
+ assertEquals(m_xc2.getName().getLocalPart(), "at0");
+ assertTrue(m_xc2.toNextAttribute());
+ assertEquals(m_xc2.getName().getLocalPart(), "at0");
+ }
}
- m_xc1.dispose();
}
/**
@@ -183,7 +183,7 @@ public class MoveXmlTest2 extends BasicC
{
super.tearDown();
if (m_xc1 != null) {
- m_xc1.dispose();
+ m_xc1.close();
m_xc1 = null;
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/MultipleCopyFromCursorTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/MultipleCopyFromCursorTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/MultipleCopyFromCursorTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/MultipleCopyFromCursorTest.java Thu Jan 6 17:54:30 2022
@@ -42,9 +42,8 @@ public class MultipleCopyFromCursorTest
(CarLocationMessageDocument) XmlObject.Factory.parse(
JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM));
assertNotNull(clm);
- XmlCursor xc = clm.newCursor();
XmlCursor[] aCursors = new XmlCursor[3];
- try {
+ try (XmlCursor xc = clm.newCursor()) {
xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT +
"$this//GeographicLocation");
xc.toNextSelection();
@@ -119,9 +118,8 @@ public class MultipleCopyFromCursorTest
}
} finally {
- xc.dispose();
for (int i = 0; i < 3; i++) {
- aCursors[i].dispose();
+ aCursors[i].close();
}
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/MultipleCopyTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/MultipleCopyTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/MultipleCopyTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/MultipleCopyTest.java Thu Jan 6 17:54:30 2022
@@ -36,9 +36,8 @@ public class MultipleCopyTest {
(CarLocationMessageDocument) XmlObject.Factory.parse(
JarUtil.getResourceFromJar(Common.TRANXML_FILE_CLM));
assertNotNull(clm);
- XmlCursor xc = clm.newCursor();
XmlCursor[] aCursors = new XmlCursor[3];
- try {
+ try (XmlCursor xc = clm.newCursor()) {
xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT +
"$this//GeographicLocation");
xc.toNextSelection();
@@ -70,9 +69,8 @@ public class MultipleCopyTest {
assertEquals("xyz", gl.getCountrySubdivisionCode());
}
} finally {
- xc.dispose();
for (int i = 0; i < 3; i++) {
- aCursors[i].dispose();
+ aCursors[i].close();
}
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/MultipleCursorSetTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/MultipleCursorSetTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/MultipleCursorSetTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/MultipleCursorSetTest.java Thu Jan 6 17:54:30 2022
@@ -30,18 +30,20 @@ import static org.junit.Assert.*;
public class MultipleCursorSetTest {
@Test
public void testMultipleCursorSet() throws Exception {
- XmlCursor xc = XmlObject.Factory.parse(JarUtil.getResourceFromJar(
- Common.TRANXML_FILE_CLM)).newCursor();
- xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT +
- "$this//EquipmentNumber");
- xc.toNextSelection();
- XmlString xs = (XmlString) xc.getObject();
- assertEquals("123456", xs.getStringValue());
- assertEquals(TokenType.TEXT, xc.toNextToken());
XmlCursor[] aCursors = new XmlCursor[6];
- for (int i = 0; i < 6; i++) {
- xc.toNextChar(1);
- aCursors[i] = xc.newCursor();
+ XmlString xs;
+ try (XmlCursor xc = XmlObject.Factory.parse(JarUtil.getResourceFromJar(
+ Common.TRANXML_FILE_CLM)).newCursor()) {
+ xc.selectPath(Common.CLM_NS_XQUERY_DEFAULT +
+ "$this//EquipmentNumber");
+ xc.toNextSelection();
+ xs = (XmlString) xc.getObject();
+ assertEquals("123456", xs.getStringValue());
+ assertEquals(TokenType.TEXT, xc.toNextToken());
+ for (int i = 0; i < 6; i++) {
+ xc.toNextChar(1);
+ aCursors[i] = xc.newCursor();
+ }
}
for (int i = 0; i < 6; i++) {
for (int j = 0; j != i && j < 6; j++) {
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/ObjectCursorInteractionTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/ObjectCursorInteractionTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/ObjectCursorInteractionTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/ObjectCursorInteractionTest.java Thu Jan 6 17:54:30 2022
@@ -39,21 +39,18 @@ public class ObjectCursorInteractionTest
// LocationDocument locDoc = (LocationDocument) XmlObject.Factory.parse(sXml);
LocationDocument locDoc = LocationDocument.Factory.parse(sXml);
Location loc = locDoc.getLocation();
- XmlCursor xc0 = loc.newCursor();
- assertEquals("DALLAS", loc.getCityName());
- loc = null;
- System.gc();
- try {
+ try (XmlCursor xc0 = loc.newCursor()) {
+ assertEquals("DALLAS", loc.getCityName());
+ loc = null;
+ System.gc();
Thread.sleep(1000);
xc0.toFirstChild();
assertEquals("DALLAS", xc0.getTextValue());
- } finally {
- xc0.dispose();
}
}
@Test
- public void testCursorDisposalEffectOnObject() throws Exception {
+ public void testCursorCloseEffectOnObject() throws Exception {
String sNamespace = "xmlns:loc=\"http://xbean.test/xmlcursor/Location\"";
String sXml = "<loc:Location " + sNamespace + ">" +
"<loc:CityName>DALLAS</loc:CityName><loc:StateCode>TX</loc:StateCode></loc:Location>";
@@ -62,23 +59,20 @@ public class ObjectCursorInteractionTest
assertTrue(locDoc.validate());
Location loc0 = locDoc.getLocation();
Location loc1 = locDoc.getLocation();
- XmlCursor xc0 = loc0.newCursor();
- XmlCursor xc1 = loc1.newCursor();
- xc0.toFirstChild();
- xc1.toFirstChild();
- xc0.setTextValue("AUSTIN");
- try {
+ try (XmlCursor xc0 = loc0.newCursor();
+ XmlCursor xc1 = loc1.newCursor()) {
+ xc0.toFirstChild();
+ xc1.toFirstChild();
+ xc0.setTextValue("AUSTIN");
+
assertEquals("AUSTIN", loc0.getCityName());
loc1.setCityName("SAN ANTONIO");
- xc0.dispose();
+ xc0.close();
assertEquals("SAN ANTONIO", xc1.getTextValue());
xc1.setTextValue("HOUSTON");
- xc1.dispose();
+ xc1.close();
assertEquals("HOUSTON", loc0.getCityName());
- } finally {
- xc0.dispose();
- xc1.dispose();
}
}
@@ -120,7 +114,7 @@ public class ObjectCursorInteractionTest
xc0 = loc0.newCursor();
assertEquals(sXml1, xc0.xmlText());
} finally {
- xc0.dispose();
+ xc0.close();
}
}
@@ -167,8 +161,8 @@ public class ObjectCursorInteractionTest
assertEquals("US", loc0.getCountryCode());
} finally {
- xc0.dispose();
- xc1.dispose();
+ xc0.close();
+ xc1.close();
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/SelectionsTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/SelectionsTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/SelectionsTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/SelectionsTest.java Thu Jan 6 17:54:30 2022
@@ -35,34 +35,35 @@ public class SelectionsTest extends Basi
//average case test
@Test
public void testNormalCase() throws Exception {
- XmlCursor m_xc1 = m_xo.newCursor();
- int nSelectionsCount = 7;
- m_xc.selectPath("$this//a");
- assertFalse(m_xc.hasNextSelection());
- assertFalse(m_xc.toNextSelection());
- assertEquals(0, m_xc.getSelectionCount());
-
- m_xc.selectPath("$this//b");
- m_xc1.toFirstChild();
- m_xc1.toFirstChild();
- do {
- m_xc1.addToSelection();
- } while (m_xc1.toNextSibling());
- assertEquals(nSelectionsCount, m_xc.getSelectionCount());
- int i = 0;
- while (m_xc.hasNextSelection()) {
- m_xc.toNextSelection();
- assertEquals("" + i, m_xc.getTextValue());
- i++;
- }
- int j = 0;
- while (m_xc1.hasNextSelection()) {
- m_xc1.toSelection(j);
- assertEquals("" + j, m_xc1.getTextValue());
- j++;
- }
- assertEquals(nSelectionsCount, j);
- assertEquals(nSelectionsCount, i);
+ try (XmlCursor m_xc1 = m_xo.newCursor()) {
+ int nSelectionsCount = 7;
+ m_xc.selectPath("$this//a");
+ assertFalse(m_xc.hasNextSelection());
+ assertFalse(m_xc.toNextSelection());
+ assertEquals(0, m_xc.getSelectionCount());
+
+ m_xc.selectPath("$this//b");
+ m_xc1.toFirstChild();
+ m_xc1.toFirstChild();
+ do {
+ m_xc1.addToSelection();
+ } while (m_xc1.toNextSibling());
+ assertEquals(nSelectionsCount, m_xc.getSelectionCount());
+ int i = 0;
+ while (m_xc.hasNextSelection()) {
+ m_xc.toNextSelection();
+ assertEquals("" + i, m_xc.getTextValue());
+ i++;
+ }
+ int j = 0;
+ while (m_xc1.hasNextSelection()) {
+ m_xc1.toSelection(j);
+ assertEquals("" + j, m_xc1.getTextValue());
+ j++;
+ }
+ assertEquals(nSelectionsCount, j);
+ assertEquals(nSelectionsCount, i);
+ }
}
@Test
@@ -108,21 +109,19 @@ public class SelectionsTest extends Basi
"declare namespace ns='http://xbean.test/xmlcursor/CR196679'" +
"$this/ns:value";
- XmlCursor cursor = test.newCursor();
- cursor.push();
- cursor.selectPath(queryName);
- cursor.toNextSelection();
-
- assertEquals("myTest", cursor.getTextValue());
-
- cursor.pop();
- cursor.selectPath(queryValue);
- cursor.toNextSelection();
-
- assertEquals("5", cursor.getTextValue());//expected output is value=5
-
- cursor.dispose();
+ try (XmlCursor cursor = test.newCursor()) {
+ cursor.push();
+ cursor.selectPath(queryName);
+ cursor.toNextSelection();
+
+ assertEquals("myTest", cursor.getTextValue());
+
+ cursor.pop();
+ cursor.selectPath(queryValue);
+ cursor.toNextSelection();
+ assertEquals("5", cursor.getTextValue());//expected output is value=5
+ }
}
@Before
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/ToBookmarkTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/ToBookmarkTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/ToBookmarkTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/ToBookmarkTest.java Thu Jan 6 17:54:30 2022
@@ -39,15 +39,13 @@ public class ToBookmarkTest extends Basi
m_xc = m_xo.newCursor();
toNextTokenOfType(m_xc, TokenType.START);
m_xc.setBookmark(_theBookmark);
- XmlCursor xc1 = m_xc.newCursor();
- xc1.toEndDoc();
- assertTrue(xc1.toBookmark(_theBookmark));
- try {
+ try (XmlCursor xc1 = m_xc.newCursor()) {
+ xc1.toEndDoc();
+ assertTrue(xc1.toBookmark(_theBookmark));
+
assertTrue(m_xc.isAtSamePositionAs(xc1));
SimpleBookmark sa = (SimpleBookmark) xc1.getBookmark(_theBookmark.getClass());
assertEquals("value", sa.text);
- } finally {
- xc1.dispose();
}
}
@@ -57,15 +55,13 @@ public class ToBookmarkTest extends Basi
m_xc = m_xo.newCursor();
toNextTokenOfType(m_xc, TokenType.START);
m_xc.setBookmark(_theBookmark);
- XmlCursor xc1 = m_xc.newCursor();
- xc1.toStartDoc();
- assertTrue(xc1.toBookmark(_theBookmark));
- try {
+ try (XmlCursor xc1 = m_xc.newCursor()) {
+ xc1.toStartDoc();
+ assertTrue(xc1.toBookmark(_theBookmark));
+
assertTrue(m_xc.isAtSamePositionAs(xc1));
SimpleBookmark sa = (SimpleBookmark) xc1.getBookmark(_theBookmark.getClass());
assertEquals("value", sa.text);
- } finally {
- xc1.dispose();
}
}
@@ -75,14 +71,12 @@ public class ToBookmarkTest extends Basi
m_xc = m_xo.newCursor();
toNextTokenOfType(m_xc, TokenType.START);
m_xc.setBookmark(_theBookmark);
- XmlCursor xc1 = m_xc.newCursor();
- xc1.toEndDoc();
- assertFalse(xc1.toBookmark(null));
- try {
+ try (XmlCursor xc1 = m_xc.newCursor()) {
+ xc1.toEndDoc();
+ assertFalse(xc1.toBookmark(null));
+
assertFalse(m_xc.isAtSamePositionAs(xc1));
assertEquals(TokenType.ENDDOC, xc1.currentTokenType());
- } finally {
- xc1.dispose();
}
}
@@ -91,15 +85,13 @@ public class ToBookmarkTest extends Basi
m_xo = XmlObject.Factory.parse(Common.XML_FOO_TEXT);
m_xc = m_xo.newCursor();
XmlObject xo = XmlObject.Factory.parse(Common.XML_FOO);
- XmlCursor xc1 = xo.newCursor();
- assertFalse(m_xc.isInSameDocument(xc1));
- toNextTokenOfType(m_xc, TokenType.START);
- m_xc.setBookmark(_theBookmark);
- try {
+ try (XmlCursor xc1 = xo.newCursor()) {
+ assertFalse(m_xc.isInSameDocument(xc1));
+ toNextTokenOfType(m_xc, TokenType.START);
+ m_xc.setBookmark(_theBookmark);
+
assertFalse(xc1.toBookmark(_theBookmark));
assertFalse(m_xc.isInSameDocument(xc1));
- } finally {
- xc1.dispose();
}
}
@@ -110,23 +102,23 @@ public class ToBookmarkTest extends Basi
String exp_ns = "xmlns:po=\"http://xbean.test/xmlcursor/PurchaseOrder\"";
m_xc = m_xo.newCursor();
- XmlCursor xc1 = m_xo.newCursor();
- m_xc.selectPath(ns + " $this//po:shipTo/po:city");
- while (m_xc.toNextSelection()) {
- m_xc.setBookmark(_theBookmark);
- xc1.selectPath(ns + " $this//po:billTo/po:city");
- while (xc1.toNextSelection()) {
- m_xc.moveXml(xc1);
- try {
- assertTrue(xc1.toBookmark(_theBookmark));
- assertEquals("<po:city " + exp_ns + ">Mill Valley</po:city>", xc1.xmlText());
- xc1.toNextSibling();
- assertEquals("<po:city " + exp_ns + ">Old Town</po:city>", xc1.xmlText());
- } catch (Exception e) {
+ try (XmlCursor xc1 = m_xo.newCursor()) {
+ m_xc.selectPath(ns + " $this//po:shipTo/po:city");
+ while (m_xc.toNextSelection()) {
+ m_xc.setBookmark(_theBookmark);
+ xc1.selectPath(ns + " $this//po:billTo/po:city");
+ while (xc1.toNextSelection()) {
+ m_xc.moveXml(xc1);
+ try {
+ assertTrue(xc1.toBookmark(_theBookmark));
+ assertEquals("<po:city " + exp_ns + ">Mill Valley</po:city>", xc1.xmlText());
+ xc1.toNextSibling();
+ assertEquals("<po:city " + exp_ns + ">Old Town</po:city>", xc1.xmlText());
+ } catch (Exception e) {
+ }
}
}
}
- xc1.dispose();
}
@Test
@@ -136,76 +128,74 @@ public class ToBookmarkTest extends Basi
String exp_ns = "xmlns:po=\"http://xbean.test/xmlcursor/PurchaseOrder\"";
m_xc = m_xo.newCursor();
- XmlCursor xc1 = m_xo.newCursor();
- m_xc.selectPath(ns + " $this//po:shipTo/po:city");
- while (m_xc.toNextSelection()) {
- m_xc.setBookmark(_theBookmark);
- toNextTokenOfType(m_xc, TokenType.TEXT);
- m_xc.toNextToken();
- m_xc.toNextToken(); // move to behind the <city>Mill Valley</city> element
- assertEquals(TokenType.TEXT, m_xc.currentTokenType());
- m_xc.setBookmark(_theBookmark1);
- m_xc.toBookmark(_theBookmark);
- xc1.selectPath(ns + " $this//po:billTo/po:city");
- while (xc1.toNextSelection()) {
- m_xc.moveXml(xc1);
- m_xc.toStartDoc();
- try {
- assertTrue(xc1.toBookmark(_theBookmark1));
- xc1.toPrevSibling();
- assertEquals("<po:street " + exp_ns + ">123 Maple Street</po:street>", xc1.xmlText());
- } catch (Exception e) {
+ try (XmlCursor xc1 = m_xo.newCursor()) {
+ m_xc.selectPath(ns + " $this//po:shipTo/po:city");
+ while (m_xc.toNextSelection()) {
+ m_xc.setBookmark(_theBookmark);
+ toNextTokenOfType(m_xc, TokenType.TEXT);
+ m_xc.toNextToken();
+ m_xc.toNextToken(); // move to behind the <city>Mill Valley</city> element
+ assertEquals(TokenType.TEXT, m_xc.currentTokenType());
+ m_xc.setBookmark(_theBookmark1);
+ m_xc.toBookmark(_theBookmark);
+ xc1.selectPath(ns + " $this//po:billTo/po:city");
+ while (xc1.toNextSelection()) {
+ m_xc.moveXml(xc1);
+ m_xc.toStartDoc();
+ try {
+ assertTrue(xc1.toBookmark(_theBookmark1));
+ xc1.toPrevSibling();
+ assertEquals("<po:street " + exp_ns + ">123 Maple Street</po:street>", xc1.xmlText());
+ } catch (Exception e) {
+ }
}
}
}
- xc1.dispose();
}
@Test
public void testToBookmarkPostCopy() throws Exception {
m_xo = XmlObject.Factory.parse(JarUtil.getResourceFromJar(Common.TRANXML_FILE_XMLCURSOR_PO));
m_xc = m_xo.newCursor();
- XmlCursor xc1 = m_xo.newCursor();
- String ns = "declare namespace po=\"http://xbean.test/xmlcursor/PurchaseOrder\"";
- String exp_ns = "xmlns:po=\"http://xbean.test/xmlcursor/PurchaseOrder\"";
-
- m_xc.selectPath(ns + " $this//po:shipTo/po:city");
- while (m_xc.toNextSelection()) {
- m_xc.setBookmark(_theBookmark);
- xc1.selectPath(ns + "$this//po:billTo/po:city");
- while (xc1.toNextSelection()) {
- m_xc.copyXml(xc1);
- try {
- assertTrue(xc1.toBookmark(_theBookmark));
- assertEquals("<po:city " + exp_ns + ">Mill Valley</po:city>", xc1.xmlText());
- xc1.toNextSibling();
- assertEquals("<po:state " + exp_ns + ">CA</po:state>", xc1.xmlText());
- } catch (Exception e) {
+ try (XmlCursor xc1 = m_xo.newCursor()) {
+ String ns = "declare namespace po=\"http://xbean.test/xmlcursor/PurchaseOrder\"";
+ String exp_ns = "xmlns:po=\"http://xbean.test/xmlcursor/PurchaseOrder\"";
+
+ m_xc.selectPath(ns + " $this//po:shipTo/po:city");
+ while (m_xc.toNextSelection()) {
+ m_xc.setBookmark(_theBookmark);
+ xc1.selectPath(ns + "$this//po:billTo/po:city");
+ while (xc1.toNextSelection()) {
+ m_xc.copyXml(xc1);
+ try {
+ assertTrue(xc1.toBookmark(_theBookmark));
+ assertEquals("<po:city " + exp_ns + ">Mill Valley</po:city>", xc1.xmlText());
+ xc1.toNextSibling();
+ assertEquals("<po:state " + exp_ns + ">CA</po:state>", xc1.xmlText());
+ } catch (Exception e) {
+ }
}
}
}
- xc1.dispose();
}
@Test
public void testToBookmarkPostMoveChars() throws Exception {
m_xo = XmlObject.Factory.parse(Common.XML_FOO_DIGITS);
m_xc = m_xo.newCursor();
- XmlCursor xc1 = m_xo.newCursor();
- toNextTokenOfType(m_xc, TokenType.TEXT);
- xc1.toCursor(m_xc);
- xc1.toNextChar(1);
- xc1.setBookmark(_theBookmark); // set an Bookmark at the '1'
- xc1.toNextChar(2); // move xc1 to the '3'
- try {
+ try (XmlCursor xc1 = m_xo.newCursor()) {
+ toNextTokenOfType(m_xc, TokenType.TEXT);
+ xc1.toCursor(m_xc);
+ xc1.toNextChar(1);
+ xc1.setBookmark(_theBookmark); // set an Bookmark at the '1'
+ xc1.toNextChar(2); // move xc1 to the '3'
+
assertEquals("34", xc1.getTextValue());
assertEquals(2, m_xc.moveChars(2, xc1));
assertEquals("20134", m_xc.getTextValue());
assertEquals("34", xc1.getTextValue());
xc1.toBookmark(_theBookmark);
assertEquals("134", xc1.getTextValue());
- } finally {
- xc1.dispose();
}
}
@@ -220,14 +210,14 @@ public class ToBookmarkTest extends Basi
m_xc = m_xo.newCursor();
// XmlCursor xc1 = m_xo.newCursor();
toNextTokenOfType(m_xc, TokenType.TEXT);
- XmlCursor xc1 = m_xc.newCursor();
- //xc1.toCursor(m_xc);
- xc1.toNextChar(1);
- // set a Bookmark at the '1', text is 1234
- xc1.setBookmark(_theBookmark);
- // move xc1 to the '3' , text post cursor is 34
- xc1.toNextChar(2);
- try {
+ try (XmlCursor xc1 = m_xc.newCursor()) {
+ //xc1.toCursor(m_xc);
+ xc1.toNextChar(1);
+ // set a Bookmark at the '1', text is 1234
+ xc1.setBookmark(_theBookmark);
+ // move xc1 to the '3' , text post cursor is 34
+ xc1.toNextChar(2);
+
assertEquals("34", xc1.getTextValue());
//text at m_xc is 01234, should get 0123*01*4
assertEquals(2, m_xc.copyChars(2, xc1));
@@ -235,8 +225,6 @@ public class ToBookmarkTest extends Basi
assertEquals("34", xc1.getTextValue());
xc1.toBookmark(_theBookmark);
assertEquals("120134", xc1.getTextValue());
- } finally {
- xc1.dispose();
}
}
@@ -244,32 +232,32 @@ public class ToBookmarkTest extends Basi
public void testDumb() throws Exception {
m_xo = XmlObject.Factory.parse("<foo>01234</foo>");
m_xc = m_xo.newCursor();
- toNextTokenOfType(m_xc, TokenType.TEXT);
- XmlCursor xc1 = m_xc.newCursor();
- xc1.toNextChar(2);
- assertEquals(2, m_xc.copyChars(2, xc1));
+ try (XmlCursor xc1 = toNextTokenOfTypeCursor(m_xc, TokenType.TEXT)) {
+ xc1.toNextChar(2);
+ assertEquals(2, m_xc.copyChars(2, xc1));
+ }
}
@Test(expected = IllegalArgumentException.class)
public void testDumbDelete() throws Exception {
m_xo = XmlObject.Factory.parse("<foo>01234</foo>");
m_xc = m_xo.newCursor();
- toNextTokenOfType(m_xc, TokenType.TEXT);
- XmlCursor xc1 = m_xc.newCursor();
- m_xc.toNextChar(2);
- m_xc.setBookmark(_theBookmark);
- m_xc.toStartDoc();
- //remove the text , bookmark goes bye bye too
- xc1.removeXml();
- xc1.toCursor(m_xc);
- //both at start of original doc
- assertEquals(m_xc.currentTokenType(),
- XmlCursor.TokenType.STARTDOC);
- assertTrue(m_xc.isAtSamePositionAs(xc1));
- //move xc1 to outer space
- xc1.toBookmark(_theBookmark);
- assertTrue(!m_xc.isInSameDocument(xc1));
- assertTrue(!m_xc.isLeftOf(xc1));
+ try (XmlCursor xc1 = toNextTokenOfTypeCursor(m_xc, TokenType.TEXT)) {
+ m_xc.toNextChar(2);
+ m_xc.setBookmark(_theBookmark);
+ m_xc.toStartDoc();
+ //remove the text , bookmark goes bye bye too
+ xc1.removeXml();
+ xc1.toCursor(m_xc);
+ //both at start of original doc
+ assertEquals(m_xc.currentTokenType(),
+ XmlCursor.TokenType.STARTDOC);
+ assertTrue(m_xc.isAtSamePositionAs(xc1));
+ //move xc1 to outer space
+ xc1.toBookmark(_theBookmark);
+ assertTrue(!m_xc.isInSameDocument(xc1));
+ assertTrue(!m_xc.isLeftOf(xc1));
+ }
}
@Test
@@ -282,26 +270,26 @@ public class ToBookmarkTest extends Basi
m_xc.toNextToken();
m_xc.setBookmark(_theBookmark); // set annot. at 'text'
- XmlCursor xc1 = m_xc.newCursor();
- xc1.toBookmark(_theBookmark);
- SimpleBookmark sa = (SimpleBookmark) xc1.getBookmark(SimpleBookmark.class);
- assertEquals("value", sa.text);
- m_xc.toStartDoc();
- xc1.toPrevToken();
- xc1.removeXml();
- xc1.toStartDoc();
- assertTrue(m_xc.isAtSamePositionAs(xc1));
- assertEquals("<foo/>", m_xc.xmlText());
- //test modified, the two cursors are not in the same
- //tree anymore
- assertTrue(xc1.toBookmark(_theBookmark));
- assertTrue(!xc1.isInSameDocument(m_xc));
-// assertTrue(!xc1.isLeftOf(m_xc));
-
- sa = (SimpleBookmark) xc1.getBookmark(SimpleBookmark.class);
- assertNotNull(sa);
- assertEquals(TokenType.TEXT, xc1.currentTokenType());
- xc1.dispose();
+ try (XmlCursor xc1 = m_xc.newCursor()) {
+ xc1.toBookmark(_theBookmark);
+ SimpleBookmark sa = (SimpleBookmark) xc1.getBookmark(SimpleBookmark.class);
+ assertEquals("value", sa.text);
+ m_xc.toStartDoc();
+ xc1.toPrevToken();
+ xc1.removeXml();
+ xc1.toStartDoc();
+ assertTrue(m_xc.isAtSamePositionAs(xc1));
+ assertEquals("<foo/>", m_xc.xmlText());
+ //test modified, the two cursors are not in the same
+ //tree anymore
+ assertTrue(xc1.toBookmark(_theBookmark));
+ assertTrue(!xc1.isInSameDocument(m_xc));
+// assertTrue(!xc1.isLeftOf(m_xc));
+
+ sa = (SimpleBookmark) xc1.getBookmark(SimpleBookmark.class);
+ assertNotNull(sa);
+ assertEquals(TokenType.TEXT, xc1.currentTokenType());
+ }
}
@Test
@@ -311,21 +299,19 @@ public class ToBookmarkTest extends Basi
toNextTokenOfType(m_xc, TokenType.ATTR);
m_xc.setBookmark(_theBookmark); // set annot. at attribute
m_xc.toStartDoc();
- XmlCursor xc1 = m_xc.newCursor();
- xc1.toBookmark(_theBookmark);
- SimpleBookmark sa = (SimpleBookmark) xc1.getBookmark(SimpleBookmark.class);
- assertEquals("value", sa.text);
- xc1.toEndDoc();
+ try (XmlCursor xc1 = m_xc.newCursor()) {
+ xc1.toBookmark(_theBookmark);
+ SimpleBookmark sa = (SimpleBookmark) xc1.getBookmark(SimpleBookmark.class);
+ assertEquals("value", sa.text);
+ xc1.toEndDoc();
+
+ toNextTokenOfType(m_xc, TokenType.START);
+ m_xc.removeAttribute(new QName("attr0"));
+ m_xc.toStartDoc();
- toNextTokenOfType(m_xc, TokenType.START);
- m_xc.removeAttribute(new QName("attr0"));
- m_xc.toStartDoc();
- try {
assertEquals("<foo>text</foo>", m_xc.xmlText());
assertTrue(xc1.toBookmark(_theBookmark));
assertTrue(!xc1.isInSameDocument(m_xc));
- } finally {
- xc1.dispose();
}
}
@@ -340,17 +326,15 @@ public class ToBookmarkTest extends Basi
m_xc.toPrevChar(2);
assertEquals(3, m_xc.removeChars(3)); // '2' should be deleted
assertEquals("34", m_xc.getTextValue());
- XmlCursor xc1 = m_xc.newCursor();
- xc1.toEndDoc();
- try {
+ try (XmlCursor xc1 = m_xc.newCursor()) {
+ xc1.toEndDoc();
+
assertTrue(xc1.toBookmark(_theBookmark));
assertTrue(!xc1.isInSameDocument(m_xc));
SimpleBookmark sa =
(SimpleBookmark) xc1.getBookmark(SimpleBookmark.class);
assertEquals("value", sa.text);
assertEquals(TokenType.TEXT, xc1.currentTokenType());
- } finally {
- xc1.dispose();
}
}
@@ -362,20 +346,18 @@ public class ToBookmarkTest extends Basi
m_xc.toNextChar(2);
assertEquals("xt", m_xc.getTextValue());
m_xc.setBookmark(_theBookmark); // set annot. in middle of TEXT
- XmlCursor xc1 = m_xc.newCursor();
- xc1.toEndDoc();
- m_xc.toPrevToken();
- m_xc.setTextValue("changed");
- m_xc.toStartDoc();
- assertEquals("<foo>changed</foo>", m_xc.xmlText());
- try {
+ try (XmlCursor xc1 = m_xc.newCursor()) {
+ xc1.toEndDoc();
+ m_xc.toPrevToken();
+ m_xc.setTextValue("changed");
+ m_xc.toStartDoc();
+ assertEquals("<foo>changed</foo>", m_xc.xmlText());
+
assertTrue(xc1.toBookmark(_theBookmark));
assertTrue(!xc1.isInSameDocument(m_xc));
SimpleBookmark sa = (SimpleBookmark) xc1.getBookmark(SimpleBookmark.class);
assertEquals("value", sa.text);
assertEquals(TokenType.TEXT, xc1.currentTokenType());
- } finally {
- xc1.dispose();
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/detailed/XmlLineNumberTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/detailed/XmlLineNumberTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/detailed/XmlLineNumberTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/detailed/XmlLineNumberTest.java Thu Jan 6 17:54:30 2022
@@ -47,20 +47,22 @@ public class XmlLineNumberTest extends C
XmlOptions opt = new XmlOptions();
opt.setLoadLineNumbers();
XmlObject xo = XmlObject.Factory.parse(f, opt);
- XmlCursor c = xo.newCursor();
- c.toFirstChild();
- assertEquals(XmlCursor.TokenType.START, c.currentTokenType());
- XmlLineNumber ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- assertNotNull(ln);
- assertEquals(16, ln.getLine());
- c.toFirstChild();
- ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- assertEquals(17, ln.getLine());
- c.toEndToken();
- assertEquals(XmlCursor.TokenType.END, c.currentTokenType());
- ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- // no bookmark at END
- assertNull(ln);
+
+ try (XmlCursor c = xo.newCursor()) {
+ c.toFirstChild();
+ assertEquals(XmlCursor.TokenType.START, c.currentTokenType());
+ XmlLineNumber ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ assertNotNull(ln);
+ assertEquals(16, ln.getLine());
+ c.toFirstChild();
+ ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ assertEquals(17, ln.getLine());
+ c.toEndToken();
+ assertEquals(XmlCursor.TokenType.END, c.currentTokenType());
+ ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ // no bookmark at END
+ assertNull(ln);
+ }
}
/**
@@ -73,21 +75,23 @@ public class XmlLineNumberTest extends C
XmlOptions opt = new XmlOptions();
opt.setLoadLineNumbersEndElement();
XmlObject xo = XmlObject.Factory.parse(f, opt);
- XmlCursor c = xo.newCursor();
- c.toFirstChild();
- assertEquals(XmlCursor.TokenType.START, c.currentTokenType());
- XmlLineNumber ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- assertNotNull(ln);
- assertEquals(16, ln.getLine());
- c.toFirstChild();
- ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- assertEquals(17, ln.getLine());
- c.toEndToken();
- assertEquals(XmlCursor.TokenType.END, c.currentTokenType());
- ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- // there is a bookmark at END
- assertNotNull(ln);
- assertEquals(34, ln.getLine());
+
+ try (XmlCursor c = xo.newCursor()) {
+ c.toFirstChild();
+ assertEquals(XmlCursor.TokenType.START, c.currentTokenType());
+ XmlLineNumber ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ assertNotNull(ln);
+ assertEquals(16, ln.getLine());
+ c.toFirstChild();
+ ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ assertEquals(17, ln.getLine());
+ c.toEndToken();
+ assertEquals(XmlCursor.TokenType.END, c.currentTokenType());
+ ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ // there is a bookmark at END
+ assertNotNull(ln);
+ assertEquals(34, ln.getLine());
+ }
}
/**
@@ -98,23 +102,25 @@ public class XmlLineNumberTest extends C
public void testLineNumber1() throws Exception {
XmlOptions opt = new XmlOptions().setLoadLineNumbers();
XmlObject xo = XmlObject.Factory.parse(xml, opt);
- XmlCursor c = xo.newCursor();
- c.toFirstContentToken();
- c.toFirstChild();
- XmlLineNumber ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- assertEquals(1, ln.getLine());
- assertEquals(50, ln.getColumn());
- // offset is not implemented
- assertEquals(-1, ln.getOffset());
- c.toFirstChild();
- ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- assertEquals(2, ln.getLine());
- assertEquals(10, ln.getColumn());
- c.toFirstChild();
- ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- assertEquals(3, ln.getLine());
- // finishes after reading after <first_name> + 2xtabs
- assertEquals(14, ln.getColumn());
+
+ try (XmlCursor c = xo.newCursor()) {
+ c.toFirstContentToken();
+ c.toFirstChild();
+ XmlLineNumber ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ assertEquals(1, ln.getLine());
+ assertEquals(50, ln.getColumn());
+ // offset is not implemented
+ assertEquals(-1, ln.getOffset());
+ c.toFirstChild();
+ ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ assertEquals(2, ln.getLine());
+ assertEquals(10, ln.getColumn());
+ c.toFirstChild();
+ ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ assertEquals(3, ln.getLine());
+ // finishes after reading after <first_name> + 2xtabs
+ assertEquals(14, ln.getColumn());
+ }
}
/**
@@ -127,28 +133,30 @@ public class XmlLineNumberTest extends C
XmlOptions opt = new XmlOptions();
opt.setLoadLineNumbersEndElement();
XmlObject xo = XmlObject.Factory.parse(f, opt);
- XmlCursor c = xo.newCursor();
- c.toFirstContentToken();
- c.toFirstChild();
- XmlLineNumber ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- assertEquals(17, ln.getLine());
- assertEquals(15, ln.getColumn());
- assertEquals(-1, ln.getOffset());
- c.toFirstChild();
- c.push();
- ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- assertEquals(18, ln.getLine());
- assertEquals(13, ln.getColumn());
- c.toEndToken();
- ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- assertEquals(18, ln.getLine());
- assertEquals(33, ln.getColumn());
- c.pop();
- c.toNextSibling(); //address
- c.toEndToken();
- ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
- assertEquals(24, ln.getLine());
- assertEquals(17, ln.getColumn());
- assertEquals(-1, ln.getOffset());
+
+ try (XmlCursor c = xo.newCursor()) {
+ c.toFirstContentToken();
+ c.toFirstChild();
+ XmlLineNumber ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ assertEquals(17, ln.getLine());
+ assertEquals(15, ln.getColumn());
+ assertEquals(-1, ln.getOffset());
+ c.toFirstChild();
+ c.push();
+ ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ assertEquals(18, ln.getLine());
+ assertEquals(13, ln.getColumn());
+ c.toEndToken();
+ ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ assertEquals(18, ln.getLine());
+ assertEquals(33, ln.getColumn());
+ c.pop();
+ c.toNextSibling(); //address
+ c.toEndToken();
+ ln = (XmlLineNumber) c.getBookmark(XmlLineNumber.class);
+ assertEquals(24, ln.getLine());
+ assertEquals(17, ln.getColumn());
+ assertEquals(-1, ln.getOffset());
+ }
}
}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/CharactersTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/CharactersTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/CharactersTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/CharactersTest.java Thu Jan 6 17:54:30 2022
@@ -198,21 +198,22 @@ public abstract class CharactersTest {
@Before
public void setUp() throws Exception {
- XmlCursor cur = XmlObject.Factory.newInstance().newCursor();
- cur.toNextToken();
+ try (XmlCursor cur = XmlObject.Factory.newInstance().newCursor()) {
+ cur.toNextToken();
- // cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"), "val0");
- cur.insertComment(" some comment ");
- cur.beginElement(new QName("foo.org", "foo", ""));
- cur.insertAttribute("localName");
- cur.insertChars("some text");
- cur.insertElement("foo2");
- cur.toNextToken(); //close foo elt
- cur.insertChars("\t");
+ // cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"), "val0");
+ cur.insertComment(" some comment ");
+ cur.beginElement(new QName("foo.org", "foo", ""));
+ cur.insertAttribute("localName");
+ cur.insertChars("some text");
+ cur.insertElement("foo2");
+ cur.toNextToken(); //close foo elt
+ cur.insertChars("\t");
- cur.toStartDoc();
- m_stream = getStream(cur);
+ cur.toStartDoc();
+ m_stream = getStream(cur);
+ }
}
@After
Modified: xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/GeneralMethodsTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/GeneralMethodsTest.java?rev=1896764&r1=1896763&r2=1896764&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/GeneralMethodsTest.java (original)
+++ xmlbeans/trunk/src/test/java/xmlcursor/jsr173/common/GeneralMethodsTest.java Thu Jan 6 17:54:30 2022
@@ -102,27 +102,28 @@ public abstract class GeneralMethodsTest
@Before
public void setUp() throws Exception {
- XmlCursor cur = XmlObject.Factory.newInstance().newCursor();
- cur.toNextToken();
+ try (XmlCursor cur = XmlObject.Factory.newInstance().newCursor()) {
+ cur.toNextToken();
- cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"),
- "val0");
- cur.insertAttributeWithValue(new QName("", "at1", "pre"), "val1");
- cur.insertNamespace("pre", "foons.bar.org");
- cur.beginElement(new QName("foo.org", "foo", ""));
- cur.insertAttribute("localName");
- cur.insertChars("some text");
- cur.toNextToken();
- cur.toNextToken();//end elt
- cur.insertProcInst("xml-stylesheet", "http://foobar");
-
- cur.toStartDoc();
- XmlDocumentProperties opt = cur.documentProperties();
-
- m_stream1 = getStream(cur);
-
- opt.setEncoding("utf-8");
- m_stream = getStream(cur);
+ cur.insertAttributeWithValue(new QName("foo.org", "at0", "pre"),
+ "val0");
+ cur.insertAttributeWithValue(new QName("", "at1", "pre"), "val1");
+ cur.insertNamespace("pre", "foons.bar.org");
+ cur.beginElement(new QName("foo.org", "foo", ""));
+ cur.insertAttribute("localName");
+ cur.insertChars("some text");
+ cur.toNextToken();
+ cur.toNextToken();//end elt
+ cur.insertProcInst("xml-stylesheet", "http://foobar");
+
+ cur.toStartDoc();
+ XmlDocumentProperties opt = cur.documentProperties();
+
+ m_stream1 = getStream(cur);
+
+ opt.setEncoding("utf-8");
+ m_stream = getStream(cur);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org