View Javadoc
1   package org.codehaus.plexus.interpolation.multi;
2   
3   /*
4    * Copyright 2001-2009 Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.codehaus.plexus.interpolation.InterpolationException;
20  import org.codehaus.plexus.interpolation.MapBasedValueSource;
21  import org.codehaus.plexus.interpolation.ValueSource;
22  import org.codehaus.plexus.interpolation.multi.MultiDelimiterStringSearchInterpolator;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import junit.framework.TestCase;
28  
29  public class MultiDelimiterStringSearchInterpolatorTest
30      extends TestCase
31  {
32  
33      public void testInterpolationWithDifferentDelimiters()
34          throws InterpolationException
35      {
36          Map ctx = new HashMap();
37          ctx.put( "name", "User" );
38          ctx.put( "otherName", "@name@" );
39  
40          String input = "${otherName}";
41  
42          ValueSource vs = new MapBasedValueSource( ctx );
43          MultiDelimiterStringSearchInterpolator interpolator = new MultiDelimiterStringSearchInterpolator().addDelimiterSpec( "@" )
44                                                                        .withValueSource( vs );
45  
46          String result = interpolator.interpolate( input );
47  
48          assertEquals( ctx.get( "name" ), result );
49      }
50  
51      public void testSuccessiveInterpolationWithDifferentDelimiters_ReversedDelimiterSequence()
52          throws InterpolationException
53      {
54          Map ctx = new HashMap();
55          ctx.put( "name", "User" );
56          ctx.put( "otherName", "${name}" );
57  
58          String input = "@otherName@";
59  
60          ValueSource vs = new MapBasedValueSource( ctx );
61          MultiDelimiterStringSearchInterpolator interpolator = new MultiDelimiterStringSearchInterpolator().addDelimiterSpec( "@" )
62                                                                        .withValueSource( vs );
63  
64          String result = interpolator.interpolate( input );
65  
66          assertEquals( ctx.get( "name" ), result );
67      }
68  
69  }