CVS: plexus-container-new/src/test/org/apache/plexus/configuration XmlPullConfigurationBuilderTest.java,NONE,1.1 plexus.conf,NONE,1.1

[email protected] Fri, 2 May 2003 19:30:59 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container-new/src/test/org/apache/plexus/configuration
In directory eng.werken.com:/tmp/cvs-serv1319

Added Files:
	XmlPullConfigurationBuilderTest.java plexus.conf 
Log Message:
o Test for an XmlPull-based configuration builder.


--- NEW FILE: XmlPullConfigurationBuilderTest.java ---
package org.apache.plexus.configuration;

import junit.framework.TestCase;
import org.apache.avalon.framework.configuration.Configuration;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;

/**
 * Generated by JUnitDoclet, a tool provided by ObjectFab GmbH under LGPL.
 * Please see www.junitdoclet.org, www.gnu.org and www.objectfab.de for
 * informations about the tool, the licence and the authors.
 */
public class XmlPullConfigurationBuilderTest
    extends TestCase
{
    public XmlPullConfigurationBuilderTest( String name )
    {
        super( name );
    }

    /**
     * The JUnit setup method
     */
    protected void setUp()
        throws Exception
    {
    }

    /**
     * The teardown method for JUnit
     */
    protected void tearDown()
        throws Exception
    {
    }

    public void testSimpleConfigurationBuilding()
        throws Exception
    {
        String s = "<conf><name>jason</name></conf>";
        XmlPullConfigurationBuilder cb = new XmlPullConfigurationBuilder();
        Configuration c = cb.parse( new StringReader( s ) );

        assertNotNull( c );
        assertEquals( "jason", c.getChild( "name" ).getValue() );
    }

    public void testComplexConfigurationBuilding()
        throws Exception
    {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(
            "org/apache/plexus/configuration/plexus.conf" );

        XmlPullConfigurationBuilder cb = new XmlPullConfigurationBuilder();
        Configuration c = cb.parse( new InputStreamReader( is ) );

        assertNotNull( c );

        Configuration logging = c.getChild( "logging" );
        assertNotNull( logging );
        assertEquals( "org.apache.plexus.logging.ConsoleLoggerManager",
                      logging.getChild( "implementation" ).getValue() );

        Configuration componentRepository = c.getChild( "component-repository" );
        assertNotNull( componentRepository );
        assertEquals( "org.apache.plexus.service.repository.DefaultComponentRepository",
                      componentRepository.getChild( "implementation" ).getValue() );

        Configuration resourceManager = c.getChild( "resource-manager" );
        assertNotNull( resourceManager );
        assertEquals( "org.apache.plexus.classloader.DefaultResourceManager",
                      resourceManager.getChild( "implementation" ).getValue() );

        Configuration lifecycleHandler = c.getChild( "lifecycle-handler" );
        assertNotNull( lifecycleHandler );
        assertEquals( lifecycleHandler.getChild( "id" ).getValue(), "avalon-lifecycle-handler" );
        assertEquals( lifecycleHandler.getChild( "name" ).getValue(), "Avalon Lifecycle Handler" );
        assertEquals( lifecycleHandler.getChild( "implementation" ).getValue(),
                      "org.apache.plexus.lifecycle.avalon.AvalonLifecycleHandler" );

        Configuration[] startSegmentPhases =
            lifecycleHandler.getChild( "start-segment" ).getChildren( "phase" );

        assertEquals( "org.apache.plexus.lifecycle.phase.LogEnablePhase",
                      startSegmentPhases[0].getAttribute( "implementation" ) );
        assertEquals( "org.apache.plexus.lifecycle.phase.ContextualizePhase",
                      startSegmentPhases[1].getAttribute( "implementation" ) );
        assertEquals( "org.apache.plexus.lifecycle.phase.ServicePhase",
                      startSegmentPhases[2].getAttribute( "implementation" ) );
        assertEquals( "org.apache.plexus.lifecycle.phase.ConfigurePhase",
                      startSegmentPhases[3].getAttribute( "implementation" ) );
        assertEquals( "org.apache.plexus.lifecycle.phase.ParameterizePhase",
                      startSegmentPhases[4].getAttribute( "implementation" ) );
        assertEquals( "org.apache.plexus.lifecycle.phase.InitializePhase",
                      startSegmentPhases[5].getAttribute( "implementation" ) );
        assertEquals( "org.apache.plexus.lifecycle.phase.StartPhase",
                      startSegmentPhases[6].getAttribute( "implementation" ) );

        Configuration[] components = c.getChild( "components" ).getChildren( "component" );

        assertEquals( "org.apache.plexus.service.repository.factory.ComponentFactory",
                      components[0].getChild( "role" ).getValue() );
        assertEquals( "java",
                      components[0].getChild( "role-hint" ).getValue() );
        assertEquals( "org.apache.plexus.service.repository.factory.JavaComponentFactory",
                      components[0].getChild( "implementation" ).getValue() );
    }

    public void testParserReuse()
        throws Exception
    {
        String s = "<conf><name>jason</name></conf>";
        XmlPullConfigurationBuilder cb = new XmlPullConfigurationBuilder();

        Configuration c = cb.parse( new StringReader( s ) );
        assertNotNull( c );
        assertEquals( "jason", c.getChild( "name" ).getValue() );

        s = "<conf><name>bob</name></conf>";
        c = cb.parse( new StringReader( s ) );
        assertNotNull( c );
        assertEquals( "bob", c.getChild( "name" ).getValue() );

        s = "<conf><name>pete</name></conf>";
        c = cb.parse( new StringReader( s ) );
        assertNotNull( c );
        assertEquals( "pete", c.getChild( "name" ).getValue() );

        s = "<conf><name>melissa</name></conf>";
        c = cb.parse( new StringReader( s ) );
        assertNotNull( c );
        assertEquals( "melissa", c.getChild( "name" ).getValue() );
    }
}

