01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.databinding.utils;
20:
21: import junit.framework.TestCase;
22: import org.apache.axiom.om.util.StAXUtils;
23:
24: import javax.xml.namespace.QName;
25: import javax.xml.stream.XMLStreamException;
26: import javax.xml.stream.XMLStreamReader;
27: import java.io.StringReader;
28:
29: public class SimpleElementReaderStateMachineTest extends TestCase {
30:
31: public void testStateMachine() throws Exception {
32: String xmlDoc = "<myIntVal>200</myIntVal>";
33: XMLStreamReader reader = StAXUtils
34: .createXMLStreamReader(new StringReader(xmlDoc));
35: SimpleElementReaderStateMachine sm = new SimpleElementReaderStateMachine();
36: sm.setElementNameToTest(new QName("myIntVal"));
37: try {
38: sm.read(reader);
39: } catch (XMLStreamException e) {
40: e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
41: }
42:
43: assertEquals("200", sm.getText());
44: }
45:
46: public void testStateMachine2() throws Exception {
47: String xmlDoc = "<wrapper><myIntVal>200</myIntVal></wrapper>";
48: XMLStreamReader reader = StAXUtils
49: .createXMLStreamReader(new StringReader(xmlDoc));
50: SimpleElementReaderStateMachine sm = new SimpleElementReaderStateMachine();
51: sm.setElementNameToTest(new QName("myIntVal"));
52: try {
53: sm.read(reader);
54: } catch (XMLStreamException e) {
55: e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
56: }
57:
58: assertEquals("200", sm.getText());
59: }
60:
61: public void testStateMachine3() throws Exception {
62: String xmlDoc = "<myIntVal>200<a/></myIntVal>";
63: XMLStreamReader reader = StAXUtils
64: .createXMLStreamReader(new StringReader(xmlDoc));
65: SimpleElementReaderStateMachine sm = new SimpleElementReaderStateMachine();
66: sm.setElementNameToTest(new QName("myIntVal"));
67: try {
68: sm.read(reader);
69: fail();
70: } catch (Exception e) {
71:
72: }
73:
74: }
75:
76: }
|