1 package org.apache.maven.archiva.common.spring;
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
24 import javax.xml.parsers.DocumentBuilder;
25 import javax.xml.parsers.DocumentBuilderFactory;
27 import junit.framework.TestCase;
29 import org.dom4j.io.DOMReader;
30 import org.dom4j.io.OutputFormat;
31 import org.dom4j.io.XMLWriter;
32 import org.springframework.beans.factory.config.BeanDefinition;
33 import org.springframework.core.io.UrlResource;
34 import org.w3c.dom.Document;
37 * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
39 public class PlexusBeanDefinitionDocumentReaderTest
43 public void testXslt()
46 URL plexus = getClass().getResource( "components.xml" );
47 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
48 DocumentBuilder builder = factory.newDocumentBuilder();
49 Document doc = builder.parse( plexus.openStream() );
51 PlexusBeanDefinitionDocumentReader reader = new PlexusBeanDefinitionDocumentReader();
52 doc = reader.convertPlexusDescriptorToSpringBeans( doc );
54 new XMLWriter( System.out, OutputFormat.createPrettyPrint() ).write( new DOMReader().read( doc ) );
58 * Test conversion from a typical Plexus components descriptor to a spring beanFactory
61 public void testConvertPlexusToSpring()
64 URL plexus = getClass().getResource( "components.xml" );
65 PlexusBeanFactory factory = new PlexusBeanFactory( new UrlResource( plexus ) );
66 assertEquals( 2, factory.getBeanDefinitionCount() );
68 BeanDefinition bd = factory.getBeanDefinition( "org.apache.maven.archiva.configuration.ArchivaConfiguration" );
69 assertEquals( "org.apache.maven.archiva.configuration.DefaultArchivaConfiguration", bd.getBeanClassName() );
70 assertEquals( "prototype", bd.getScope() );
71 assertEquals( 5, bd.getPropertyValues().size() );