--- NEW FILE: plexus.conf ---
<plexus>
  <logging>
    <implementation>org.apache.plexus.logging.ConsoleLoggerManager</implementation>
  </logging>
  <component-repository>
    <implementation>org.apache.plexus.service.repository.DefaultComponentRepository</implementation>
  </component-repository>
  <resource-manager>
    <implementation>org.apache.plexus.classloader.DefaultResourceManager</implementation>
  </resource-manager>
  <lifecycle-handler>
    <id>avalon-lifecycle-handler</id>
    <name>Avalon Lifecycle Handler</name>
    <implementation>org.apache.plexus.lifecycle.avalon.AvalonLifecycleHandler</implementation>
    <start-segment>
      <phase implementation="org.apache.plexus.lifecycle.phase.LogEnablePhase"/>
      <phase implementation="org.apache.plexus.lifecycle.phase.ContextualizePhase"/>
      <phase implementation="org.apache.plexus.lifecycle.phase.ServicePhase"/>
      <phase implementation="org.apache.plexus.lifecycle.phase.ConfigurePhase"/>
      <phase implementation="org.apache.plexus.lifecycle.phase.ParameterizePhase"/>
      <phase implementation="org.apache.plexus.lifecycle.phase.InitializePhase"/>
      <phase implementation="org.apache.plexus.lifecycle.phase.StartPhase"/>
    </start-segment>
    <suspend-segment>
      <phase implementation="org.apache.plexus.lifecycle.phase.SuspendPhase"/>
    </suspend-segment>
    <resume-segment>
      <phase implementation="org.apache.plexus.lifecycle.phase.ResumePhase"/>
      <phase implementation="org.apache.plexus.lifecycle.phase.RecontextualizePhase"/>
      <phase implementation="org.apache.plexus.lifecycle.phase.ReconfigurePhase"/>
      <phase implementation="org.apache.plexus.lifecycle.phase.ReparameterizePhase"/>
    </resume-segment>
    <end-segment>
      <phase implementation="org.apache.plexus.lifecycle.phase.StopPhase"/>
      <phase implementation="org.apache.plexus.lifecycle.phase.DisposePhase"/>
    </end-segment>
  </lifecycle-handler>

  <!-- Default Components -->

  <components>
    <!--
     |
     | These are the default component factories.
     |
     -->
    <component>
      <role>org.apache.plexus.service.repository.factory.ComponentFactory</role>
      <role-hint>java</role-hint>
      <implementation>org.apache.plexus.service.repository.factory.JavaComponentFactory</implementation>
      <configuration>
      </configuration>
    </component>

    <!--
     |
     | These are the default instance managers.
     |
     -->
    <component>
      <role>org.apache.plexus.service.repository.instance.InstanceManager</role>
      <role-hint>per-lookup</role-hint>
      <implementation>org.apache.plexus.service.repository.instance.PerLookupInstanceManager</implementation>
      <configuration>
        <tag>per-lookup</tag>
      </configuration>
    </component>
    <component>
      <role>org.apache.plexus.service.repository.instance.InstanceManager</role>
      <role-hint>poolable</role-hint>
      <implementation>org.apache.plexus.service.repository.instance.PoolableInstanceManager</implementation>
      <configuration>
        <tag>poolable</tag>
      </configuration>
    </component>
    <component>
      <role>org.apache.plexus.service.repository.instance.InstanceManager</role>
      <role-hint>singleton</role-hint>
      <implementation>org.apache.plexus.service.repository.instance.SingletonInstanceManager</implementation>
      <configuration>
        <tag>poolable</tag>
      </configuration>
    </component>
  </components>
</plexus>