View Javadoc
1   package org.apache.maven.scm.provider.jazz.command.checkin;
2   
3   import org.apache.maven.scm.ScmFileSet;
4   import org.apache.maven.scm.log.DefaultLog;
5   import org.apache.maven.scm.provider.jazz.JazzScmTestCase;
6   import org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository;
7   import org.codehaus.plexus.util.cli.Commandline;
8   
9   /*
10   * Licensed to the Apache Software Foundation (ASF) under one
11   * or more contributor license agreements.  See the NOTICE file
12   * distributed with this work for additional information
13   * regarding copyright ownership.  The ASF licenses this file
14   * to you under the Apache License, Version 2.0 (the
15   * "License"); you may not use this file except in compliance
16   * with the License.  You may obtain a copy of the License at
17   *
18   * http://www.apache.org/licenses/LICENSE-2.0
19   *
20   * Unless required by applicable law or agreed to in writing,
21   * software distributed under the License is distributed on an
22   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23   * KIND, either express or implied.  See the License for the
24   * specific language governing permissions and limitations
25   * under the License.
26   */
27  
28  /**
29   * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
30   */
31  public class JazzCheckInCommandTest
32      extends JazzScmTestCase
33  {
34      private JazzScmProviderRepository repo;
35  
36      private JazzCheckInConsumer checkinConsumer;
37  
38      protected void setUp()
39          throws Exception
40      {
41          super.setUp();
42  
43          repo = getScmProviderRepository();
44  
45          checkinConsumer = new JazzCheckInConsumer( repo, new DefaultLog() );
46      }
47  
48      public void testCreateCreateChangesetCommand()
49          throws Exception
50      {
51          JazzScmProviderRepository repo = getScmProviderRepository();
52          Commandline cmd = new JazzCheckInCommand().createCreateChangesetCommand( repo, getScmFileSet(),
53                                                                                   "This is my comment." ).getCommandline();
54          String expected = "scm create changeset --username myUserName --password myPassword \"This is my comment.\"";
55          assertCommandLine( expected, getWorkingDirectory(), cmd );
56      }
57  
58      public void testCreateCheckInCommandCheckingInSpecificFiles()
59          throws Exception
60      {
61          JazzScmProviderRepository repo = getScmProviderRepository();
62          Commandline cmd = new JazzCheckInCommand().createCheckInCommand( repo, getScmFileSet() ).getCommandline();
63          String expected = "scm checkin --username myUserName --password myPassword " + getFiles();
64          assertCommandLine( expected, getWorkingDirectory(), cmd );
65      }
66  
67      public void testCreateCheckInCommandCheckingInLocalChanges()
68          throws Exception
69      {
70          JazzScmProviderRepository repo = getScmProviderRepository();
71          Commandline cmd = new JazzCheckInCommand().createCheckInCommand( repo, new ScmFileSet(
72              getWorkingDirectory() ) ).getCommandline();
73          String expected = "scm checkin --username myUserName --password myPassword .";
74          assertCommandLine( expected, getWorkingDirectory(), cmd );
75      }
76  
77      public void testCheckInConsumerWithFiles()
78          throws Exception
79      {
80          checkinConsumer.consumeLine( "Committing..." );
81          checkinConsumer.consumeLine(
82              "Workspace: (1903) \"MavenSCMTestWorkspace_1332908068770\" <-> (1903) \"MavenSCMTestWorkspace_1332908068770\"" );
83          checkinConsumer.consumeLine( "  Component: (1768) \"MavenSCMTestComponent\"" );
84          checkinConsumer.consumeLine( "    Outgoing:" );
85          checkinConsumer.consumeLine( "      Change sets:" );
86          checkinConsumer.consumeLine( "        (1907)  *--@  \"Commit message\"" );
87          checkinConsumer.consumeLine( "          Changes:" );
88          checkinConsumer.consumeLine( "            --a-- \\src\\main\\java\\Me.java" );
89          checkinConsumer.consumeLine( "            --a-- \\src\\main\\java\\Me1.java" );
90          checkinConsumer.consumeLine( "            --a-- \\src\\main\\java\\Me2.java" );
91  
92          assertEquals( "Wrong number of files parsed!", 3, checkinConsumer.getFiles().size() );
93          assertEquals( "Parsing error for file1!", "src\\main\\java\\Me.java",
94                        checkinConsumer.getFiles().get( 0 ).getPath() );
95          assertEquals( "Parsing error for file2!", "src\\main\\java\\Me1.java",
96                        checkinConsumer.getFiles().get( 1 ).getPath() );
97          assertEquals( "Parsing error for file3!", "src\\main\\java\\Me2.java",
98                        checkinConsumer.getFiles().get( 2 ).getPath() );
99      }
100 
101     public void testCheckInConsumerWithOutFiles()
102         throws Exception
103     {
104         checkinConsumer.consumeLine( "Committing..." );
105         checkinConsumer.consumeLine(
106             "Workspace: (1004) \"Release Repository Workspace\" <-> (1005) \"Maven Release Plugin Stream\"" );
107         checkinConsumer.consumeLine( "  Component: (1006) \"Release Component\"" );
108         checkinConsumer.consumeLine( "    Outgoing:" );
109         checkinConsumer.consumeLine( "      Change sets:" );
110         checkinConsumer.consumeLine( "        (1008) --@ <No comment>" );
111 
112         assertEquals( "Wrong number of files parsed!", 0, checkinConsumer.getFiles().size() );
113     }
114 }