001package org.apache.maven.scm.provider.jazz.command.checkout;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.scm.ScmFile;
023import org.apache.maven.scm.ScmFileStatus;
024import org.apache.maven.scm.ScmRevision;
025import org.apache.maven.scm.log.DefaultLog;
026import org.apache.maven.scm.provider.jazz.JazzScmTestCase;
027import org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository;
028import org.codehaus.plexus.util.cli.Commandline;
029
030import java.util.List;
031
032/**
033 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
034 */
035public class JazzCheckOutCommandTest
036    extends JazzScmTestCase
037{
038    private JazzScmProviderRepository repo;
039
040    private JazzCheckOutConsumer checkOutConsumer;
041
042    protected void setUp()
043        throws Exception
044    {
045        super.setUp();
046        repo = getScmProviderRepository();
047        checkOutConsumer = new JazzCheckOutConsumer( getScmProviderRepository(), new DefaultLog() );
048    }
049
050    public void testCreateJazzLoadCommand()
051        throws Exception
052    {
053        ScmRevision rev = new ScmRevision( "revision" );
054        // TODO figure out what Jazz SCM does in terms of branch/tag/revision
055        // TODO figure out how/when to load specific files
056        Commandline cmd =
057            new JazzCheckOutCommand().createJazzLoadCommand( repo, getScmFileSet(), rev ).getCommandline();
058        String expected =
059            "scm load --force --repository-uri https://localhost:9443/jazz --username myUserName --password myPassword --dir "
060                + getScmFileSet().getBasedir().getAbsolutePath() + " \"Dave's Repository Workspace\"";
061        assertCommandLine( expected, getWorkingDirectory(), cmd );
062    }
063
064    public void testConsumer()
065    {
066        checkOutConsumer.consumeLine(
067            "Downloading /maven-checkout-test/src/main/java/org/apache/maven/scm/provider/jazz/EmptyFile.txt  (0 B)" );
068        checkOutConsumer.consumeLine(
069            "Downloading /maven-checkout-test/src/main/java/org/apache/maven/scm/provider/jazz/folder with spaces/test.java  (123 KB)" );
070        checkOutConsumer.consumeLine(
071            "Downloading /maven-checkout-test/src/main/java/org/apache/maven/scm/provider/jazz/file with spaces.java  (12.34 KB)" );
072        checkOutConsumer.consumeLine(
073            "Downloading /maven-checkout-test/src/main/java/org/apache/maven/scm/provider/jazz/folder with spaces/file with spaces.txt  (12.3 B)" );
074        checkOutConsumer.consumeLine( "" );
075
076        List<ScmFile> checkedOutFiles = checkOutConsumer.getCheckedOutFiles();
077        assertNotNull( checkedOutFiles );
078        assertEquals( 4, checkedOutFiles.size() );
079        assertTrue( checkedOutFiles.contains(
080            new ScmFile( "/maven-checkout-test/src/main/java/org/apache/maven/scm/provider/jazz/EmptyFile.txt",
081                         ScmFileStatus.CHECKED_OUT ) ) );
082        assertTrue( checkedOutFiles.contains( new ScmFile(
083            "/maven-checkout-test/src/main/java/org/apache/maven/scm/provider/jazz/folder with spaces/test.java",
084            ScmFileStatus.CHECKED_OUT ) ) );
085        assertTrue( checkedOutFiles.contains(
086            new ScmFile( "/maven-checkout-test/src/main/java/org/apache/maven/scm/provider/jazz/file with spaces.java",
087                         ScmFileStatus.CHECKED_OUT ) ) );
088        assertTrue( checkedOutFiles.contains( new ScmFile(
089            "/maven-checkout-test/src/main/java/org/apache/maven/scm/provider/jazz/folder with spaces/file with spaces.txt",
090            ScmFileStatus.CHECKED_OUT ) ) );
091    }
092}