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 testCreateChangesetAssociateCommand() 059 throws Exception 060 { 061 JazzScmProviderRepository repo = getScmProviderRepository(); 062 // Populate the values that are normally parsed and set by the StatusConsumer. 063 repo.setWorkItem( "215762" ); 064 Commandline cmd = new JazzCheckInCommand().createChangesetAssociateCommand( repo, new Integer(1234) ).getCommandline(); 065 // Because we do not use a ScmFileSet, the working dir is not set, so the test fails. 066 cmd.setWorkingDirectory( getWorkingDirectory() ); 067 String expected = "scm changeset associate --username myUserName --password myPassword 1234 215762"; 068 assertCommandLine( expected, getWorkingDirectory(), cmd ); 069 } 070 071 public void testCreateCheckInCommandCheckingInSpecificFiles() 072 throws Exception 073 { 074 JazzScmProviderRepository repo = getScmProviderRepository(); 075 Commandline cmd = new JazzCheckInCommand().createCheckInCommand( repo, getScmFileSet() ).getCommandline(); 076 String expected = "scm checkin --username myUserName --password myPassword " + getFiles(); 077 assertCommandLine( expected, getWorkingDirectory(), cmd ); 078 } 079 080 public void testCreateCheckInCommandCheckingInLocalChanges() 081 throws Exception 082 { 083 JazzScmProviderRepository repo = getScmProviderRepository(); 084 Commandline cmd = new JazzCheckInCommand().createCheckInCommand( repo, new ScmFileSet( 085 getWorkingDirectory() ) ).getCommandline(); 086 String expected = "scm checkin --username myUserName --password myPassword ."; 087 assertCommandLine( expected, getWorkingDirectory(), cmd ); 088 } 089 090 public void testCheckInConsumerWithFiles() 091 throws Exception 092 { 093 checkinConsumer.consumeLine( "Committing..." ); 094 checkinConsumer.consumeLine( 095 "Workspace: (1903) \"MavenSCMTestWorkspace_1332908068770\" <-> (1903) \"MavenSCMTestWorkspace_1332908068770\"" ); 096 checkinConsumer.consumeLine( " Component: (1768) \"MavenSCMTestComponent\"" ); 097 checkinConsumer.consumeLine( " Outgoing:" ); 098 checkinConsumer.consumeLine( " Change sets:" ); 099 checkinConsumer.consumeLine( " (1907) *--@ \"Commit message\"" ); 100 checkinConsumer.consumeLine( " Changes:" ); 101 checkinConsumer.consumeLine( " --a-- \\src\\main\\java\\Me.java" ); 102 checkinConsumer.consumeLine( " --a-- \\src\\main\\java\\Me1.java" ); 103 checkinConsumer.consumeLine( " --a-- \\src\\main\\java\\Me2.java" ); 104 105 assertEquals( "Wrong number of files parsed!", 3, checkinConsumer.getFiles().size() ); 106 assertEquals( "Parsing error for file1!", "src\\main\\java\\Me.java", 107 checkinConsumer.getFiles().get( 0 ).getPath() ); 108 assertEquals( "Parsing error for file2!", "src\\main\\java\\Me1.java", 109 checkinConsumer.getFiles().get( 1 ).getPath() ); 110 assertEquals( "Parsing error for file3!", "src\\main\\java\\Me2.java", 111 checkinConsumer.getFiles().get( 2 ).getPath() ); 112 } 113 114 public void testCheckInConsumerWithOutFiles() 115 throws Exception 116 { 117 checkinConsumer.consumeLine( "Committing..." ); 118 checkinConsumer.consumeLine( 119 "Workspace: (1004) \"Release Repository Workspace\" <-> (1005) \"Maven Release Plugin Stream\"" ); 120 checkinConsumer.consumeLine( " Component: (1006) \"Release Component\"" ); 121 checkinConsumer.consumeLine( " Outgoing:" ); 122 checkinConsumer.consumeLine( " Change sets:" ); 123 checkinConsumer.consumeLine( " (1008) --@ <No comment>" ); 124 125 assertEquals( "Wrong number of files parsed!", 0, checkinConsumer.getFiles().size() ); 126 } 127}