View Javadoc
1   package org.apache.maven.scm.provider.git.gitexe.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.ScmBranch;
23  import org.apache.maven.scm.ScmRevision;
24  import org.apache.maven.scm.ScmTestCase;
25  import org.apache.maven.scm.ScmVersion;
26  import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
27  import org.apache.maven.scm.repository.ScmRepository;
28  import org.codehaus.plexus.util.cli.Commandline;
29  
30  import java.io.File;
31  import java.util.Calendar;
32  import java.util.Date;
33  
34  /**
35   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
36   *
37   */
38  public class GitChangeLogCommandTest
39      extends ScmTestCase
40  {
41      private File workingDirectory;
42      
43      public void setUp() throws Exception
44      {
45          super.setUp();
46          
47          workingDirectory = getTestFile( "target/git-update-command-test" );
48      }
49  
50      public void testCommandLineNoDates()
51          throws Exception
52      {
53          testCommandLine( "scm:git:http://foo.com/git", null, (Date) null, (Date) null, 40,
54                           "git whatchanged --date=iso --max-count=40 -- ." );
55      }
56  
57      public void testCommandLineNoDatesLimitedCount()
58          throws Exception
59      {
60          testCommandLine( "scm:git:http://foo.com/git", null, (Date) null, (Date) null,
61                           "git whatchanged --date=iso -- ." );
62      }
63  
64      public void testCommandLineWithDates()
65          throws Exception
66      {
67          Date startDate = getDate( 2003, Calendar.SEPTEMBER, 10, GMT_TIME_ZONE );
68          Date endDate = getDate( 2007, Calendar.OCTOBER, 10, GMT_TIME_ZONE );
69  
70          testCommandLine( "scm:git:http://foo.com/git", null, startDate, endDate,
71                           "git whatchanged \"--since=2003-09-10 00:00:00 +0000\" \"--until=2007-10-10 00:00:00 +0000\" --date=iso -- ." );
72      }
73  
74      public void testCommandLineStartDateOnly()
75          throws Exception
76      {
77          Date startDate = getDate( 2003, Calendar.SEPTEMBER, 10, 1, 1, 1, GMT_TIME_ZONE );
78  
79          testCommandLine( "scm:git:http://foo.com/git", null, startDate, null,
80                           "git whatchanged \"--since=2003-09-10 01:01:01 +0000\" --date=iso -- ." );
81      }
82  
83      public void testCommandLineDateFormat()
84          throws Exception
85      {
86          Date startDate = getDate( 2003, Calendar.SEPTEMBER, 10, 1, 1, 1, GMT_TIME_ZONE );
87          Date endDate = getDate( 2005, Calendar.NOVEMBER, 13, 23, 23, 23, GMT_TIME_ZONE );
88  
89          testCommandLine( "scm:git:http://foo.com/git", null, startDate, endDate,
90                           "git whatchanged \"--since=2003-09-10 01:01:01 +0000\" \"--until=2005-11-13 23:23:23 +0000\" --date=iso -- ." );
91      }
92  
93      public void testCommandLineDateVersionRanges()
94          throws Exception
95      {
96          Date startDate = getDate( 2003, Calendar.SEPTEMBER, 10, 1, 1, 1, GMT_TIME_ZONE );
97          Date endDate = getDate( 2005, Calendar.NOVEMBER, 13, 23, 23, 23, GMT_TIME_ZONE );
98      
99          testCommandLine( "scm:git:http://foo.com/git", null, startDate, endDate, new ScmRevision( "1" ), new ScmRevision( "10" ),
100                          "git whatchanged \"--since=2003-09-10 01:01:01 +0000\" \"--until=2005-11-13 23:23:23 +0000\" --date=iso 1..10 -- ." );
101     }
102     
103     public void testCommandLineEndDateOnly()
104         throws Exception
105     {
106         Date endDate = getDate( 2003, Calendar.NOVEMBER, 10, GMT_TIME_ZONE );
107 
108         // Only specifying end date should print no dates at all
109         testCommandLine( "scm:git:http://foo.com/git", null, null, endDate,
110                          "git whatchanged \"--until=2003-11-10 00:00:00 +0000\" --date=iso -- ." );
111     }
112 
113     public void testCommandLineWithBranchNoDates()
114         throws Exception
115     {
116         testCommandLine( "scm:git:http://foo.com/git", new ScmBranch( "my-test-branch" ), (Date) null, (Date) null, 
117                          "git whatchanged --date=iso my-test-branch -- ." );
118     }
119 
120 
121     public void testCommandLineWithStartVersion()
122         throws Exception
123     {
124         testCommandLine( "scm:git:http://foo.com/git", null, new ScmRevision( "1" ), null, 
125                          "git whatchanged --date=iso 1.. -- ." );
126     }
127 
128     public void testCommandLineWithStartVersionAndEndVersion()
129         throws Exception
130     {
131         testCommandLine( "scm:git:http://foo.com/git", null, new ScmRevision( "1" ), new ScmRevision( "10" ), 
132                          "git whatchanged --date=iso 1..10 -- ." );
133     }
134 
135     public void testCommandLineWithStartVersionAndEndVersionEquals()
136         throws Exception
137     {
138         testCommandLine( "scm:git:http://foo.com/git", null, new ScmRevision( "1" ), new ScmRevision( "1" ), 
139                          "git whatchanged --date=iso 1..1 -- ." );
140     }
141 
142     public void testCommandLineWithStartVersionAndEndVersionAndBranch()
143         throws Exception
144     {
145         testCommandLine( "scm:git:http://foo.com/git", new ScmBranch( "my-test-branch" ), new ScmRevision( "1" ), new ScmRevision( "10" ), 
146                          "git whatchanged --date=iso 1..10 my-test-branch -- ." );
147     }
148 
149     // ----------------------------------------------------------------------
150     // private helper functions
151     // ----------------------------------------------------------------------
152 
153     private void testCommandLine( String scmUrl, ScmBranch branch, Date startDate, Date endDate, String commandLine )
154         throws Exception
155     {
156         testCommandLine( scmUrl, branch, startDate, endDate, null, commandLine );
157     }
158 
159     private void testCommandLine( String scmUrl, ScmBranch branch, Date startDate, Date endDate, Integer limit, String commandLine )
160         throws Exception
161     {
162         ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
163 
164         GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
165 
166         Commandline cl = GitChangeLogCommand.createCommandLine( gitRepository, workingDirectory, branch, startDate,
167                                                                 endDate, null, null, limit );
168 
169         assertCommandLine( commandLine, workingDirectory, cl );
170     }
171 
172     private void testCommandLine( String scmUrl, ScmBranch branch, ScmVersion startVersion, ScmVersion endVersion, String commandLine )
173         throws Exception
174     {
175         ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
176 
177         GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
178 
179         Commandline cl = GitChangeLogCommand.createCommandLine( gitRepository, workingDirectory, branch, null, null,
180                                                                 startVersion, endVersion );
181 
182         assertCommandLine( commandLine, workingDirectory, cl );
183     }
184 
185     private void testCommandLine( String scmUrl, ScmBranch branch, Date startDate, Date endDate, 
186                                   ScmVersion startVersion, ScmVersion endVersion, String commandLine )
187         throws Exception
188     {
189         ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
190     
191         GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
192     
193         Commandline cl = GitChangeLogCommand.createCommandLine( gitRepository, workingDirectory, branch, startDate, endDate,
194                                                                 startVersion, endVersion );
195     
196         assertCommandLine( commandLine, workingDirectory, cl );
197     }
198 }