1 package org.apache.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
23 import java.util.ArrayList;
24 import java.util.List;
26 import org.dom4j.Element;
33 public class XMLReaderTest
34 extends AbstractArchivaXmlTestCase
36 private void assertElementTexts( List<Element> elementList, String[] expectedTexts )
38 assertEquals( "Element List Size", expectedTexts.length, elementList.size() );
40 List<String> texts = new ArrayList<String>();
41 for ( Element element : elementList )
43 texts.add( element.getTextTrim() );
46 for ( int i = 0; i < expectedTexts.length; i++ )
48 String expectedText = expectedTexts[i];
49 assertTrue( "Contains [" + expectedText + "]", texts.contains( expectedText ) );
53 public void testNoPrologBasicRead()
56 File xmlFile = getExampleXml( "no-prolog-basic.xml" );
57 XMLReader reader = new XMLReader( "basic", xmlFile );
59 List<Element> fruits = reader.getElementList( "//basic/fruits/fruit" );
60 assertElementTexts( fruits, new String[] { "apple", "cherry", "pear", "peach" } );
63 public void testNoPrologEntitiesRead()
66 File xmlFile = getExampleXml( "no-prolog-with-entities.xml" );
67 XMLReader reader = new XMLReader( "basic", xmlFile );
69 List<Element> names = reader.getElementList( "//basic/names/name" );
70 assertElementTexts( names, new String[] { TRYGVIS, INFINITE_ARCHIVA } );
73 public void testNoPrologUtf8Read()
76 File xmlFile = getExampleXml( "no-prolog-with-utf8.xml" );
77 XMLReader reader = new XMLReader( "basic", xmlFile );
79 List<Element> names = reader.getElementList( "//basic/names/name" );
80 assertElementTexts( names, new String[] { TRYGVIS, INFINITE_ARCHIVA } );
83 public void testPrologUtf8Read()
86 File xmlFile = getExampleXml( "prolog-with-utf8.xml" );
87 XMLReader reader = new XMLReader( "basic", xmlFile );
89 List<Element> names = reader.getElementList( "//basic/names/name" );
90 assertElementTexts( names, new String[] { TRYGVIS, INFINITE_ARCHIVA } );
94 public void testProxiedMetadataRead()
97 File xmlFile = getExampleXml( "maven-metadata-codehaus-snapshots.xml" );
98 XMLReader reader = new XMLReader( "metadata", xmlFile );
99 reader.removeNamespaces();
101 Element groupId = reader.getElement( "//metadata/groupId" );
102 assertNotNull( groupId );
103 assertEquals( "org.codehaus.mojo", groupId.getTextTrim() );