1   package org.apache.maven.scm.provider.starteam.command.checkin;
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.ScmFileSet;
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.starteam.command.StarteamCommandLineUtils;
27  import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
28  import org.apache.maven.scm.repository.ScmRepository;
29  import org.codehaus.plexus.util.cli.Commandline;
30  
31  import java.io.File;
32  
33  /**
34   * @author <a href="mailto:dantran@gmail.com">Dan T. Tran</a>
35   */
36  public class StarteamCheckInCommandTest
37      extends ScmTestCase
38  {
39  
40      public void testGetCommandLineWithWorkingDirectory()
41          throws Exception
42      {
43          ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
44  
45          String workingCopy = StarteamCommandLineUtils.toJavaPath( getWorkingCopy().getPath() );
46  
47          String starteamUrl = "user:password@host:1234/project/view";
48          String mavenUrl = "scm:starteam:" + starteamUrl;
49  
50          String expectedCmd =
51              "stcmd ci -x -nologo -stop" + " -p " + starteamUrl + " -fp " + workingCopy + " -is -f NCI -eol on";
52  
53          testCommandLine( mavenUrl, fileSet, "", new ScmRevision( "" ), "", "", expectedCmd );
54  
55      }
56  
57      public void testGetCommandLineWithFileOnRoot()
58          throws Exception
59      {
60          ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( "test.txt" ) );
61  
62          String workingCopy = StarteamCommandLineUtils.toJavaPath( getWorkingCopy().getPath() );
63  
64          String starteamUrl = "user:password@host:1234/project/view";
65          String mavenUrl = "scm:starteam:" + starteamUrl;
66  
67          String expectedCmd =
68              "stcmd ci -x -nologo -stop" + " -p " + starteamUrl + " -fp " + workingCopy + " -eol on test.txt";
69  
70          testCommandLine( mavenUrl, fileSet, "", new ScmRevision( "" ), "", "", expectedCmd );
71  
72      }
73  
74      public void testGetCommandLineWithFileInSubDir()
75          throws Exception
76      {
77          ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( "src/test.txt" ) );
78  
79          String workingCopy = StarteamCommandLineUtils.toJavaPath( getWorkingCopy().getPath() );
80  
81          String starteamUrl = "user:password@host:1234/project/view";
82          String mavenUrl = "scm:starteam:" + starteamUrl;
83  
84          String expectedCmd = "stcmd ci -x -nologo -stop" + " -p " + starteamUrl + "/src" + " -fp " + workingCopy +
85              "/src" + " -eol on test.txt";
86  
87          testCommandLine( mavenUrl, fileSet, "", new ScmRevision( "" ), "", "", expectedCmd );
88  
89      }
90  
91      public void testGetCommandLineWithDirInWorkingDirectory()
92          throws Exception
93      {
94          //physically create dir so that cmd can be generated correctly
95          new File( getWorkingCopy(), "src" ).mkdirs();
96  
97          ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( "src" ) );
98  
99          String workingCopy = StarteamCommandLineUtils.toJavaPath( getWorkingCopy().getPath() );
100 
101         String starteamUrl = "user:password@host:1234/project/view";
102         String mavenUrl = "scm:starteam:" + starteamUrl;
103 
104         String expectedCmd = "stcmd ci -x -nologo -stop" + " -p " + starteamUrl + "/src" + " -fp " + workingCopy +
105             "/src" + " -is -f NCI -eol on";
106 
107         testCommandLine( mavenUrl, fileSet, "", new ScmRevision( "" ), "", "", expectedCmd );
108 
109     }
110 
111     public void testGetCommandLineWithEmptyIssueValue()
112         throws Exception
113     {
114         ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( "test.txt" ) );
115 
116         String workingCopy = StarteamCommandLineUtils.toJavaPath( getWorkingCopy().getPath() );
117 
118         String starteamUrl = "user:password@host:1234/project/view";
119         String mavenUrl = "scm:starteam:" + starteamUrl;
120 
121         String expectedCmd =
122             "stcmd ci -x -nologo -stop" + " -p " + starteamUrl + " -fp " + workingCopy + " -active -eol on test.txt";
123 
124         testCommandLine( mavenUrl, fileSet, null, new ScmRevision( "" ), "active", " ", expectedCmd );
125     }
126 // ----------------------------------------------------------------------
127 //
128 // ----------------------------------------------------------------------
129 
130     private void testCommandLine( String scmUrl, ScmFileSet fileSet, String message, ScmVersion version,
131                                   String issueType, String issueValue, String commandLine )
132         throws Exception
133     {
134         ScmRepository repo = getScmManager().makeScmRepository( scmUrl );
135 
136         StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo.getProviderRepository();
137 
138         Commandline cl =
139             StarteamCheckInCommand.createCommandLine( repository, fileSet, message, version, issueType, issueValue );
140 
141         assertCommandLine( commandLine, null, cl );
142     }
143 
144 
145 }