001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.provider.svn.svnexe.command.changelog; 020 021import java.io.File; 022import java.util.Calendar; 023import java.util.Date; 024 025import org.apache.maven.scm.ScmBranch; 026import org.apache.maven.scm.ScmRevision; 027import org.apache.maven.scm.ScmTestCase; 028import org.apache.maven.scm.ScmVersion; 029import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository; 030import org.apache.maven.scm.repository.ScmRepository; 031import org.codehaus.plexus.util.cli.Commandline; 032import org.junit.Test; 033 034/** 035 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 036 * 037 */ 038public class SvnChangeLogCommandTest extends ScmTestCase { 039 @Test 040 public void testCommandLineNoDates() throws Exception { 041 testCommandLine( 042 "scm:svn:http://foo.com/svn/trunk", 043 null, 044 null, 045 null, 046 "svn --non-interactive log -v http://foo.com/svn/trunk@"); 047 } 048 049 @Test 050 public void testCommandLineNoDatesLimitedCount() throws Exception { 051 testCommandLine( 052 "scm:svn:http://foo.com/svn/trunk", 053 null, 054 null, 055 null, 056 40, 057 "svn --non-interactive log -v --limit 40 http://foo.com/svn/trunk@"); 058 } 059 060 @Test 061 public void testCommandLineWithDates() throws Exception { 062 Date startDate = getDate(2003, Calendar.SEPTEMBER, 10, GMT_TIME_ZONE); 063 Date endDate = getDate(2003, Calendar.OCTOBER, 10, GMT_TIME_ZONE); 064 065 testCommandLine( 066 "scm:svn:http://foo.com/svn/trunk", 067 null, 068 startDate, 069 endDate, 070 "svn --non-interactive log -v -r \"{2003-09-10 00:00:00 +0000}:{2003-10-10 00:00:00 +0000}\" http://foo.com/svn/trunk@"); 071 } 072 073 @Test 074 public void testCommandLineStartDateOnly() throws Exception { 075 Date startDate = getDate(2003, Calendar.SEPTEMBER, 10, 1, 1, 1, GMT_TIME_ZONE); 076 077 testCommandLine( 078 "scm:svn:http://foo.com/svn/trunk", 079 null, 080 startDate, 081 null, 082 "svn --non-interactive log -v -r \"{2003-09-10 01:01:01 +0000}:HEAD\" http://foo.com/svn/trunk@"); 083 } 084 085 @Test 086 public void testCommandLineDateFormat() throws Exception { 087 Date startDate = getDate(2003, Calendar.SEPTEMBER, 10, 1, 1, 1, GMT_TIME_ZONE); 088 Date endDate = getDate(2005, Calendar.NOVEMBER, 13, 23, 23, 23, GMT_TIME_ZONE); 089 090 testCommandLine( 091 "scm:svn:http://foo.com/svn/trunk", 092 null, 093 startDate, 094 endDate, 095 "svn --non-interactive log -v -r \"{2003-09-10 01:01:01 +0000}:{2005-11-13 23:23:23 +0000}\" http://foo.com/svn/trunk@"); 096 } 097 098 @Test 099 public void testCommandLineEndDateOnly() throws Exception { 100 Date endDate = getDate(2003, Calendar.NOVEMBER, 10, GMT_TIME_ZONE); 101 102 // Only specifying end date should print no dates at all 103 testCommandLine( 104 "scm:svn:http://foo.com/svn/trunk", 105 null, 106 null, 107 endDate, 108 "svn --non-interactive log -v http://foo.com/svn/trunk@"); 109 } 110 111 @Test 112 public void testCommandLineWithBranchNoDates() throws Exception { 113 testCommandLine( 114 "scm:svn:http://foo.com/svn/trunk", 115 new ScmBranch("my-test-branch"), 116 null, 117 null, 118 "svn --non-interactive log -v http://foo.com/svn/branches/my-test-branch@ http://foo.com/svn/trunk@"); 119 } 120 121 @Test 122 public void testCommandLineWithBranchStartDateOnly() throws Exception { 123 Date startDate = getDate(2003, Calendar.SEPTEMBER, 10, 1, 1, 1, GMT_TIME_ZONE); 124 125 testCommandLine( 126 "scm:svn:http://foo.com/svn/trunk", 127 new ScmBranch("my-test-branch"), 128 startDate, 129 null, 130 "svn --non-interactive log -v -r \"{2003-09-10 01:01:01 +0000}:HEAD\" http://foo.com/svn/branches/my-test-branch@ http://foo.com/svn/trunk@"); 131 } 132 133 @Test 134 public void testCommandLineWithBranchEndDateOnly() throws Exception { 135 Date endDate = getDate(2003, Calendar.OCTOBER, 10, 1, 1, 1, GMT_TIME_ZONE); 136 137 // Only specifying end date should print no dates at all 138 testCommandLine( 139 "scm:svn:http://foo.com/svn/trunk", 140 new ScmBranch("my-test-branch"), 141 null, 142 endDate, 143 "svn --non-interactive log -v http://foo.com/svn/branches/my-test-branch@ http://foo.com/svn/trunk@"); 144 } 145 146 @Test 147 public void testCommandLineWithBranchBothDates() throws Exception { 148 Date startDate = getDate(2003, Calendar.SEPTEMBER, 10, GMT_TIME_ZONE); 149 Date endDate = getDate(2003, Calendar.OCTOBER, 10, GMT_TIME_ZONE); 150 151 testCommandLine( 152 "scm:svn:http://foo.com/svn/trunk", 153 new ScmBranch("my-test-branch"), 154 startDate, 155 endDate, 156 "svn --non-interactive log -v -r \"{2003-09-10 00:00:00 +0000}:{2003-10-10 00:00:00 +0000}\" http://foo.com/svn/branches/my-test-branch@ http://foo.com/svn/trunk@"); 157 } 158 159 @Test 160 public void testCommandLineWithStartVersion() throws Exception { 161 testCommandLine( 162 "scm:svn:http://foo.com/svn/trunk", 163 new ScmRevision("1"), 164 null, 165 "svn --non-interactive log -v -r 1:HEAD http://foo.com/svn/trunk@"); 166 } 167 168 @Test 169 public void testCommandLineWithStartVersionAndEndVersion() throws Exception { 170 testCommandLine( 171 "scm:svn:http://foo.com/svn/trunk", 172 new ScmRevision("1"), 173 new ScmRevision("10"), 174 "svn --non-interactive log -v -r 1:10 http://foo.com/svn/trunk@"); 175 } 176 177 @Test 178 public void testCommandLineWithStartVersionAndEndVersionEquals() throws Exception { 179 testCommandLine( 180 "scm:svn:http://foo.com/svn/trunk", 181 new ScmRevision("1"), 182 new ScmRevision("1"), 183 "svn --non-interactive log -v -r 1 http://foo.com/svn/trunk@"); 184 } 185 186 @Test 187 public void testCommandLineWithBaseVersion() throws Exception { 188 testCommandLine( 189 "scm:svn:http://foo.com/svn/trunk", 190 new ScmRevision("1"), 191 new ScmRevision("BASE"), 192 "svn --non-interactive log -v -r 1:BASE"); 193 } 194 195 // ---------------------------------------------------------------------- 196 // 197 // ---------------------------------------------------------------------- 198 199 private void testCommandLine(String scmUrl, ScmBranch branch, Date startDate, Date endDate, String commandLine) 200 throws Exception { 201 testCommandLine(scmUrl, branch, startDate, endDate, null, commandLine); 202 } 203 204 private void testCommandLine( 205 String scmUrl, ScmBranch branch, Date startDate, Date endDate, Integer limit, String commandLine) 206 throws Exception { 207 File workingDirectory = getTestFile("target/svn-update-command-test"); 208 209 ScmRepository repository = getScmManager().makeScmRepository(scmUrl); 210 211 SvnScmProviderRepository svnRepository = (SvnScmProviderRepository) repository.getProviderRepository(); 212 213 Commandline cl = SvnChangeLogCommand.createCommandLine( 214 svnRepository, workingDirectory, branch, startDate, endDate, null, null, limit); 215 216 assertCommandLine(commandLine, workingDirectory, cl); 217 } 218 219 private void testCommandLine(String scmUrl, ScmVersion startVersion, ScmVersion endVersion, String commandLine) 220 throws Exception { 221 File workingDirectory = getTestFile("target/svn-update-command-test"); 222 223 ScmRepository repository = getScmManager().makeScmRepository(scmUrl); 224 225 SvnScmProviderRepository svnRepository = (SvnScmProviderRepository) repository.getProviderRepository(); 226 227 Commandline cl = SvnChangeLogCommand.createCommandLine( 228 svnRepository, workingDirectory, null, null, null, startVersion, endVersion); 229 assertCommandLine(commandLine, workingDirectory, cl); 230 } 231}