001package org.apache.maven.scm.provider.jazz.command.checkin;
002
003import org.apache.maven.scm.ScmFileSet;
004import org.apache.maven.scm.log.DefaultLog;
005import org.apache.maven.scm.provider.jazz.JazzScmTestCase;
006import org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository;
007import org.codehaus.plexus.util.cli.Commandline;
008
009/*
010 * Licensed to the Apache Software Foundation (ASF) under one
011 * or more contributor license agreements.  See the NOTICE file
012 * distributed with this work for additional information
013 * regarding copyright ownership.  The ASF licenses this file
014 * to you under the Apache License, Version 2.0 (the
015 * "License"); you may not use this file except in compliance
016 * with the License.  You may obtain a copy of the License at
017 *
018 * http://www.apache.org/licenses/LICENSE-2.0
019 *
020 * Unless required by applicable law or agreed to in writing,
021 * software distributed under the License is distributed on an
022 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
023 * KIND, either express or implied.  See the License for the
024 * specific language governing permissions and limitations
025 * under the License.
026 */
027
028/**
029 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
030 */
031public class JazzCheckInCommandTest
032    extends JazzScmTestCase
033{
034    private JazzScmProviderRepository repo;
035
036    private JazzCheckInConsumer checkinConsumer;
037
038    protected void setUp()
039        throws Exception
040    {
041        super.setUp();
042
043        repo = getScmProviderRepository();
044
045        checkinConsumer = new JazzCheckInConsumer( repo, new DefaultLog() );
046    }
047
048    public void testCreateCreateChangesetCommand()
049        throws Exception
050    {
051        JazzScmProviderRepository repo = getScmProviderRepository();
052        Commandline cmd = new JazzCheckInCommand().createCreateChangesetCommand( repo, getScmFileSet(),
053                                                                                 "This is my comment." ).getCommandline();
054        String expected = "scm create changeset --username myUserName --password myPassword \"This is my comment.\"";
055        assertCommandLine( expected, getWorkingDirectory(), cmd );
056    }
057
058    public void testCreateCheckInCommandCheckingInSpecificFiles()
059        throws Exception
060    {
061        JazzScmProviderRepository repo = getScmProviderRepository();
062        Commandline cmd = new JazzCheckInCommand().createCheckInCommand( repo, getScmFileSet() ).getCommandline();
063        String expected = "scm checkin --username myUserName --password myPassword " + getFiles();
064        assertCommandLine( expected, getWorkingDirectory(), cmd );
065    }
066
067    public void testCreateCheckInCommandCheckingInLocalChanges()
068        throws Exception
069    {
070        JazzScmProviderRepository repo = getScmProviderRepository();
071        Commandline cmd = new JazzCheckInCommand().createCheckInCommand( repo, new ScmFileSet(
072            getWorkingDirectory() ) ).getCommandline();
073        String expected = "scm checkin --username myUserName --password myPassword .";
074        assertCommandLine( expected, getWorkingDirectory(), cmd );
075    }
076
077    public void testCheckInConsumerWithFiles()
078        throws Exception
079    {
080        checkinConsumer.consumeLine( "Committing..." );
081        checkinConsumer.consumeLine(
082            "Workspace: (1903) \"MavenSCMTestWorkspace_1332908068770\" <-> (1903) \"MavenSCMTestWorkspace_1332908068770\"" );
083        checkinConsumer.consumeLine( "  Component: (1768) \"MavenSCMTestComponent\"" );
084        checkinConsumer.consumeLine( "    Outgoing:" );
085        checkinConsumer.consumeLine( "      Change sets:" );
086        checkinConsumer.consumeLine( "        (1907)  *--@  \"Commit message\"" );
087        checkinConsumer.consumeLine( "          Changes:" );
088        checkinConsumer.consumeLine( "            --a-- \\src\\main\\java\\Me.java" );
089        checkinConsumer.consumeLine( "            --a-- \\src\\main\\java\\Me1.java" );
090        checkinConsumer.consumeLine( "            --a-- \\src\\main\\java\\Me2.java" );
091
092        assertEquals( "Wrong number of files parsed!", 3, checkinConsumer.getFiles().size() );
093        assertEquals( "Parsing error for file1!", "src\\main\\java\\Me.java",
094                      checkinConsumer.getFiles().get( 0 ).getPath() );
095        assertEquals( "Parsing error for file2!", "src\\main\\java\\Me1.java",
096                      checkinConsumer.getFiles().get( 1 ).getPath() );
097        assertEquals( "Parsing error for file3!", "src\\main\\java\\Me2.java",
098                      checkinConsumer.getFiles().get( 2 ).getPath() );
099    }
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}