001package org.apache.maven.scm.provider.jazz.command.list;
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.log.DefaultLog;
025import org.apache.maven.scm.provider.jazz.JazzScmTestCase;
026import org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository;
027import org.codehaus.plexus.util.cli.Commandline;
028
029import java.util.List;
030
031/**
032 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
033 */
034public class JazzListCommandTest
035    extends JazzScmTestCase
036{
037    private JazzListConsumer listConsumer;
038
039    private JazzScmProviderRepository repo;
040
041    protected void setUp()
042        throws Exception
043    {
044        super.setUp();
045        repo = getScmProviderRepository();
046
047        listConsumer = new JazzListConsumer( getScmProviderRepository(), new DefaultLog() );
048
049        // Simulate the output of the parsing of the "scm status" command.
050        // IE, fill in the workspace and component details
051        // Needed for the remote workspace and component name for the list remotefiles
052        repo.setWorkspace( "Dave's Repository Workspace" );
053        repo.setComponent( "Dave's Component" );
054    }
055
056    public void testCreateListCommand()
057        throws Exception
058    {
059        Commandline cmd = new JazzListCommand().createListCommand( repo, getScmFileSet(), true, null ).getCommandline();
060        String expected =
061            "scm list remotefiles --repository-uri https://localhost:9443/jazz --username myUserName --password myPassword \"Dave's Repository Workspace\" \"Dave's Component\"";
062        assertCommandLine( expected, getWorkingDirectory(), cmd );
063    }
064
065    public void testConsumer()
066    {
067        listConsumer.consumeLine( "/" );
068        listConsumer.consumeLine( "/BogusTestJazz/" );
069        listConsumer.consumeLine( "/BogusTestJazz/.jazzignore" );
070        listConsumer.consumeLine( "/BogusTestJazz/pom.xml" );
071        listConsumer.consumeLine( "/BogusTestJazz/Readme.txt" );
072        listConsumer.consumeLine( "/BogusTestJazz/src/" );
073        listConsumer.consumeLine( "/BogusTestJazz/src/main/" );
074        listConsumer.consumeLine( "/BogusTestJazz/src/main/resources/" );
075        listConsumer.consumeLine( "/BogusTestJazz/src/main/resources/AFile.txt" );
076        listConsumer.consumeLine( "/BogusTestJazz/src/main/java/" );
077        listConsumer.consumeLine( "/BogusTestJazz/src/main/java/BogusTest.java" );
078
079        // Test the ScmFile and ScmFileStatus bits.
080        List<ScmFile> changedFiles = listConsumer.getFiles();
081        assertNotNull( changedFiles );
082        assertEquals( 11, changedFiles.size() );
083        assertTrue( changedFiles.contains( new ScmFile( "/", ScmFileStatus.CHECKED_IN ) ) );
084        assertTrue( changedFiles.contains( new ScmFile( "/BogusTestJazz/", ScmFileStatus.CHECKED_IN ) ) );
085        assertTrue( changedFiles.contains( new ScmFile( "/BogusTestJazz/.jazzignore", ScmFileStatus.CHECKED_IN ) ) );
086        assertTrue( changedFiles.contains( new ScmFile( "/BogusTestJazz/pom.xml", ScmFileStatus.CHECKED_IN ) ) );
087        assertTrue( changedFiles.contains( new ScmFile( "/BogusTestJazz/Readme.txt", ScmFileStatus.CHECKED_IN ) ) );
088        assertTrue( changedFiles.contains( new ScmFile( "/BogusTestJazz/src/", ScmFileStatus.CHECKED_IN ) ) );
089        assertTrue( changedFiles.contains( new ScmFile( "/BogusTestJazz/src/main/", ScmFileStatus.CHECKED_IN ) ) );
090        assertTrue(
091            changedFiles.contains( new ScmFile( "/BogusTestJazz/src/main/resources/", ScmFileStatus.CHECKED_IN ) ) );
092        assertTrue( changedFiles.contains(
093            new ScmFile( "/BogusTestJazz/src/main/resources/AFile.txt", ScmFileStatus.CHECKED_IN ) ) );
094        assertTrue( changedFiles.contains( new ScmFile( "/BogusTestJazz/src/main/java/", ScmFileStatus.CHECKED_IN ) ) );
095        assertTrue( changedFiles.contains(
096            new ScmFile( "/BogusTestJazz/src/main/java/BogusTest.java", ScmFileStatus.CHECKED_IN ) ) );
097    }
098
099}