View Javadoc
1   package org.codehaus.plexus.classworlds.launcher;
2   
3   import org.codehaus.plexus.classworlds.AbstractClassWorldsTestCase;
4   
5   public class ConfigurationParserTest
6       extends AbstractClassWorldsTestCase
7   {
8       
9       ConfigurationParser configurator = new ConfigurationParser( null, System.getProperties() );
10  
11      public ConfigurationParserTest( String string )
12      {
13          super( string );
14      }
15  
16      public void testFilter_Unterminated()
17          throws Exception
18      {
19          try
20          {
21              this.configurator.filter( "${cheese" );
22              fail( "throw ConfigurationException" );
23          }
24          catch ( ConfigurationException e )
25          {
26              // expected and correct
27              assertTrue( e.getMessage().startsWith( "Unterminated" ) );
28          }
29      }
30  
31      public void testFilter_Solitary()
32          throws Exception
33      {
34          System.setProperty( "classworlds.test.prop", "test prop value" );
35  
36          String result = this.configurator.filter( "${classworlds.test.prop}" );
37  
38          assertEquals( "test prop value", result );
39      }
40  
41      public void testFilter_AtStart()
42          throws Exception
43      {
44          System.setProperty( "classworlds.test.prop", "test prop value" );
45  
46          String result = this.configurator.filter( "${classworlds.test.prop}cheese" );
47  
48          assertEquals( "test prop valuecheese", result );
49      }
50  
51      public void testFilter_AtEnd()
52          throws Exception
53      {
54          System.setProperty( "classworlds.test.prop", "test prop value" );
55  
56          String result = this.configurator.filter( "cheese${classworlds.test.prop}" );
57  
58          assertEquals( "cheesetest prop value", result );
59      }
60  
61      public void testFilter_Multiple()
62          throws Exception
63      {
64          System.setProperty( "classworlds.test.prop.one", "test prop value one" );
65  
66          System.setProperty( "classworlds.test.prop.two", "test prop value two" );
67  
68          String result =
69              this.configurator.filter( "I like ${classworlds.test.prop.one} and ${classworlds.test.prop.two} a lot" );
70  
71          assertEquals( "I like test prop value one and test prop value two a lot", result );
72      }
73  
74      public void testFilter_NonExistent()
75          throws Exception
76      {
77          try
78          {
79              this.configurator.filter( "${gollygeewillikers}" );
80              fail( "throw ConfigurationException" );
81          }
82          catch ( ConfigurationException e )
83          {
84              // expected and correct
85              assertTrue( e.getMessage().startsWith( "No such property" ) );
86          }
87      }
88  
89      public void testFilter_InMiddle()
90          throws Exception
91      {
92          System.setProperty( "classworlds.test.prop", "test prop value" );
93  
94          String result = this.configurator.filter( "cheese${classworlds.test.prop}toast" );
95  
96          assertEquals( "cheesetest prop valuetoast", result );
97      }
98  
99  }