View Javadoc

1   package org.apache.maven.scm.provider.starteam.command.changelog;
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 org.apache.maven.scm.ChangeSet;
23  import org.apache.maven.scm.ScmTestCase;
24  import org.apache.maven.scm.log.DefaultLog;
25  
26  import java.io.BufferedReader;
27  import java.io.File;
28  import java.io.FileInputStream;
29  import java.io.InputStreamReader;
30  import java.util.Iterator;
31  import java.util.List;
32  import java.util.Locale;
33  
34  /**
35   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
36   * @version $Id: StarteamChangeLogConsumerTest.java 1058774 2011-01-13 22:51:51Z olamy $
37   */
38  public class StarteamChangeLogConsumerTest
39      extends ScmTestCase
40  {
41      private File testFile;
42  
43      public void setUp()
44          throws Exception
45      {
46          super.setUp();
47  
48          String language = Locale.getDefault().getLanguage();
49  
50          testFile = getTestFile( "/src/test/resources/starteam/changelog/starteamlog_" + language + ".txt" );
51  
52          if ( !testFile.exists() )
53          {
54              testFile = getTestFile( "/src/test/resources/starteam/changelog/starteamlog_en.txt" );
55          }
56      }
57  
58      private List<ChangeSet> parseTestFile()
59          throws Exception
60      {
61          /* must match the working directory in the text test file */
62  
63          File basedir = new File( "C:/Test" );
64  
65          FileInputStream fis = new FileInputStream( testFile );
66  
67          BufferedReader in = new BufferedReader( new InputStreamReader( fis ) );
68  
69          String s = in.readLine();
70  
71          StarteamChangeLogConsumer consumer =
72              new StarteamChangeLogConsumer( basedir, new DefaultLog(), null, null, null );
73  
74          while ( s != null )
75          {
76              consumer.consumeLine( s );
77  
78              s = in.readLine();
79          }
80  
81          return consumer.getModifications();
82      }
83  
84      public void testNumberOfModifications()
85          throws Exception
86      {
87          List<ChangeSet> entries = parseTestFile();
88  
89          assertEquals( "Wrong number of entries returned", 6, entries.size() );
90  
91          for ( Iterator<ChangeSet> i = entries.iterator(); i.hasNext(); )
92          {
93              assertTrue( "ChangeLogEntry erroneously picked up",
94                          i.next().toString().indexOf( "ChangeLogEntry.java" ) == -1 );
95          }
96      }
97  
98      public void testRelativeFilePath()
99          throws Exception
100     {
101         List<ChangeSet> entries = parseTestFile();
102 
103         // ensure the filename in the first ChangeSet has correct relative path
104         ChangeSet entry = (ChangeSet) entries.get( 1 );
105 
106         assertTrue( entry.containsFilename( "./maven/src/File2.java" ));
107     }
108 
109     public void testLocales()
110         throws Exception
111     {
112         Locale currentLocale = Locale.getDefault();
113 
114         Locale[] availableLocales = Locale.getAvailableLocales();
115         try
116         {
117             for ( int i = 0; i < availableLocales.length; i++ )
118             {
119                 Locale.setDefault( availableLocales[i] );
120 
121                 String language = availableLocales[i].getLanguage();
122 
123                 testFile = getTestFile( "/src/test/resources/starteam/changelog/starteamlog_" + language + ".txt" );
124 
125                 if ( !testFile.exists() )
126                 {
127                     testFile = getTestFile( "/src/test/resources/starteam/changelog/starteamlog_en.txt" );
128                 }
129 
130                 parseTestFile();
131             }
132         }
133         finally
134         {
135             Locale.setDefault( currentLocale );
136         }
137     }
138 }