Author: veithen Date: Tue Sep 28 09:28:40 2010 New Revision: 1002071 URL: http://svn.apache.org/viewvc?rev=1002071&view=rev Log: Added dialect tests for the hasName and hasText methods.
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/BooleanPropertyTestCase.java (with props) webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/EventSpecificTestCase.java (with props) webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/HasNameTestCase.java (with props) webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/HasTextTestCase.java (with props) Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/IllegalStateExceptionTestCase.java Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/BooleanPropertyTestCase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/BooleanPropertyTestCase.java?rev=1002071&view=auto ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/BooleanPropertyTestCase.java (added) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/BooleanPropertyTestCase.java Tue Sep 28 09:28:40 2010 @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.axiom.util.stax.dialect; + +import javax.xml.stream.XMLStreamReader; + +public abstract class BooleanPropertyTestCase extends EventSpecificTestCase { + private final boolean expected; + + public BooleanPropertyTestCase(int event, boolean expected) { + super(event); + this.expected = expected; + } + + protected void runTest(XMLStreamReader reader) throws Throwable { + assertEquals(expected, invoke(reader)); + } + + protected abstract boolean invoke(XMLStreamReader reader); +} Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/BooleanPropertyTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java?rev=1002071&r1=1002070&r2=1002071&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java Tue Sep 28 09:28:40 2010 @@ -101,6 +101,32 @@ public class DialectTest extends TestSui addDialectTest(new GetPrefixWithNoPrefixTestCase()); addDialectTest(new GetTextInPrologTestCase()); addDialectTest(new GetVersionTestCase()); + addDialectTest(new HasNameTestCase(XMLStreamConstants.START_ELEMENT, true)); + addDialectTest(new HasNameTestCase(XMLStreamConstants.END_ELEMENT, true)); + addDialectTest(new HasNameTestCase(XMLStreamConstants.PROCESSING_INSTRUCTION, false)); + addDialectTest(new HasNameTestCase(XMLStreamConstants.CHARACTERS, false)); + addDialectTest(new HasNameTestCase(XMLStreamConstants.COMMENT, false)); + addDialectTest(new HasNameTestCase(XMLStreamConstants.SPACE, false)); + addDialectTest(new HasNameTestCase(XMLStreamConstants.START_DOCUMENT, false)); + addDialectTest(new HasNameTestCase(XMLStreamConstants.END_DOCUMENT, false)); + addDialectTest(new HasNameTestCase(XMLStreamConstants.ENTITY_REFERENCE, false)); + addDialectTest(new HasNameTestCase(XMLStreamConstants.DTD, false)); + addDialectTest(new HasNameTestCase(XMLStreamConstants.CDATA, false)); + addDialectTest(new HasTextTestCase(XMLStreamConstants.START_ELEMENT, false)); + addDialectTest(new HasTextTestCase(XMLStreamConstants.END_ELEMENT, false)); + addDialectTest(new HasTextTestCase(XMLStreamConstants.PROCESSING_INSTRUCTION, false)); + addDialectTest(new HasTextTestCase(XMLStreamConstants.CHARACTERS, true)); + addDialectTest(new HasTextTestCase(XMLStreamConstants.COMMENT, true)); + addDialectTest(new HasTextTestCase(XMLStreamConstants.SPACE, true)); + addDialectTest(new HasTextTestCase(XMLStreamConstants.START_DOCUMENT, false)); + addDialectTest(new HasTextTestCase(XMLStreamConstants.END_DOCUMENT, false)); + addDialectTest(new HasTextTestCase(XMLStreamConstants.ENTITY_REFERENCE, true)); + addDialectTest(new HasTextTestCase(XMLStreamConstants.DTD, true)); + // Note: CDATA events are actually not mentioned in the Javadoc of XMLStreamReader#hasText(). + // This is because reporting CDATA sections as CDATA events is an implementation + // specific feature. Nevertheless, for obvious reasons, we expect hasText to + // return true in this case. + addDialectTest(new HasTextTestCase(XMLStreamConstants.CDATA, true)); addDialectTest(new IsCharactersOnCDATASectionTestCase()); addDialectTest(new IsStandaloneTestCase()); addDialectTest(new MaskedNamespaceTestCase()); Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/EventSpecificTestCase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/EventSpecificTestCase.java?rev=1002071&view=auto ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/EventSpecificTestCase.java (added) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/EventSpecificTestCase.java Tue Sep 28 09:28:40 2010 @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.axiom.util.stax.dialect; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.util.stax.XMLEventUtils; + +/** + * Base class for test cases that test the behavior of a {...@link XMLStreamReader} method for specific + * event types. It is able to produce a reader that is positioned on an event with a predefined + * type. + */ +public abstract class EventSpecificTestCase extends DialectTestCase { + private final int event; + + public EventSpecificTestCase(int event) { + this.event = event; + setName(getClass().getName() + " [" + XMLEventUtils.getEventTypeString(event) + "]"); + } + + protected final void runTest() throws Throwable { + XMLInputFactory factory = getDialect().enableCDataReporting(newNormalizedXMLInputFactory()); + factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); + InputStream in = IllegalStateExceptionTestCase.class.getResourceAsStream("alleventtypes.xml"); + try { + XMLStreamReader reader = factory.createXMLStreamReader(in); + while (true) { + if (reader.getEventType() == event) { + break; + } else if (reader.hasNext()) { + reader.next(); + } else { + fail("Internal error: didn't encounter event " + event); + } + } + runTest(reader); + } finally { + in.close(); + } + } + + protected abstract void runTest(XMLStreamReader reader) throws Throwable; +} Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/EventSpecificTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/HasNameTestCase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/HasNameTestCase.java?rev=1002071&view=auto ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/HasNameTestCase.java (added) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/HasNameTestCase.java Tue Sep 28 09:28:40 2010 @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.axiom.util.stax.dialect; + +import javax.xml.stream.XMLStreamReader; + +public class HasNameTestCase extends BooleanPropertyTestCase { + public HasNameTestCase(int event, boolean expected) { + super(event, expected); + } + + protected boolean invoke(XMLStreamReader reader) { + return reader.hasName(); + } +} Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/HasNameTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/HasTextTestCase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/HasTextTestCase.java?rev=1002071&view=auto ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/HasTextTestCase.java (added) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/HasTextTestCase.java Tue Sep 28 09:28:40 2010 @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.axiom.util.stax.dialect; + +import javax.xml.stream.XMLStreamReader; + +public class HasTextTestCase extends BooleanPropertyTestCase { + public HasTextTestCase(int event, boolean expected) { + super(event, expected); + } + + protected boolean invoke(XMLStreamReader reader) { + return reader.hasText(); + } +} Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/HasTextTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/IllegalStateExceptionTestCase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/IllegalStateExceptionTestCase.java?rev=1002071&r1=1002070&r2=1002071&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/IllegalStateExceptionTestCase.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/IllegalStateExceptionTestCase.java Tue Sep 28 09:28:40 2010 @@ -18,53 +18,29 @@ */ package org.apache.axiom.util.stax.dialect; -import java.io.InputStream; - -import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; -import org.apache.axiom.util.stax.XMLEventUtils; - -public abstract class IllegalStateExceptionTestCase extends DialectTestCase { - private final int event; +public abstract class IllegalStateExceptionTestCase extends EventSpecificTestCase { private final boolean expectException; public IllegalStateExceptionTestCase(int event, boolean expectException) { - this.event = event; + super(event); this.expectException = expectException; - setName(getClass().getName() + " [" + XMLEventUtils.getEventTypeString(event) + "]"); } - protected final void runTest() throws Throwable { - XMLInputFactory factory = getDialect().enableCDataReporting(newNormalizedXMLInputFactory()); - factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); - InputStream in = IllegalStateExceptionTestCase.class.getResourceAsStream("alleventtypes.xml"); + protected final void runTest(XMLStreamReader reader) throws Throwable { + boolean exception; try { - XMLStreamReader reader = factory.createXMLStreamReader(in); - while (true) { - if (reader.getEventType() == event) { - break; - } else if (reader.hasNext()) { - reader.next(); - } else { - fail("Internal error: didn't encounter event " + event); - } - } - boolean exception; - try { - invoke(reader); - exception = false; - } catch (IllegalStateException ex) { - exception = true; - } - if (exception && !expectException) { - fail("Didn't expect IllegalStateException"); - } else if (!exception && expectException) { - fail("Expected IllegalStateException"); - } - } finally { - in.close(); + invoke(reader); + exception = false; + } catch (IllegalStateException ex) { + exception = true; + } + if (exception && !expectException) { + fail("Didn't expect IllegalStateException"); + } else if (!exception && expectException) { + fail("Expected IllegalStateException"); } }