View Javadoc
1   package org.apache.maven.scm.provider.clearcase.command.update;
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.ScmFile;
23  import org.apache.maven.scm.ScmFileStatus;
24  import org.apache.maven.scm.ScmTestCase;
25  import org.apache.maven.scm.log.DefaultLog;
26  
27  import java.io.BufferedReader;
28  import java.io.File;
29  import java.io.IOException;
30  import java.io.InputStream;
31  import java.io.InputStreamReader;
32  import java.util.Collection;
33  import java.util.Locale;
34  
35  /**
36   * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
37   */
38  public class ClearCaseUpdateConsumerTest
39      extends ScmTestCase
40  {
41      private InputStream getResourceAsStream( String name, Locale locale )
42      {
43          String path;
44          if ( locale == null || "".equals( locale.getLanguage() ) )
45          {
46              path = name;
47          }
48          else
49          {
50              String base = name.substring( 0, name.lastIndexOf( '.' ) );
51              String ext = name.substring( name.lastIndexOf( '.' ) );
52              path = base + "_" + locale.getLanguage() + ext;
53              if ( !new File( path ).exists() )
54              {
55                  path = name;
56              }
57          }
58  
59          return super.getResourceAsStream( path );
60      }
61  
62      private void localizedConsumer( Locale locale )
63          throws IOException
64      {
65          InputStream inputStream = getResourceAsStream( "/clearcase/update/update.txt", locale );
66  
67          BufferedReader in = new BufferedReader( new InputStreamReader( inputStream, "UTF-8" ) );
68  
69          String s = in.readLine();
70  
71          ClearCaseUpdateConsumer consumer = new ClearCaseUpdateConsumer( new DefaultLog() );
72  
73          while ( s != null )
74          {
75              consumer.consumeLine( s );
76  
77              s = in.readLine();
78          }
79  
80          String message = "locale is \"" + locale.getLanguage() + "\"";
81          Collection<ScmFile> entries = consumer.getUpdatedFiles();
82  
83          assertEquals( message + " Wrong number of entries returned", 1, entries.size() );
84  
85          ScmFile scmFile = entries.iterator().next();
86          assertEquals( message, "my_vob\\modules\\utils\\utils-logging-jar\\testfile.txt", scmFile.getPath() );
87          assertEquals( message, ScmFileStatus.UPDATED, scmFile.getStatus() );
88      }
89  
90      public void testConsumer()
91          throws IOException
92      {
93          // Locale[] locales = { Locale.US, Locale.JAPANESE };
94          Locale[] locales = { Locale.getDefault() };
95          Locale defaultLocale = Locale.getDefault();
96  
97          for ( int i = 0; i < locales.length; i++ )
98          {
99              Locale.setDefault( locales[i] );
100             localizedConsumer( locales[i] );
101         }
102         Locale.setDefault( defaultLocale );
103     }
104 }