1 package org.apache.maven.scm.provider.starteam.command.changelog;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
36
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
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
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 }