CVS: plexus-container-new/src/test/org/apache/plexus/util ContextMapAdapterTest.java,NONE,1.1 InterpolationFilterReaderTest.java,1.2,1.3

[email protected]
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container-new/src/test/org/apache/plexus/util
In directory eng.werken.com:/tmp/cvs-serv7788/src/test/org/apache/plexus/util

Modified Files:
	InterpolationFilterReaderTest.java 
Added Files:
	ContextMapAdapterTest.java 
Log Message:
o Clarifying name of the container host.
o Using the context as the source of values for the configuration resource
  interpolation. As a result I cleaned up anything to do with configuration
  variables as this is redundant given the existence of the context.
o Created a simple adapter so that a context can be used as a Map in the
  InterpolationFilterReader.
o Added test cases for the ContextMapAdapter and the InterpolationFilterReader
  using the adapter.


--- NEW FILE: ContextMapAdapterTest.java ---
package org.apache.plexus.util;

import junit.framework.TestCase;

import java.util.Map;
import java.util.HashMap;
import java.io.StringReader;
import java.io.StringWriter;

import org.apache.plexus.context.DefaultContext;

/**
 * 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 ContextMapAdapterTest
    extends TestCase
{
    public ContextMapAdapterTest( 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 testInterpolation()
        throws Exception
    {
        DefaultContext context = new DefaultContext();
        context.put( "name", "jason" );
        context.put( "occupation", "exotic dancer" );

        ContextMapAdapter adapter = new ContextMapAdapter( context );

        assertEquals( "jason", (String) adapter.get( "name" ) );
        assertEquals( "exotic dancer", (String) adapter.get( "occupation" ) );
    }
}

Index: InterpolationFilterReaderTest.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/test/org/apache/plexus/util/InterpolationFilterReaderTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- InterpolationFilterReaderTest.java	25 Apr 2003 18:11:19 -0000	1.2
+++ InterpolationFilterReaderTest.java	27 Apr 2003 16:27:43 -0000	1.3
@@ -7,6 +7,9 @@
 import java.io.StringReader;
 import java.io.StringWriter;
 
+import org.apache.avalon.framework.context.Context;
+import org.apache.plexus.context.DefaultContext;
+
 /**
  * Generated by JUnitDoclet, a tool provided by ObjectFab GmbH under LGPL.
  * Please see www.junitdoclet.org, www.gnu.org and www.objectfab.de for
@@ -46,6 +49,28 @@
         String foo = "${name} is an ${noun}. ${not.interpolated}";
 
         InterpolationFilterReader reader = new InterpolationFilterReader( new StringReader( foo ), m );
+
+        StringWriter writer = new StringWriter();
+        IOUtil.copy( reader, writer );
+
+        String bar = writer.toString();
+
+        System.out.println( "interpolated string: " + bar );
+
+        assertEquals( "jason is an asshole. ${not.interpolated}", bar );
+    }
+
+    public void testInterpolationWithContext()
+        throws Exception
+    {
+        DefaultContext context = new DefaultContext();
+        context.put( "name", "jason" );
+        context.put( "noun", "asshole" );
+
+        String foo = "${name} is an ${noun}. ${not.interpolated}";
+
+        InterpolationFilterReader reader =
+            new InterpolationFilterReader( new StringReader( foo ), new ContextMapAdapter( context ) );
 
         StringWriter writer = new StringWriter();
         IOUtil.copy( reader, writer );
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.