1 package org.apache.maven.archiva.xml;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.dom4j.Element;
25 import java.util.ArrayList;
26 import java.util.Iterator;
27 import java.util.List;
34 public class XMLReaderTest
35 extends AbstractArchivaXmlTestCase
37 private void assertElementTexts( List elementList, String[] expectedTexts )
39 assertEquals( "Element List Size", expectedTexts.length, elementList.size() );
41 List texts = new ArrayList();
42 for ( Iterator iter = elementList.iterator(); iter.hasNext(); )
44 Element element = (Element) iter.next();
45 texts.add( element.getTextTrim() );
48 for ( int i = 0; i < expectedTexts.length; i++ )
50 String expectedText = expectedTexts[i];
51 assertTrue( "Contains [" + expectedText + "]", texts.contains( expectedText ) );
55 public void testNoPrologBasicRead()
58 File xmlFile = getExampleXml( "no-prolog-basic.xml" );
59 XMLReader reader = new XMLReader( "basic", xmlFile );
61 List fruits = reader.getElementList( "//basic/fruits/fruit" );
62 assertElementTexts( fruits, new String[] { "apple", "cherry", "pear", "peach" } );
65 public void testNoPrologEntitiesRead()
68 File xmlFile = getExampleXml( "no-prolog-with-entities.xml" );
69 XMLReader reader = new XMLReader( "basic", xmlFile );
71 List names = reader.getElementList( "//basic/names/name" );
72 assertElementTexts( names, new String[] { TRYGVIS, INFINITE_ARCHIVA } );
75 public void testNoPrologUtf8Read()
78 File xmlFile = getExampleXml( "no-prolog-with-utf8.xml" );
79 XMLReader reader = new XMLReader( "basic", xmlFile );
81 List names = reader.getElementList( "//basic/names/name" );
82 assertElementTexts( names, new String[] { TRYGVIS, INFINITE_ARCHIVA } );
85 public void testPrologUtf8Read()
88 File xmlFile = getExampleXml( "prolog-with-utf8.xml" );
89 XMLReader reader = new XMLReader( "basic", xmlFile );
91 List names = reader.getElementList( "//basic/names/name" );
92 assertElementTexts( names, new String[] { TRYGVIS, INFINITE_ARCHIVA } );