1   package org.apache.maven.cli;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import java.util.Properties;
23  
24  import junit.framework.TestCase;
25  
26  /**
27   * Test method for 'org.apache.maven.cli.MavenCli.main(String[], ClassWorld)'
28   *
29   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
30   * @version $Id: MavenCliTest.java 788791 2009-06-26 17:55:26Z jdcasey $
31   */
32  public class MavenCliTest
33      extends TestCase
34  {
35  
36      public void testGetExecutionProperties()
37          throws Exception
38      {
39          System.setProperty( "test.property.1", "1.0" );
40          System.setProperty( "test.property.2", "2.0" );
41          Properties execProperties = new Properties();
42          Properties userProperties = new Properties();
43  
44          MavenCli.populateProperties( ( new CLIManager() ).parse( new String[] {
45              "-Dtest.property.2=2.1",
46              "-Dtest.property.3=3.0" } ), execProperties, userProperties );
47          
48          System.out.println( "Execution properties:\n\n" );
49          execProperties.list( System.out );
50          
51          System.out.println( "\n\nUser properties:\n\n" );
52          userProperties.list( System.out );
53  
54          // assume that everybody has a PATH env var
55          String envPath = execProperties.getProperty( "env.PATH" );
56          String envPath2 = userProperties.getProperty( "env.PATH" );
57          if ( envPath == null )
58          {
59              envPath = execProperties.getProperty( "env.Path" );
60              envPath2 = userProperties.getProperty( "env.Path" );
61          }
62  
63          assertNotNull( envPath );
64          assertNull( envPath2 );
65  
66          assertEquals( "1.0", execProperties.getProperty( "test.property.1" ) );
67          assertNull( userProperties.getProperty( "test.property.1" ) );
68  
69          assertEquals( "3.0", execProperties.getProperty( "test.property.3" ) );
70          assertEquals( "3.0", userProperties.getProperty( "test.property.3" ) );
71  
72          // sys props should override cmdline props
73          //assertEquals( "2.0", p.getProperty( "test.property.2" ) );
74      }
75  
76      public void testGetBuildProperties()
77          throws Exception
78      {
79          Properties properties = MavenCli.getBuildProperties();
80  
81          assertNotNull( properties.getProperty( "version" ) );
82          assertNotNull( properties.getProperty( "buildNumber" ) );
83          assertNotNull( properties.getProperty( "timestamp" ) );
84          assertFalse( properties.getProperty( "version" ).equals( "${project.version}" ) );
85          assertFalse( properties.getProperty( "buildNumber" ).equals( "${buildNumber}" ) );
86          assertFalse( properties.getProperty( "timestamp" ).equals( "${timestamp}" ) );
87      }
88  }