Modified: xmlbeans/trunk/src/test/java/random/checkin/RandomTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/random/checkin/RandomTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/random/checkin/RandomTest.java (original) +++ xmlbeans/trunk/src/test/java/random/checkin/RandomTest.java Sun Feb 6 01:51:55 2022 @@ -16,8 +16,8 @@ package random.checkin; import org.apache.xmlbeans.impl.tool.CommandLine; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import random.common.Random; import java.util.Arrays; @@ -25,12 +25,12 @@ import java.util.Arrays; public class RandomTest { - long seed; + long seed; int iterations; int threads; int docs; - @Before + @BeforeEach public void setUp() { seed = System.currentTimeMillis(); iterations = Integer.MAX_VALUE; @@ -39,11 +39,11 @@ public class RandomTest { } @Test - public void testNoQuery() { + void testNoQuery() { String[] args = new String[]{"-seed", "0", "-i", "20", "-noquery"}; CommandLine cl = new CommandLine(args, - Arrays.asList(new String[]{"?", "help", "readonly", "noquery", "nosave"}), - Arrays.asList(new String[]{"seed", "i", "t", "docs", "?", "help"})); + Arrays.asList("?", "help", "readonly", "noquery", "nosave"), + Arrays.asList("seed", "i", "t", "docs", "?", "help")); Random.runTest(cl); } }
Modified: xmlbeans/trunk/src/test/java/scomp/attributes/detailed/AttrGroupTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/attributes/detailed/AttrGroupTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/attributes/detailed/AttrGroupTest.java (original) +++ xmlbeans/trunk/src/test/java/scomp/attributes/detailed/AttrGroupTest.java Sun Feb 6 01:51:55 2022 @@ -16,21 +16,22 @@ package scomp.attributes.detailed; import org.apache.xmlbeans.*; -import org.junit.Test; -import scomp.common.BaseCase; +import org.junit.jupiter.api.Test; import xbean.scomp.attribute.attributeGroup.AttGroupEltDocument; import xbean.scomp.attribute.attributeGroup.GlobalT; import javax.xml.namespace.QName; import java.math.BigDecimal; import java.math.BigInteger; +import java.util.Collection; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; +import static scomp.common.BaseCase.getErrorCodes; -public class AttrGroupTest extends BaseCase { +public class AttrGroupTest { @Test - public void testAttributeGroup() throws Throwable { + void testAttributeGroup() throws Throwable { AttGroupEltDocument doc = AttGroupEltDocument.Factory.newInstance(); GlobalT elt = doc.addNewAttGroupElt(); XmlObject obj = elt.addNewChild2(); @@ -46,30 +47,18 @@ public class AttrGroupTest extends BaseC try (XmlCursor cur = elt.newCursor()) { //move to document element cur.toNextToken(); - cur.insertAttribute(new QName("http://org.apache.sample", "attr", - "pre")); + cur.insertAttribute(new QName("http://org.apache.sample", "attr", "pre")); } - String[] errExpected=new String[]{ - XmlErrorCodes - .ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE}; - assertTrue( !doc.validate(validateOptions) ); - - /* assertTrue( compareErrorCodes(new String[]{ - XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID - }) ); */ - assertEquals(1, errorList.size()); - showErrors(); - assertTrue(compareErrorCodes(errExpected)); + String[] errExpected={XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE}; + + XmlOptions validateOptions = createOptions(); + assertFalse(doc.validate(validateOptions)); + Collection<XmlError> errorList = validateOptions.getErrorListener(); + assertEquals(1, errorList.size()); + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); - System.out.println("*******"); elt.setID("IdAttr"); - try { - assertTrue(elt.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + assertTrue(elt.validate(validateOptions)); } } Modified: xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrDefault.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrDefault.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrDefault.java (original) +++ xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrDefault.java Sun Feb 6 01:51:55 2022 @@ -16,20 +16,21 @@ package scomp.attributes.detailed; import org.apache.xmlbeans.XmlErrorCodes; import org.apache.xmlbeans.XmlException; -import org.junit.Test; -import scomp.common.BaseCase; +import org.apache.xmlbeans.XmlOptions; +import org.junit.jupiter.api.Test; import xbean.scomp.attribute.globalAttrDefault.GlobalAttrDefaultDocDocument; import xbean.scomp.attribute.globalAttrDefault.GlobalAttrDefaultT; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; +import static scomp.common.BaseCase.getErrorCodes; -public class GlobalAttrDefault extends BaseCase { +public class GlobalAttrDefault { /** * If value is missing default should appear */ @Test - public void testMissing() { + void testMissing() { GlobalAttrDefaultT testDoc = GlobalAttrDefaultDocDocument.Factory.newInstance() .addNewGlobalAttrDefaultDoc(); @@ -40,7 +41,7 @@ public class GlobalAttrDefault extends B * Test val preservation */ @Test - public void testPresent() { + void testPresent() { GlobalAttrDefaultT testDoc = GlobalAttrDefaultDocDocument.Factory.newInstance() .addNewGlobalAttrDefaultDoc(); @@ -52,38 +53,30 @@ public class GlobalAttrDefault extends B * Test empty string: should be preserved */ @Test - public void testPresentEmpty() throws Throwable { + void testPresentEmpty() throws Throwable { GlobalAttrDefaultT testDoc = GlobalAttrDefaultDocDocument.Factory.parse("<pre:GlobalAttrDefaultDoc" + " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrDefault\" " + " pre:testattribute=\"\"/>").getGlobalAttrDefaultDoc(); assertEquals("", testDoc.getTestattribute()); - try { - assertTrue(testDoc.validate(validateOptions)); - } catch (Throwable t) { - showErrors(); - throw t; - } + assertTrue(testDoc.validate(createOptions())); } /** * Type mismatch */ - public void testBadType() throws XmlException { + @Test + void testBadType() throws XmlException { GlobalAttrDefaultT testDoc = GlobalAttrDefaultDocDocument.Factory.parse("<pre:GlobalAttrDefaultDoc" + " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrDefault\" " + "pre:testattributeInt=\"\"/>").getGlobalAttrDefaultDoc(); - String[] errExpected=new String[]{ - XmlErrorCodes.DECIMAL - }; - assertTrue(!testDoc.validate(validateOptions)); - assertEquals(1, errorList.size()); - showErrors(); - assertTrue(compareErrorCodes(errExpected)); - + XmlOptions validateOptions = createOptions(); + assertFalse(testDoc.validate(validateOptions)); + String[] errExpected={XmlErrorCodes.DECIMAL}; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } Modified: xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrFixed.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrFixed.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrFixed.java (original) +++ xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrFixed.java Sun Feb 6 01:51:55 2022 @@ -18,45 +18,38 @@ package scomp.attributes.detailed; import org.apache.xmlbeans.XmlErrorCodes; import org.apache.xmlbeans.XmlException; -import org.junit.Test; -import scomp.common.BaseCase; +import org.apache.xmlbeans.XmlOptions; +import org.junit.jupiter.api.Test; import xbean.scomp.attribute.globalAttrFixed.GlobalAttrFixedDocDocument; import xbean.scomp.attribute.globalAttrFixed.GlobalAttrFixedT; import java.math.BigInteger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; +import static scomp.common.BaseCase.getErrorCodes; -public class GlobalAttrFixed extends BaseCase { +public class GlobalAttrFixed { /** * Missing OK */ @Test - public void testValidMissing() throws Exception { - GlobalAttrFixedT testDoc = - GlobalAttrFixedDocDocument.Factory.parse("<pre:GlobalAttrFixedDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + - "/>").getGlobalAttrFixedDoc(); + void testValidMissing() throws Exception { + String input = "<pre:GlobalAttrFixedDoc xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" />"; + GlobalAttrFixedT testDoc = GlobalAttrFixedDocDocument.Factory.parse(input).getGlobalAttrFixedDoc(); assertTrue(testDoc.validate()); - } @Test - public void testBothValid() throws Throwable { - GlobalAttrFixedT testDoc = - GlobalAttrFixedDocDocument.Factory.parse("<pre:GlobalAttrFixedDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + - "pre:testattributeStr=\"XBeanAttrStr\" " + - "pre:testattributeInt=\" 1 \"/>").getGlobalAttrFixedDoc(); - try { - assertTrue(testDoc.validate(validateOptions)); - } catch (Throwable t) { - showErrors(); - throw t; - } - + void testBothValid() throws Throwable { + String input = + "<pre:GlobalAttrFixedDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + + "pre:testattributeStr=\"XBeanAttrStr\" " + + "pre:testattributeInt=\" 1 \"/>"; + GlobalAttrFixedT testDoc = GlobalAttrFixedDocDocument.Factory.parse(input).getGlobalAttrFixedDoc(); + assertTrue(testDoc.validate(createOptions())); assertEquals("XBeanAttrStr", testDoc.getTestattributeStr()); assertEquals(1, testDoc.getTestattributeInt().intValue()); } @@ -65,102 +58,84 @@ public class GlobalAttrFixed extends Bas * value does not match fixed */ @Test - public void testStringInvalidSpace() throws Exception { - GlobalAttrFixedT testAtt = - GlobalAttrFixedDocDocument.Factory.parse("<pre:GlobalAttrFixedDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + - "pre:testattributeStr=\" XBeanAttrStr \"/>").getGlobalAttrFixedDoc(); - String[] errExpected = new String[]{ - XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED - }; - assertTrue(!testAtt.validate(validateOptions)); - assertEquals(1, errorList.size()); - showErrors(); - assertTrue(compareErrorCodes(errExpected)); + void testStringInvalidSpace() throws Exception { + String input = + "<pre:GlobalAttrFixedDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + + "pre:testattributeStr=\" XBeanAttrStr \"/>"; + GlobalAttrFixedT testAtt = GlobalAttrFixedDocDocument.Factory.parse(input).getGlobalAttrFixedDoc(); + XmlOptions validateOptions = createOptions(); + assertFalse(testAtt.validate(validateOptions)); + String[] errExpected = {XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED}; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); //catch XmlExceptionHere; } @Test - public void testStringInvalidValue() throws Exception { - GlobalAttrFixedT testAtt = - GlobalAttrFixedDocDocument.Factory.parse("<pre:GlobalAttrFixedDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + - "pre:testattributeStr=\" foobar \" />").getGlobalAttrFixedDoc(); - String[] errExpected = new String[]{ - XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED - }; - assertTrue(!testAtt.validate(validateOptions)); - assertEquals(1, errorList.size()); - showErrors(); - assertTrue(compareErrorCodes(errExpected)); + void testStringInvalidValue() throws Exception { + String input = + "<pre:GlobalAttrFixedDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + + "pre:testattributeStr=\" foobar \" />"; + GlobalAttrFixedT testAtt = GlobalAttrFixedDocDocument.Factory.parse(input).getGlobalAttrFixedDoc(); + XmlOptions validateOptions = createOptions(); + assertFalse(testAtt.validate(validateOptions)); + String[] errExpected = {XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED}; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } /** * Test empty string: should be preserved */ @Test - public void testIntInvalidType() throws XmlException { - GlobalAttrFixedT testAtt = - GlobalAttrFixedDocDocument.Factory.parse("<pre:GlobalAttrFixedDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + - "pre:testattributeInt=\" foo \"/>").getGlobalAttrFixedDoc(); - - assertTrue(!testAtt.validate(validateOptions)); - assertEquals(1, errorList.size()); - showErrors(); - String[] errExpected = new String[]{ - XmlErrorCodes.DECIMAL - }; - assertTrue(compareErrorCodes(errExpected)); + void testIntInvalidType() throws XmlException { + String input = + "<pre:GlobalAttrFixedDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + + "pre:testattributeInt=\" foo \"/>"; + GlobalAttrFixedT testAtt = GlobalAttrFixedDocDocument.Factory.parse(input).getGlobalAttrFixedDoc(); + + XmlOptions validateOptions = createOptions(); + assertFalse(testAtt.validate(validateOptions)); + String[] errExpected = {XmlErrorCodes.DECIMAL}; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } @Test - public void testIntInvalidValue() throws XmlException { - GlobalAttrFixedT testAtt = - GlobalAttrFixedDocDocument.Factory.parse("<pre:GlobalAttrFixedDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + - "pre:testattributeInt=\" 4 \"/>").getGlobalAttrFixedDoc(); - assertTrue(!testAtt.validate(validateOptions)); - assertEquals(1, errorList.size()); - showErrors(); - String[] errExpected = new String[]{ - XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED - }; - assertTrue(compareErrorCodes(errExpected)); - + void testIntInvalidValue() throws XmlException { + String input = + "<pre:GlobalAttrFixedDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + + "pre:testattributeInt=\" 4 \"/>"; + GlobalAttrFixedT testAtt = GlobalAttrFixedDocDocument.Factory.parse(input).getGlobalAttrFixedDoc(); + XmlOptions validateOptions = createOptions(); + assertFalse(testAtt.validate(validateOptions)); + String[] errExpected = {XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED}; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } @Test - public void testIntValidValue() throws Throwable { - GlobalAttrFixedT testAtt = - GlobalAttrFixedDocDocument.Factory.parse("<pre:GlobalAttrFixedDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + - "pre:testattributeInt=\" +01 \"/>").getGlobalAttrFixedDoc(); - try { - assertTrue(testAtt.validate(validateOptions)); - } catch (Throwable t) { - showErrors(); - throw t; - } - - //catch XmlExceptionHere; + void testIntValidValue() throws Throwable { + String input = + "<pre:GlobalAttrFixedDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrFixed\" " + + "pre:testattributeInt=\" +01 \"/>"; + GlobalAttrFixedT testAtt = GlobalAttrFixedDocDocument.Factory.parse(input).getGlobalAttrFixedDoc(); + assertTrue(testAtt.validate(createOptions())); } @Test - public void testSetValue() { - GlobalAttrFixedDocDocument testAtt = - GlobalAttrFixedDocDocument.Factory.newInstance(); + void testSetValue() { + GlobalAttrFixedDocDocument testAtt = GlobalAttrFixedDocDocument.Factory.newInstance(); GlobalAttrFixedT testDoc = testAtt.addNewGlobalAttrFixedDoc(); testDoc.setTestattributeInt(new BigInteger("5")); //shouldn't this fail? assertEquals(5, testDoc.getTestattributeInt().intValue()); - assertTrue(!testDoc.validate(validateOptions)); - assertEquals(1, errorList.size()); - showErrors(); - String[] errExpected = new String[]{ - XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED}; - assertTrue(compareErrorCodes(errExpected)); + XmlOptions validateOptions = createOptions(); + assertFalse(testDoc.validate(validateOptions)); + String[] errExpected = {XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED}; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } } Modified: xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrIdTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrIdTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrIdTest.java (original) +++ xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrIdTest.java Sun Feb 6 01:51:55 2022 @@ -14,33 +14,21 @@ */ package scomp.attributes.detailed; -import org.junit.Test; -import scomp.common.BaseCase; -import xbean.scomp.attribute.globalAttrId.GlobalAttrIdT; +import org.junit.jupiter.api.Test; import xbean.scomp.attribute.globalAttrId.GlobalAttrIdDocument; -import xbean.scomp.attribute.globalAttrId.IDRefT; -import org.apache.xmlbeans.XmlString; -import javax.xml.namespace.QName; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static scomp.common.BaseCase.createOptions; -import static org.junit.Assert.assertTrue; - -public class GlobalAttrIdTest extends BaseCase { +public class GlobalAttrIdTest { @Test - public void testId() throws Throwable { - GlobalAttrIdDocument testDoc = - GlobalAttrIdDocument.Factory.newInstance(); + void testId() throws Throwable { + GlobalAttrIdDocument testDoc = GlobalAttrIdDocument.Factory.newInstance(); GlobalAttrIdDocument.GlobalAttrId elt = testDoc.addNewGlobalAttrId(); elt.addNewIDElement().setId1("foobar"); elt.addNewIDRefElement().setIdref1("foobar"); - try { - assertTrue(testDoc.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + assertTrue(testDoc.validate(createOptions())); } } Modified: xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrType.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrType.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrType.java (original) +++ xmlbeans/trunk/src/test/java/scomp/attributes/detailed/GlobalAttrType.java Sun Feb 6 01:51:55 2022 @@ -14,34 +14,31 @@ */ package scomp.attributes.detailed; -import org.junit.Test; -import scomp.common.BaseCase; -import org.apache.xmlbeans.*; +import org.apache.xmlbeans.XmlDouble; +import org.apache.xmlbeans.XmlInteger; +import org.apache.xmlbeans.XmlString; +import org.junit.jupiter.api.Test; import xbean.scomp.attribute.globalAttrType.GlobalAttrTypeDocDocument; import xbean.scomp.attribute.globalAttrType.GlobalAttrTypeT; -import java.util.ArrayList; 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; +import static scomp.common.BaseCase.createOptions; -public class GlobalAttrType extends BaseCase { +public class GlobalAttrType { @Test - public void testAllValid() throws Throwable { - GlobalAttrTypeT testDoc = - GlobalAttrTypeDocDocument.Factory.parse("<pre:GlobalAttrTypeDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrType\" " + - "pre:attSimple=\"XBeanAttrStr\" " + - "pre:attAnyType=\" 1 \" " + - "pre:attAnonymous=\" 1 \" />").getGlobalAttrTypeDoc(); - try { - assertTrue(testDoc.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + void testAllValid() throws Throwable { + String input = + "<pre:GlobalAttrTypeDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrType\" " + + "pre:attSimple=\"XBeanAttrStr\" " + + "pre:attAnyType=\" 1 \" " + + "pre:attAnonymous=\" 1 \" />"; + + GlobalAttrTypeT testDoc = GlobalAttrTypeDocDocument.Factory.parse(input).getGlobalAttrTypeDoc(); + assertTrue(testDoc.validate(createOptions())); assertTrue(testDoc.isSetAttSimple()); assertEquals("XBeanAttrStr", testDoc.getAttSimple()); @@ -53,96 +50,54 @@ public class GlobalAttrType extends Base * This should awlays be valid */ @Test - public void testAnyType() throws Throwable { - GlobalAttrTypeT testDoc = - GlobalAttrTypeDocDocument.Factory.parse("<pre:GlobalAttrTypeDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrType\" " + - " pre:attAnyType=\" 1 \" " + - " />").getGlobalAttrTypeDoc(); - - try { - assertTrue(testDoc.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + void testAnyType() throws Throwable { + String input = + "<pre:GlobalAttrTypeDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrType\" " + + " pre:attAnyType=\" 1 \" " + + " />"; + + GlobalAttrTypeT testDoc = GlobalAttrTypeDocDocument.Factory.parse(input).getGlobalAttrTypeDoc(); + assertTrue(testDoc.validate(createOptions())); assertEquals(" 1 ", testDoc.getAttAnyType().getStringValue()); - try { - assertTrue(testDoc.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + assertTrue(testDoc.validate(createOptions())); XmlInteger ival = XmlInteger.Factory.newInstance(); ival.setBigIntegerValue(BigInteger.ZERO); testDoc.setAttAnyType(ival); // assertEquals(BigInteger.ZERO,testDoc.getAttAnyType().changeType(XmlInteger.type)); - assertEquals(BigInteger.ZERO.toString(), - testDoc.getAttAnyType().getStringValue()); + assertEquals(BigInteger.ZERO.toString(), testDoc.getAttAnyType().getStringValue()); - try { - assertTrue(testDoc.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + assertTrue(testDoc.validate(createOptions())); XmlString sval = XmlString.Factory.newInstance(); sval.setStringValue("foobar"); testDoc.setAttAnyType(sval); assertEquals("foobar", testDoc.getAttAnyType().getStringValue()); - try { - assertTrue(testDoc.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + assertTrue(testDoc.validate(createOptions())); XmlDouble fval = XmlDouble.Factory.newInstance(); fval.setDoubleValue(-0.01); testDoc.setAttAnyType(fval); assertEquals("-0.01", testDoc.getAttAnyType().getStringValue()); - try { - assertTrue(testDoc.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + assertTrue(testDoc.validate(createOptions())); } @Test - public void testAnonType() throws Throwable { - GlobalAttrTypeT testDoc = - GlobalAttrTypeDocDocument.Factory - .parse("<pre:GlobalAttrTypeDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrType\" " + - "pre:attAnonymous=\" 1 \" " + - " />").getGlobalAttrTypeDoc(); - try { - assertTrue(testDoc.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + void testAnonType() throws Throwable { + String input = + "<pre:GlobalAttrTypeDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/GlobalAttrType\" " + + "pre:attAnonymous=\" 1 \" " + + " />"; + GlobalAttrTypeT testDoc = GlobalAttrTypeDocDocument.Factory.parse(input).getGlobalAttrTypeDoc(); + assertTrue(testDoc.validate(createOptions())); assertEquals(1, testDoc.getAttAnonymous().intValue()); testDoc.setAttAnonymous( BigInteger.ZERO ); assertEquals(0, testDoc.getAttAnonymous().intValue()); - try { - assertTrue(testDoc.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + assertTrue(testDoc.validate(createOptions())); } } Modified: xmlbeans/trunk/src/test/java/scomp/attributes/detailed/LocalAttrFixedDefault.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/attributes/detailed/LocalAttrFixedDefault.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/attributes/detailed/LocalAttrFixedDefault.java (original) +++ xmlbeans/trunk/src/test/java/scomp/attributes/detailed/LocalAttrFixedDefault.java Sun Feb 6 01:51:55 2022 @@ -15,15 +15,16 @@ package scomp.attributes.detailed; import org.apache.xmlbeans.XmlErrorCodes; -import org.junit.Test; -import scomp.common.BaseCase; +import org.apache.xmlbeans.XmlOptions; +import org.junit.jupiter.api.Test; import xbean.scomp.attribute.localAttrFixedDefault.LocalAttrFixedDefaultDocument; import xbean.scomp.attribute.localAttrFixedDefault.LocalAttrFixedDefaultT; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; +import static scomp.common.BaseCase.getErrorCodes; -public class LocalAttrFixedDefault extends BaseCase { +public class LocalAttrFixedDefault { /** * Verify that a local attribute can add a fixed value but can not overwrite * an existing fixed val @@ -32,29 +33,19 @@ public class LocalAttrFixedDefault exten //ensure default val is shadowed locally //fixed can not be... @Test - public void testDefault() throws Throwable { - LocalAttrFixedDefaultT testDoc = - LocalAttrFixedDefaultDocument.Factory.newInstance() - .addNewLocalAttrFixedDefault(); + void testDefault() throws Throwable { + LocalAttrFixedDefaultT testDoc = LocalAttrFixedDefaultDocument.Factory.newInstance().addNewLocalAttrFixedDefault(); assertTrue(testDoc.validate()); assertEquals(2, testDoc.getAttDefault().intValue()); //second fixed value is ignored testDoc.setAttFixed("NEWXBeanAttrStr"); - assertTrue(!testDoc.validate(validateOptions)); - showErrors(); - String[] errExpected = new String[]{ - XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED - }; - assertTrue(compareErrorCodes(errExpected)); + XmlOptions validateOptions = createOptions(); + assertFalse(testDoc.validate(validateOptions)); + String[] errExpected = {XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED}; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); testDoc.setAttFixed("XBeanAttrStr"); - try { - assertTrue(testDoc.validate(validateOptions)); - } catch (Throwable t) { - showErrors(); - throw t; - } - + assertTrue(testDoc.validate(validateOptions)); } } Modified: xmlbeans/trunk/src/test/java/scomp/attributes/detailed/LocalAttrForm.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/attributes/detailed/LocalAttrForm.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/attributes/detailed/LocalAttrForm.java (original) +++ xmlbeans/trunk/src/test/java/scomp/attributes/detailed/LocalAttrForm.java Sun Feb 6 01:51:55 2022 @@ -14,50 +14,42 @@ */ package scomp.attributes.detailed; -import org.junit.Test; -import scomp.common.BaseCase; +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlErrorCodes; +import org.apache.xmlbeans.XmlOptions; +import org.junit.jupiter.api.Test; import xbean.scomp.namespace.attributeFormDefault.AttributeUnqualifiedDocument; import javax.xml.namespace.QName; -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlErrorCodes; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; +import static scomp.common.BaseCase.getErrorCodes; -import static org.junit.Assert.assertTrue; - -public class LocalAttrForm extends BaseCase{ +public class LocalAttrForm { /** * attrFormDefault is "qualified", overwrite locally to "unqualified" */ @Test - public void testRun() throws Throwable{ + void testRun() throws Throwable{ String input="<ns:AttributeUnqualified " + "xmlns:ns=\"http://xbean/scomp/namespace/AttributeFormDefault\"" + " LocalAttribute=\"foobar\"/>"; - AttributeUnqualifiedDocument doc= - AttributeUnqualifiedDocument.Factory.parse(input); + AttributeUnqualifiedDocument doc= AttributeUnqualifiedDocument.Factory.parse(input); - try { - assertTrue(doc.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + XmlOptions validateOptions = createOptions(); + assertTrue(doc.validate(validateOptions)); try (XmlCursor c = doc.getAttributeUnqualified().getLocalAttribute().newCursor()) { c.setName(new QName( "http://xbean/scomp/namespace/AttributeFormDefault", "LocalAttribute")); } - assertTrue( !doc.validate(validateOptions) ); - System.out.println(doc.xmlText()); - showErrors(); - String[] errExpected = new String[] - {XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$NO_WILDCARD}; - assertTrue(compareErrorCodes(errExpected)); + assertFalse(doc.validate(validateOptions)); + String[] errExpected = {XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$NO_WILDCARD}; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } } Modified: xmlbeans/trunk/src/test/java/scomp/attributes/detailed/LocalAttrUse.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/attributes/detailed/LocalAttrUse.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/attributes/detailed/LocalAttrUse.java (original) +++ xmlbeans/trunk/src/test/java/scomp/attributes/detailed/LocalAttrUse.java Sun Feb 6 01:51:55 2022 @@ -17,8 +17,8 @@ package scomp.attributes.detailed; import org.apache.xmlbeans.XmlErrorCodes; import org.apache.xmlbeans.XmlException; -import org.junit.Test; -import scomp.common.BaseCase; +import org.apache.xmlbeans.XmlOptions; +import org.junit.jupiter.api.Test; import xbean.scomp.attribute.localAttrUse.LocalAttrUseDocDocument; import xbean.scomp.attribute.localAttrUse.LocalAttrUseT; import xbean.scomp.derivation.attributeUseProhibited.AttrProhibitedEltDocument; @@ -27,31 +27,27 @@ import xbean.scomp.derivation.attributeU import java.math.BigInteger; import java.util.Calendar; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; +import static scomp.common.BaseCase.getErrorCodes; -public class LocalAttrUse extends BaseCase { +public class LocalAttrUse { /** * Default use of an attribute should be optional * Optional attributes can be missing */ @Test - public void testDefaultOptional() throws Throwable { + void testDefaultOptional() throws Throwable { + String localAttDoc = + "<pre:LocalAttrUseDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/LocalAttrUse\" " + + "attRequired=\"1\" " + + "pre:attRequiredDefault=\"XBeanDef\" " + + "pre:attRequiredFixed=\"XBeanFix\"/>"; + //figure out the deal w/ namespaces here... - LocalAttrUseT testDoc = - LocalAttrUseDocDocument.Factory.parse("<pre:LocalAttrUseDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/LocalAttrUse\" " + - "attRequired=\"1\" " + - "pre:attRequiredDefault=\"XBeanDef\" " + - "pre:attRequiredFixed=\"XBeanFix\"/>") - .getLocalAttrUseDoc(); - - try { - assertTrue(testDoc.validate(validateOptions)); - } catch (Throwable t) { - showErrors(); - throw t; - } + LocalAttrUseT testDoc = LocalAttrUseDocDocument.Factory.parse(localAttDoc).getLocalAttrUseDoc(); + assertTrue(testDoc.validate(createOptions())); } @@ -59,11 +55,10 @@ public class LocalAttrUse extends BaseCa * test that an optional attr is not set before it is set */ @Test - public void testOptional() throws Throwable { - LocalAttrUseDocDocument testDoc = - LocalAttrUseDocDocument.Factory.newInstance(); + void testOptional() throws Throwable { + LocalAttrUseDocDocument testDoc = LocalAttrUseDocDocument.Factory.newInstance(); LocalAttrUseT att = testDoc.addNewLocalAttrUseDoc(); - assertTrue(!att.isSetLastPasswordUpdate()); + assertFalse(att.isSetLastPasswordUpdate()); att.setLastPasswordUpdate(Calendar.getInstance()); assertTrue(att.isSetLastPasswordUpdate()); } @@ -72,126 +67,109 @@ public class LocalAttrUse extends BaseCa * test that an optional attr is not set before it is set */ @Test - public void testOptionalParse() throws Throwable { - LocalAttrUseT testDoc = - LocalAttrUseDocDocument.Factory.parse("<pre:LocalAttrUseDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/LocalAttrUse\" " + - "attRequired=\"1\" " + - "pre:attRequiredDefault=\"XBeanDef\" " + - "pre:attRequiredFixed=\"XBeanFix\"/>") - .getLocalAttrUseDoc(); - assertTrue(!testDoc.isSetLastPasswordUpdate()); + void testOptionalParse() throws Throwable { + String localAttDoc = + "<pre:LocalAttrUseDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/LocalAttrUse\" " + + "attRequired=\"1\" " + + "pre:attRequiredDefault=\"XBeanDef\" " + + "pre:attRequiredFixed=\"XBeanFix\"/>"; + LocalAttrUseT testDoc = LocalAttrUseDocDocument.Factory.parse(localAttDoc).getLocalAttrUseDoc(); + assertFalse(testDoc.isSetLastPasswordUpdate()); testDoc.setLastPasswordUpdate(Calendar.getInstance()); assertTrue(testDoc.isSetLastPasswordUpdate()); - } @Test - public void testRequired() throws XmlException { + void testRequired() throws XmlException { + String localAttDoc = + "<pre:LocalAttrUseDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/LocalAttrUse\" " + + "pre:attRequiredFixed=\"XBeanAttrStr\"" + + " attRequired=\"34\"" + + " />"; + //required attRequired is missing - LocalAttrUseT testDoc = - LocalAttrUseDocDocument.Factory.parse("<pre:LocalAttrUseDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/LocalAttrUse\" " + - "pre:attRequiredFixed=\"XBeanAttrStr\"" + - " attRequired=\"34\"" + - " />").getLocalAttrUseDoc(); + LocalAttrUseT testDoc = LocalAttrUseDocDocument.Factory.parse(localAttDoc).getLocalAttrUseDoc(); //catch XML error and assert message here - assertTrue(!testDoc.validate(validateOptions)); + XmlOptions validateOptions = createOptions(); + assertFalse(testDoc.validate(validateOptions)); //default required should not be explicitly needed? //assertEquals(1, errorList.size()); - showErrors(); - String[] errExpected = new String[]{ + String[] errExpected = { XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED, - XmlErrorCodes. - ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE - }; - assertTrue(compareErrorCodes(errExpected)); - - + XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE + }; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } /** * can not overwrite an existing value */ @Test - public void testRequiredFixed() throws XmlException { - LocalAttrUseT testDoc = - LocalAttrUseDocDocument.Factory.parse("<foo:LocalAttrUseDoc" + - " xmlns:foo=\"http://xbean/scomp/attribute/LocalAttrUse\" " + - "foo:attRequiredFixed=\"foobar\" " + - " />").getLocalAttrUseDoc(); + void testRequiredFixed() throws XmlException { + String localAttDoc = + "<foo:LocalAttrUseDoc" + + " xmlns:foo=\"http://xbean/scomp/attribute/LocalAttrUse\" " + + "foo:attRequiredFixed=\"foobar\" " + + " />"; + LocalAttrUseT testDoc = LocalAttrUseDocDocument.Factory.parse(localAttDoc).getLocalAttrUseDoc(); //catch XML error and assert message here - assertTrue(!testDoc.validate(validateOptions)); + XmlOptions validateOptions = createOptions(); + assertFalse(testDoc.validate(validateOptions)); assertEquals("foobar", testDoc.getAttRequiredFixed()); - showErrors(); //attr locally valid for fixed val - String[] errExpected = new String[]{ - XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED, - XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE , - XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE - }; - assertTrue(compareErrorCodes(errExpected)); - + String[] errExpected = { + XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED, + XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE, + XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE + }; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } @Test - public void testRequiredDefault() throws XmlException { - LocalAttrUseT testDoc = - LocalAttrUseDocDocument.Factory.parse("<pre:LocalAttrUseDoc" + - " xmlns:pre=\"http://xbean/scomp/attribute/LocalAttrUse\" " + - "pre:attRequiredDefault=\"newval\" " + - " />").getLocalAttrUseDoc(); + void testRequiredDefault() throws XmlException { + String localAttDoc = + "<pre:LocalAttrUseDoc" + + " xmlns:pre=\"http://xbean/scomp/attribute/LocalAttrUse\" " + + "pre:attRequiredDefault=\"newval\" " + + " />"; + LocalAttrUseT testDoc = LocalAttrUseDocDocument.Factory.parse(localAttDoc).getLocalAttrUseDoc(); //catch XML error and assert message here - assertTrue(!testDoc.validate(validateOptions)); + XmlOptions validateOptions = createOptions(); + assertFalse(testDoc.validate(validateOptions)); assertEquals("newval", testDoc.getAttRequiredDefault()); - showErrors(); - String[] errExpected = new String[]{ - XmlErrorCodes. - ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE - , - XmlErrorCodes. - ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE - }; - assertTrue(compareErrorCodes(errExpected)); - + String[] errExpected = { + XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE, + XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_REQUIRED_ATTRIBUTE + }; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } @Test - public void testUseProhibited() throws Throwable { - AttrProhibitedEltDocument doc = - AttrProhibitedEltDocument.Factory.newInstance(); + void testUseProhibited() throws Throwable { + AttrProhibitedEltDocument doc = AttrProhibitedEltDocument.Factory.newInstance(); AttrUseProhibited elt = doc.addNewAttrProhibitedElt(); elt.setAttRequiredFixed("XBeanFix"); elt.setAttRequired(new BigInteger("10")); elt.setAttRequiredDefault("boo"); - try { - assertTrue(elt.validate(validateOptions)); - } catch (Throwable t) { - showErrors(); - throw t; - } + XmlOptions validateOptions = createOptions(); + assertTrue(elt.validate(validateOptions)); //use here is prohibited elt.setAttOpt("bla"); - assertTrue(!elt.validate(validateOptions)); - showErrors(); + assertFalse(elt.validate(validateOptions)); //does Kevin have the right code here? doesn't seem so to me? String[] errExpected = new String[]{ XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$NO_WILDCARD }; - assertTrue(compareErrorCodes(errExpected)); - + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); elt.unsetAttOpt(); - try { - assertTrue(elt.validate(validateOptions)); - } catch (Throwable t) { - showErrors(); - throw t; - } + assertTrue(elt.validate(validateOptions)); } } Modified: xmlbeans/trunk/src/test/java/scomp/common/BaseCase.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/common/BaseCase.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/common/BaseCase.java (original) +++ xmlbeans/trunk/src/test/java/scomp/common/BaseCase.java Sun Feb 6 01:51:55 2022 @@ -16,76 +16,17 @@ package scomp.common; import org.apache.xmlbeans.XmlError; import org.apache.xmlbeans.XmlOptions; -import org.junit.Before; import java.util.ArrayList; -public class BaseCase { - protected boolean bVerbose = false; - - protected XmlOptions validateOptions; - protected final ArrayList<XmlError> errorList = new ArrayList<>(); - - @Before - public void setUp() { - validateOptions = new XmlOptions(); - errorList.clear(); - validateOptions.setErrorListener(errorList); - } - - protected void clearErrors() { - //reset error list for next time - errorList.clear(); - validateOptions.setErrorListener(errorList); - } - - public void showErrors() { - if (bVerbose) - for (XmlError error : errorList) { - System.out.println("\n"); - System.out.println("Message: " + error.getMessage() + "\n"); - if (error.getCursorLocation() != null) { - System.out.println("Location of invalid XML: " + error.getCursorLocation().xmlText() + "\n"); - } - } - +public final class BaseCase { + public static XmlOptions createOptions() { + XmlOptions op = new XmlOptions(); + op.setErrorListener(new ArrayList<>()); + return op; } - //TODO: compare regardless of order - public boolean compareErrorCodes(String[] expected) { - if (errorList.size() != expected.length) { - System.err.println(stringOfCodes(expected, errorList)); - - return false; - } - StringBuilder errMessage = new StringBuilder(); - for (int i = 0; i < errorList.size(); i++) { - XmlError error = errorList.get(i); - if (error.getErrorCode() == null) - errMessage.append("Kevin needs a code here " + error.getMessage() + "\n"); - - if (!expected[i].equals(error.getErrorCode())) { - if (errMessage.length() > 0) - System.err.println(errMessage); - - System.err.println(stringOfCodes(expected, errorList)); - return false; - } - } - return true; + public static String[] getErrorCodes(XmlOptions options) { + return options.getErrorListener().stream().map(XmlError::getErrorCode).toArray(String[]::new); } - - public String stringOfCodes(String[] errorCodes, ArrayList<XmlError> actual_errorCodes) { - StringBuilder res = new StringBuilder(); - res.append("\n Expected codes:\n"); - int i = 0; - for (; i < errorCodes.length; i++) - res.append(errorCodes[i] + "\n"); - res.append("\nBut Got: \n"); - for (i = 0; i < actual_errorCodes.size(); i++) - res.append(actual_errorCodes.get(i) + "\n"); - - return res.toString(); - } - } Modified: xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/AnonymousTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/AnonymousTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/AnonymousTest.java (original) +++ xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/AnonymousTest.java Sun Feb 6 01:51:55 2022 @@ -17,21 +17,21 @@ package scomp.contentType.complex.detail import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlInteger; -import org.junit.Test; -import scomp.common.BaseCase; +import org.junit.jupiter.api.Test; import xbean.scomp.contentType.anonymous.AnonymousEltDocument.AnonymousElt; import xbean.scomp.contentType.anonymous.AnonymousMixedEltDocument.AnonymousMixedElt; import java.math.BigInteger; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; /** * testing anonymous complex types */ -public class AnonymousTest extends BaseCase { +public class AnonymousTest { @Test - public void testSimpleAnonymous() throws Throwable { + void testSimpleAnonymous() throws Throwable { AnonymousElt testElt = AnonymousElt.Factory.newInstance(); assertNull(testElt.getChild1()); assertNull(testElt.xgetChild1()); @@ -40,29 +40,19 @@ public class AnonymousTest extends BaseC testElt.setChild2(new BigInteger("5")); testElt.setChild3(new BigInteger("1")); assertEquals("<xml-fragment><child1/><child2>5</child2>" + - "<child3>1</child3></xml-fragment>", - testElt.xmlText()); + "<child3>1</child3></xml-fragment>", testElt.xmlText()); testElt.xsetChild2( XmlInteger.Factory.parse("<xml-fragment>3</xml-fragment>")); ival.setBigIntegerValue(new BigInteger("10")); testElt.xsetChild1(ival); assertEquals("<xml-fragment><child1>10</child1><child2>3</child2>" + - "<child3>1</child3></xml-fragment>", - testElt.xmlText()); - try - { - assertTrue(testElt.validate(validateOptions)); - } - catch (Throwable t) - { - showErrors(); - throw t; - } + "<child3>1</child3></xml-fragment>", testElt.xmlText()); + assertTrue(testElt.validate(createOptions())); } @Test - public void testMixedAnonymous() throws Throwable { + void testMixedAnonymous() throws Throwable { AnonymousMixedElt testElt = AnonymousMixedElt.Factory.newInstance(); assertNull(testElt.getChild1()); assertNull(testElt.xgetChild1()); @@ -76,27 +66,16 @@ public class AnonymousTest extends BaseC } testElt.setChild3(new BigInteger("1")); assertEquals("<xml-fragment>Random mixed content" + - "<child2>5</child2>" + - "<child3>1</child3>" + - "</xml-fragment>", - testElt.xmlText()); + "<child2>5</child2>" + + "<child3>1</child3>" + + "</xml-fragment>", testElt.xmlText()); - testElt.xsetChild1( - XmlInteger.Factory.parse("<xml-fragment>3</xml-fragment>")); + testElt.xsetChild1(XmlInteger.Factory.parse("<xml-fragment>3</xml-fragment>")); assertEquals("<xml-fragment>Random mixed content" + - "<child1>3</child1>" + - "<child2>5</child2>" + - "<child3>1</child3>" + - "</xml-fragment>", testElt.xmlText()); - try - { - assertTrue(testElt.validate(validateOptions)); - } - catch (Throwable t) - { - showErrors(); - throw t; - } - + "<child1>3</child1>" + + "<child2>5</child2>" + + "<child3>1</child3>" + + "</xml-fragment>", testElt.xmlText()); + assertTrue(testElt.validate(createOptions())); } } Modified: xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/ComplexContentTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/ComplexContentTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/ComplexContentTest.java (original) +++ xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/ComplexContentTest.java Sun Feb 6 01:51:55 2022 @@ -18,60 +18,43 @@ package scomp.contentType.complex.detail import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; -import org.junit.Test; -import scomp.common.BaseCase; +import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static scomp.common.BaseCase.createOptions; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public class ComplexContentTest extends BaseCase { +public class ComplexContentTest { // complex types with simple content whose content is declared via an inline <simpleType> // Issue fixed with Svn revision 165352 @Test - public void testSimpleContentDerivation() { - String sInputXsd = "<?xml version=\"1.0\"?>\n" + - "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" + - " <xs:complexType name=\"myType\">\n" + - " <xs:simpleContent>\n" + - " <xs:extension base=\"xs:string\"/>\n" + - " </xs:simpleContent>\n" + - " </xs:complexType>\n" + - " <xs:complexType name=\"fooType\">\n" + - " <xs:simpleContent>\n" + - " <xs:restriction base=\"myType\">\n" + - " <xs:simpleType>\n" + - " <xs:restriction base=\"xs:string\"/>\n" + - " </xs:simpleType>\n" + - " </xs:restriction>\n" + - " </xs:simpleContent>\n" + - " </xs:complexType>\n" + - " <xs:element name=\"root\" type=\"fooType\"/>\n" + - "</xs:schema>"; - - XmlOptions options = new XmlOptions(); - List errors = new ArrayList(); - options.setErrorListener(errors); - - try { - XmlObject xobj = XmlObject.Factory.parse(sInputXsd); - assertTrue("Compiled XmlObject Validation Failed!",xobj.validate()); - } - catch (XmlException xme) { - xme.printStackTrace(); - fail("XmlException thrown when compiling schema"); - } + void testSimpleContentDerivation() throws XmlException { + String sInputXsd = + "<?xml version=\"1.0\"?>\n" + + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" + + " <xs:complexType name=\"myType\">\n" + + " <xs:simpleContent>\n" + + " <xs:extension base=\"xs:string\"/>\n" + + " </xs:simpleContent>\n" + + " </xs:complexType>\n" + + " <xs:complexType name=\"fooType\">\n" + + " <xs:simpleContent>\n" + + " <xs:restriction base=\"myType\">\n" + + " <xs:simpleType>\n" + + " <xs:restriction base=\"xs:string\"/>\n" + + " </xs:simpleType>\n" + + " </xs:restriction>\n" + + " </xs:simpleContent>\n" + + " </xs:complexType>\n" + + " <xs:element name=\"root\" type=\"fooType\"/>\n" + + "</xs:schema>"; + + XmlOptions options = createOptions(); + + XmlObject xobj = XmlObject.Factory.parse(sInputXsd); + assertTrue(xobj.validate(options), "Compiled XmlObject Validation Failed!"); // check for errors - for (Iterator iterator = errors.iterator(); iterator.hasNext();) { - System.out.println("Xsd Compilation Errors : " + iterator.next()); - } - if (!errors.isEmpty()) { - fail("Errors found when compiling schema"); - } + assertTrue(options.getErrorListener().isEmpty(), "Errors found when compiling schema"); } } Modified: xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/ElementOnlyContentTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/ElementOnlyContentTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/ElementOnlyContentTest.java (original) +++ xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/ElementOnlyContentTest.java Sun Feb 6 01:51:55 2022 @@ -18,63 +18,54 @@ package scomp.contentType.complex.detail import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlErrorCodes; import org.apache.xmlbeans.XmlInteger; -import org.junit.Test; -import scomp.common.BaseCase; +import org.apache.xmlbeans.XmlOptions; +import org.junit.jupiter.api.Test; import xbean.scomp.contentType.complexTypeTest.ElementT; import xbean.scomp.contentType.complexTypeTest.EltTypeDocument; import java.math.BigInteger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; +import static scomp.common.BaseCase.getErrorCodes; -public class ElementOnlyContentTest extends BaseCase { +public class ElementOnlyContentTest { /** * Element only content */ @Test - public void testElementOnly() throws Throwable { + void testElementOnly() throws Throwable { EltTypeDocument doc = EltTypeDocument.Factory.newInstance(); ElementT testElt = doc.getEltType(); - assertEquals(null, testElt); + assertNull(testElt); testElt = doc.addNewEltType(); - assertEquals(null, testElt.getChild1()); - assertEquals(null, testElt.xgetChild1()); + assertNull(testElt.getChild1()); + assertNull(testElt.xgetChild1()); testElt.setChild1(new BigInteger("10")); testElt.setChild2(new BigInteger("5")); testElt.setChild3(new BigInteger("1")); assertEquals("<xml-fragment><child1>10</child1><child2>5</child2>" + - "<child3>1</child3></xml-fragment>", - testElt.xmlText()); + "<child3>1</child3></xml-fragment>", testElt.xmlText()); - testElt.xsetChild2( - XmlInteger.Factory.parse("<xml-fragment>3</xml-fragment>")); + testElt.xsetChild2(XmlInteger.Factory.parse("<xml-fragment>3</xml-fragment>")); assertEquals("<xml-fragment><child1>10</child1><child2>3</child2>" + - "<child3>1</child3></xml-fragment>", - testElt.xmlText()); - try { - assertTrue(doc.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + "<child3>1</child3></xml-fragment>", testElt.xmlText()); + assertTrue(doc.validate(createOptions())); } /** * Mixed content is invalid for element only types */ @Test - public void testInvalidContent() { + void testInvalidContent() { EltTypeDocument doc = EltTypeDocument.Factory.newInstance(); - ElementT testElt - = doc.getEltType(); - assertEquals(null, testElt); + ElementT testElt = doc.getEltType(); + assertNull(testElt); testElt = doc.addNewEltType(); - assertEquals(null, testElt.getChild1()); - assertEquals(null, testElt.xgetChild1()); + assertNull(testElt.getChild1()); + assertNull(testElt.xgetChild1()); testElt.setChild1(new BigInteger("10")); testElt.setChild2(new BigInteger("5")); testElt.setChild3(new BigInteger("1")); @@ -83,13 +74,10 @@ public class ElementOnlyContentTest exte cur.toFirstContentToken(); cur.insertChars("Random mixed content"); } - System.out.println(testElt.xmlText()); - assertTrue(!testElt.validate(validateOptions)); - showErrors(); - String[] errExpected = new String[]{ - XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$ELEMENT_ONLY_WITH_TEXT}; - assertTrue(compareErrorCodes(errExpected)); - + XmlOptions validateOptions = createOptions(); + assertFalse(testElt.validate(validateOptions)); + String[] errExpected = {XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$ELEMENT_ONLY_WITH_TEXT}; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } } Modified: xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/EmptyContentTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/EmptyContentTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/EmptyContentTest.java (original) +++ xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/EmptyContentTest.java Sun Feb 6 01:51:55 2022 @@ -12,60 +12,58 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package scomp.contentType.complex.detailed; +package scomp.contentType.complex.detailed; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlErrorCodes; +import org.apache.xmlbeans.XmlOptions; import org.apache.xmlbeans.XmlString; -import org.junit.Test; -import scomp.common.BaseCase; +import org.junit.jupiter.api.Test; import xbean.scomp.contentType.complexTypeTest.EmptyT; import xbean.scomp.contentType.complexTypeTest.EmptyTypeDocument; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; +import static scomp.common.BaseCase.getErrorCodes; -public class EmptyContentTest extends BaseCase { +public class EmptyContentTest { @Test - public void testIllegalContent() { + void testIllegalContent() { EmptyTypeDocument doc = EmptyTypeDocument.Factory.newInstance(); EmptyT elt = doc.addNewEmptyType(); - assertTrue(!elt.isSetEmptyAttr()); + assertFalse(elt.isSetEmptyAttr()); elt.setEmptyAttr("foobar"); assertTrue(elt.validate()); try (XmlCursor cur = elt.newCursor()) { cur.toFirstContentToken(); cur.beginElement("foobarElt"); } - assertTrue(!elt.validate(validateOptions)); - showErrors(); - String[] errExpected = new String[]{ - XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$ELEMENT_NOT_ALLOWED - }; - assertTrue(compareErrorCodes(errExpected)); - + XmlOptions validateOptions = createOptions(); + assertFalse(elt.validate(validateOptions)); + String[] errExpected = {XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$ELEMENT_NOT_ALLOWED}; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } @Test - public void testLegalContent() { + void testLegalContent() { EmptyTypeDocument doc = EmptyTypeDocument.Factory.newInstance(); EmptyT elt = doc.addNewEmptyType(); - assertTrue(!elt.isSetEmptyAttr()); + assertFalse(elt.isSetEmptyAttr()); elt.setEmptyAttr("foobar"); assertTrue(elt.isSetEmptyAttr()); assertEquals("foobar", elt.getEmptyAttr()); - XmlString expected=XmlString.Factory.newInstance(); + XmlString expected = XmlString.Factory.newInstance(); expected.setStringValue("foobar"); - XmlString expected1=XmlString.Factory.newInstance(); + XmlString expected1 = XmlString.Factory.newInstance(); expected1.setStringValue("foobar"); - System.out.println( expected.equals(expected1)); - assertTrue( expected.valueEquals(elt.xgetEmptyAttr()) ); + assertEquals(expected.xmlText(), expected1.xmlText()); + assertTrue(expected.valueEquals(elt.xgetEmptyAttr())); elt.unsetEmptyAttr(); - assertTrue(!elt.isSetEmptyAttr()); + assertFalse(elt.isSetEmptyAttr()); assertTrue(elt.validate()); } } Modified: xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/MixedContentTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/MixedContentTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/MixedContentTest.java (original) +++ xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/MixedContentTest.java Sun Feb 6 01:51:55 2022 @@ -14,91 +14,70 @@ */ package scomp.contentType.complex.detailed; -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlErrorCodes; -import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.XmlInteger; -import org.junit.Before; -import org.junit.Test; -import scomp.common.BaseCase; +import org.apache.xmlbeans.*; +import org.junit.jupiter.api.Test; import xbean.scomp.contentType.complexTypeTest.MixedFixedEltDocument; import xbean.scomp.contentType.complexTypeTest.MixedT; import xbean.scomp.contentType.complexTypeTest.MixedTypeDocument; import java.math.BigInteger; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; +import static scomp.common.BaseCase.getErrorCodes; -public class MixedContentTest extends BaseCase { +public class MixedContentTest { @Test - public void testElementsOnly() throws Throwable { - - testElt = doc.addNewMixedType(); + void testElementsOnly() throws Throwable { + MixedTypeDocument doc = MixedTypeDocument.Factory.newInstance(); + MixedT testElt = doc.addNewMixedType(); assertNull(testElt.getChild1()); assertNull(testElt.xgetChild1()); testElt.setChild2(new BigInteger("5")); testElt.setChild3(new BigInteger("1")); testElt.setChild1(new BigInteger("0")); assertEquals("<xml-fragment><child1>0</child1><child2>5</child2>" + - "<child3>1</child3></xml-fragment>", - testElt.xmlText()); + "<child3>1</child3></xml-fragment>", testElt.xmlText()); testElt.xsetChild2( - XmlInteger.Factory.parse("<xml-fragment>3</xml-fragment>")); + XmlInteger.Factory.parse("<xml-fragment>3</xml-fragment>")); assertEquals("<xml-fragment><child1>0</child1><child2>3</child2>" + - "<child3>1</child3></xml-fragment>", - testElt.xmlText()); - try { - assertTrue(testElt.validate(validateOptions)); - } - catch (Throwable t) { - showErrors(); - throw t; - } + "<child3>1</child3></xml-fragment>", testElt.xmlText()); + assertTrue(testElt.validate(createOptions())); } /** * Note that the mixed model in XML Schema differs fundamentally from the * mixed model in XML 1.0. Under the XML Schema mixed model, the order and - * number of child elements appearing in an instance must agree with the + * number of child elements appearing in an instance must agree with the * order and number of child elements specified in the model */ @Test - public void testTextOnly() { - - testElt = doc.addNewMixedType(); + void testTextOnly() { + MixedTypeDocument doc = MixedTypeDocument.Factory.newInstance(); + MixedT testElt = doc.addNewMixedType(); assertNull(testElt.getChild1()); assertNull(testElt.xgetChild1()); try (XmlCursor cur = testElt.newCursor()) { cur.insertChars("Random mixed content"); } - assertTrue( !testElt.validate(validateOptions) ); - showErrors(); - String[] errExpected = new String[]{ - XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_ELEMENT - }; - assertTrue(compareErrorCodes(errExpected)); - - + XmlOptions validateOptions = createOptions(); + assertFalse(testElt.validate(validateOptions)); + String[] errExpected = {XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_ELEMENT}; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } @Test - public void testMixed() throws Throwable { - testElt = doc.addNewMixedType(); + void testMixed() { + MixedTypeDocument doc = MixedTypeDocument.Factory.newInstance(); + MixedT testElt = doc.addNewMixedType(); assertNull(testElt.getChild1()); assertNull(testElt.xgetChild1()); testElt.setChild2(new BigInteger("5")); testElt.setChild3(new BigInteger("1")); testElt.setChild1(new BigInteger("0")); - try { - assertTrue(testElt.validate()); - } - catch (Throwable t) { - testElt.validate(validateOptions); - showErrors(); - throw t; - } + assertTrue(testElt.validate()); try (XmlCursor cur = testElt.newCursor()) { cur.toFirstContentToken(); cur.insertChars("Random mixed content"); @@ -110,19 +89,15 @@ public class MixedContentTest extends Ba assertTrue(testElt.validate()); } - catch (Throwable t) { - testElt.validate(validateOptions); - showErrors(); - throw t; - } assertEquals("<xml-fragment>Random mixed content" + - "<child1>0</child1>Random mixed content1<child2>5</child2>" + - "<child3>1</child3></xml-fragment>",testElt.xmlText() ); + "<child1>0</child1>Random mixed content1<child2>5</child2>" + + "<child3>1</child3></xml-fragment>", testElt.xmlText()); } @Test - public void testInsertDelete() throws Throwable{ - testElt = doc.addNewMixedType(); + void testInsertDelete() { + MixedTypeDocument doc = MixedTypeDocument.Factory.newInstance(); + MixedT testElt = doc.addNewMixedType(); testElt.setChild2(new BigInteger("5")); testElt.setChild3(new BigInteger("1")); testElt.setChild1(new BigInteger("0")); @@ -134,10 +109,10 @@ public class MixedContentTest extends Ba cur.toNextToken(); cur.toNextToken(); cur.insertChars("Random mixed content1"); - assertTrue(testElt.validate(validateOptions)); + assertTrue(testElt.validate(createOptions())); assertEquals("<xml-fragment>Random mixed content" + - "<child1>0</child1>Random mixed content1<child2>5</child2>" + - "<child3>1</child3></xml-fragment>",testElt.xmlText() ); + "<child1>0</child1>Random mixed content1<child2>5</child2>" + + "<child3>1</child3></xml-fragment>", testElt.xmlText()); //to child1 cur.toPrevToken(); cur.toPrevToken(); @@ -145,14 +120,11 @@ public class MixedContentTest extends Ba cur.toPrevToken(); assertEquals(XmlCursor.TokenType.START, cur.currentTokenType()); assertTrue(cur.removeXml()); - assertEquals(null,testElt.getChild1()); + assertNull(testElt.getChild1()); assertEquals("<xml-fragment>Random mixed content" + - "Random mixed content1<child2>5</child2>" + - "<child3>1</child3></xml-fragment>",testElt.xmlText() ); - } catch (Throwable t) { - showErrors(); - throw t; + "Random mixed content1<child2>5</child2>" + + "<child3>1</child3></xml-fragment>", testElt.xmlText()); } } @@ -164,30 +136,17 @@ public class MixedContentTest extends Ba * if there is a fixed value constraint, the element may not have element children. */ @Test - public void testMixedFixed() throws XmlException{ - MixedFixedEltDocument doc= - MixedFixedEltDocument.Factory - .parse("<pre:MixedFixedElt " + - " xmlns:pre=\"http://xbean/scomp/contentType/ComplexTypeTest\">" + - "<a/>abc</pre:MixedFixedElt>"); - - assertTrue (! doc.validate(validateOptions)); - showErrors(); - String[] expected=new String[] - {XmlErrorCodes.ELEM_LOCALLY_VALID$FIXED_WITH_CONTENT}; - assertTrue(compareErrorCodes(expected)); - + void testMixedFixed() throws XmlException { + String input = + "<pre:MixedFixedElt " + + " xmlns:pre=\"http://xbean/scomp/contentType/ComplexTypeTest\">" + + "<a/>abc</pre:MixedFixedElt>"; + + MixedFixedEltDocument doc = MixedFixedEltDocument.Factory.parse(input); + XmlOptions validateOptions = createOptions(); + assertFalse(doc.validate(validateOptions)); + String[] expected = {XmlErrorCodes.ELEM_LOCALLY_VALID$FIXED_WITH_CONTENT}; + assertArrayEquals(expected, getErrorCodes(validateOptions)); } - @Before - public void setUp() { - doc = MixedTypeDocument.Factory.newInstance(); - testElt = doc.getMixedType(); - assertNull(testElt); - super.setUp(); - } - - private MixedTypeDocument doc; - private MixedT testElt; - } Modified: xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/NamedTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/NamedTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/NamedTest.java (original) +++ xmlbeans/trunk/src/test/java/scomp/contentType/complex/detailed/NamedTest.java Sun Feb 6 01:51:55 2022 @@ -16,8 +16,7 @@ package scomp.contentType.complex.detail import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlInteger; -import org.junit.Test; -import scomp.common.BaseCase; +import org.junit.jupiter.api.Test; import xbean.scomp.contentType.named.ElementT; import xbean.scomp.contentType.named.MixedT; import xbean.scomp.contentType.named.NamedEltDocument; @@ -25,12 +24,13 @@ import xbean.scomp.contentType.named.Nam import java.math.BigInteger; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; -public class NamedTest extends BaseCase { +public class NamedTest { @Test - public void testSimpleAnonymous() throws Throwable { + void testSimpleAnonymous() throws Throwable { NamedEltDocument doc = NamedEltDocument.Factory.newInstance(); ElementT testElt = doc.getNamedElt(); assertNull(testElt); @@ -40,25 +40,17 @@ public class NamedTest extends BaseCase testElt.setChild2(new BigInteger("5")); testElt.setChild3(new BigInteger("1")); assertEquals("<xml-fragment><child2>5</child2>" + - "<child3>1</child3></xml-fragment>", - testElt.xmlText()); + "<child3>1</child3></xml-fragment>", testElt.xmlText()); testElt.setChild1(BigInteger.ONE); testElt.xsetChild2(XmlInteger.Factory.parse("<xml-fragment>3</xml-fragment>")); assertEquals("<xml-fragment><child1>1</child1><child2>3</child2>" + - "<child3>1</child3></xml-fragment>", - testElt.xmlText()); - try { - assertTrue(testElt.validate(validateOptions)); - } catch (Throwable t) { - showErrors(); - throw t; - } + "<child3>1</child3></xml-fragment>", testElt.xmlText()); + assertTrue(testElt.validate(createOptions())); } @Test - public void testMixedAnonymous() throws Throwable { - NamedMixedEltDocument doc = - NamedMixedEltDocument.Factory.newInstance(); + void testMixedAnonymous() throws Throwable { + NamedMixedEltDocument doc = NamedMixedEltDocument.Factory.newInstance(); MixedT testElt = doc.getNamedMixedElt(); assertNull(testElt); @@ -77,23 +69,16 @@ public class NamedTest extends BaseCase } testElt.setChild3(new BigInteger("1")); assertEquals("<xml-fragment>Random mixed content" + - "<child2>5</child2><child3>1</child3></xml-fragment>", - testElt.xmlText()); + "<child2>5</child2><child3>1</child3></xml-fragment>", testElt.xmlText()); testElt.xsetChild2(XmlInteger.Factory.parse("<xml-fragment>3</xml-fragment>")); assertEquals("<xml-fragment>" + - "Random mixed content" + - "<child2>3</child2>" + - "<child3>1</child3>" + - "</xml-fragment>", - testElt.xmlText()); + "Random mixed content" + + "<child2>3</child2>" + + "<child3>1</child3>" + + "</xml-fragment>", testElt.xmlText()); testElt.xsetChild1(XmlInteger.Factory.parse("<xml-fragment>0</xml-fragment>")); - try { - assertTrue(testElt.validate(validateOptions)); - } catch (Throwable t) { - showErrors(); - throw t; - } + assertTrue(testElt.validate(createOptions())); } } Modified: xmlbeans/trunk/src/test/java/scomp/contentType/complex/modelGroup/detailed/AllTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/contentType/complex/modelGroup/detailed/AllTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/contentType/complex/modelGroup/detailed/AllTest.java (original) +++ xmlbeans/trunk/src/test/java/scomp/contentType/complex/modelGroup/detailed/AllTest.java Sun Feb 6 01:51:55 2022 @@ -17,54 +17,56 @@ package scomp.contentType.complex.modelG import org.apache.xmlbeans.XmlErrorCodes; import org.apache.xmlbeans.XmlException; -import org.junit.Test; -import scomp.common.BaseCase; +import org.apache.xmlbeans.XmlOptions; +import org.junit.jupiter.api.Test; import xbean.scomp.contentType.modelGroup.AllEltDocument; import xbean.scomp.contentType.modelGroup.AllT; import java.math.BigInteger; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; +import static scomp.common.BaseCase.getErrorCodes; -public class AllTest extends BaseCase { +public class AllTest { /** * Instance should be valid w/ child1 missing */ @Test - public void testChild1Optional() { - doc = AllEltDocument.Factory.newInstance(); + void testChild1Optional() { + AllEltDocument doc = AllEltDocument.Factory.newInstance(); AllT elt = doc.addNewAllElt(); elt.setChild2("doo"); elt.setChild3(BigInteger.ONE); - assertTrue(doc.validate(validateOptions)); + assertTrue(doc.validate(createOptions())); } /** * All group doesn't care about field order */ @Test - public void testOrder() throws XmlException { + void testOrder() throws XmlException { String input = "<pre:AllElt xmlns:pre=\"http://xbean/scomp/contentType/ModelGroup\">" + "<child3>5</child3><child1>2</child1><child2>bar</child2>" + "</pre:AllElt>"; - doc = AllEltDocument.Factory.parse(input); - assertTrue(doc.validate(validateOptions)); + AllEltDocument doc = AllEltDocument.Factory.parse(input); + assertTrue(doc.validate(createOptions())); } /** * maxOccurs is always 1 */ @Test - public void testIllegal() throws XmlException { + void testIllegal() throws XmlException { String input = "<pre:AllElt xmlns:pre=\"http://xbean/scomp/contentType/ModelGroup\">" + "<child3>5</child3><child3>2</child3><child2>bar</child2>" + "</pre:AllElt>"; - doc = AllEltDocument.Factory.parse(input); - assertTrue(!doc.validate(validateOptions)); - showErrors(); + AllEltDocument doc = AllEltDocument.Factory.parse(input); + XmlOptions validateOptions = createOptions(); + assertFalse(doc.validate(validateOptions)); //$TODO: QUESTIONABLE ERRORS: if <child3>2</child3> is replaced by <child1>2</child1> //all will be good: why 2 errors? String[] errExpected = { @@ -72,10 +74,6 @@ public class AllTest extends BaseCase { // XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$ELEMENT_NOT_ALLOWED, // XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$EXPECTED_ELEMENT }; - assertTrue(compareErrorCodes(errExpected)); - + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } - - - private AllEltDocument doc; } Modified: xmlbeans/trunk/src/test/java/scomp/contentType/complex/modelGroup/detailed/ChoiceTest.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/scomp/contentType/complex/modelGroup/detailed/ChoiceTest.java?rev=1897795&r1=1897794&r2=1897795&view=diff ============================================================================== --- xmlbeans/trunk/src/test/java/scomp/contentType/complex/modelGroup/detailed/ChoiceTest.java (original) +++ xmlbeans/trunk/src/test/java/scomp/contentType/complex/modelGroup/detailed/ChoiceTest.java Sun Feb 6 01:51:55 2022 @@ -17,8 +17,8 @@ package scomp.contentType.complex.modelG import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlErrorCodes; -import org.junit.Test; -import scomp.common.BaseCase; +import org.apache.xmlbeans.XmlOptions; +import org.junit.jupiter.api.Test; import xbean.scomp.contentType.modelGroup.ChoiceEltDocument; import xbean.scomp.contentType.modelGroup.ChoiceT; import xbean.scomp.contentType.modelGroup.MixedChoiceEltDocument; @@ -26,48 +26,43 @@ import xbean.scomp.contentType.modelGrou import java.math.BigInteger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; +import static scomp.common.BaseCase.createOptions; +import static scomp.common.BaseCase.getErrorCodes; //TODO: assert that order of elements in a choice group doesn't matter -public class ChoiceTest extends BaseCase { +public class ChoiceTest { @Test - public void testValidCase() throws Throwable { + void testValidCase() throws Throwable { ChoiceEltDocument doc = ChoiceEltDocument.Factory.newInstance(); ChoiceT elt = doc.addNewChoiceElt(); elt.addChild3(new BigInteger("10")); elt.addChild3(BigInteger.ZERO); - try { - assertTrue(doc.validate(validateOptions)); - } catch (Throwable t) { - showErrors(); - throw t; - } + assertTrue(doc.validate(createOptions())); } //more than 1 from choice group //TODO: test should pass but error message not good @Test - public void testChoiceViolation() throws Throwable { + void testChoiceViolation() throws Throwable { ChoiceEltDocument doc = ChoiceEltDocument.Factory.newInstance(); ChoiceT elt = doc.addNewChoiceElt(); elt.addChild2("foobar"); elt.addChild3(new BigInteger("10")); elt.addChild3(BigInteger.ZERO); - assertTrue(!doc.validate(validateOptions)); - showErrors(); - String[] errExpected = new String[]{ - XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$ELEMENT_NOT_ALLOWED - }; - assertTrue(compareErrorCodes(errExpected)); + XmlOptions validateOptions = createOptions(); + assertFalse(doc.validate(validateOptions)); + String[] errExpected = {XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$ELEMENT_NOT_ALLOWED}; + assertArrayEquals(errExpected, getErrorCodes(validateOptions)); } - public void testMixedChoice() throws Throwable { + @Test + void testMixedChoice() throws Throwable { MixedChoiceEltDocument doc = MixedChoiceEltDocument.Factory.newInstance(); MixedChoiceT elt = doc.addNewMixedChoiceElt(); - assertTrue(!elt.isSetChild1()); + assertFalse(elt.isSetChild1()); elt.setChild1(new BigInteger("10")); try (XmlCursor cur = elt.newCursor()) { assertEquals(XmlCursor.TokenType.START, cur.toFirstContentToken()); @@ -75,10 +70,7 @@ public class ChoiceTest extends BaseCase cur.toNextToken(); cur.insertChars("foobar"); - assertTrue(doc.validate(validateOptions)); - } catch (Throwable t) { - showErrors(); - throw t; + assertTrue(doc.validate(createOptions())); } assertEquals("<xml-fragment><child1>10</child1>foobar</xml-fragment>", elt.xmlText()); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
