View Javadoc
1   package org.apache.maven.scm.provider.starteam.command.add;
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.ScmTestCase;
24  import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils;
25  import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
26  import org.apache.maven.scm.repository.ScmRepository;
27  import org.codehaus.plexus.util.cli.Commandline;
28  
29  import java.io.File;
30  
31  /**
32   * @author <a href="mailto:dantran@gmail.com">Dan T. Tran</a>
33   */
34  public class StarteamAddCommandTest
35      extends ScmTestCase
36  {
37  
38      public void testGetCommandLineWithFileOnRoot()
39          throws Exception
40      {
41  
42          File testFile = new File( "testfile" );
43  
44          File testFileDir = testFile.getAbsoluteFile().getParentFile();
45  
46          String testFileDirAbsolutePath = StarteamCommandLineUtils.toJavaPath( testFileDir.getAbsolutePath() );
47  
48          String expectedCmd = "stcmd add -x -nologo -stop -p myusername:mypassword@myhost:1234/projecturl" + " -fp " +
49              testFileDirAbsolutePath + " -eol on testfile";
50  
51          ScmFileSet fileSet = new ScmFileSet( testFileDir, testFile );
52          testCommandLine( "scm:starteam:myusername:mypassword@myhost:1234/projecturl", fileSet, "", expectedCmd );
53      }
54  
55      public void testGetCommandLineWithCR()
56          throws Exception
57      {
58          File testFile = new File( "testfile" );
59  
60          File testFileDir = testFile.getAbsoluteFile().getParentFile();
61  
62          String testFileDirAbsolutePath = StarteamCommandLineUtils.toJavaPath( testFileDir.getAbsolutePath() );
63  
64          String expectedCmd = "stcmd add -x -nologo -stop -p myusername:mypassword@myhost:1234/projecturl" + " -fp " +
65              testFileDirAbsolutePath + " -cr view_root/dummycr" + " -eol on testfile";
66  
67          ScmFileSet fileSet = new ScmFileSet( testFileDir, testFile );
68          testCommandLine( "scm:starteam:myusername:mypassword@myhost:1234/projecturl", fileSet, "view_root/dummycr",
69                           expectedCmd );
70  
71      }
72  
73      public void testGetCommandLineWithFileInSubDir()
74          throws Exception
75      {
76  
77          File testFile = new File( "target/testfile" );
78  
79          File testFileDir = testFile.getAbsoluteFile().getParentFile();
80  
81          String testFileDirAbsolutePath =
82              StarteamCommandLineUtils.toJavaPath( testFileDir.getAbsolutePath() ) + "/target";
83  
84          String expectedCmd = "stcmd add -x -nologo -stop -p myusername:mypassword@myhost:1234/projecturl/target" +
85              " -fp " + testFileDirAbsolutePath + " -eol on testfile";
86  
87          ScmFileSet fileSet = new ScmFileSet( testFileDir, testFile );
88          testCommandLine( "scm:starteam:myusername:mypassword@myhost:1234/projecturl", fileSet, null, expectedCmd );
89  
90      }
91  
92      // ----------------------------------------------------------------------
93      //
94      // ----------------------------------------------------------------------
95  
96      private void testCommandLine( String scmUrl, ScmFileSet fileSet, String crPath, String commandLine )
97          throws Exception
98      {
99          ScmRepository repo = getScmManager().makeScmRepository( scmUrl );
100 
101         StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo.getProviderRepository();
102 
103         Commandline cl = StarteamAddCommand.createCommandLine( repository, fileSet, crPath );
104 
105         assertCommandLine( commandLine, null, cl );
106     }
107 }