001package org.apache.maven.scm.provider.perforce.command.status;
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.ScmTestCase;
025
026import java.io.BufferedReader;
027import java.io.File;
028import java.io.FileInputStream;
029import java.io.InputStreamReader;
030import java.util.List;
031
032/**
033 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse </a>
034 * @version $Id: PerforceChangeLogConsumerTest.java 331276 2005-11-07 15:04:54Z
035 *          evenisse $
036 */
037public class PerforceStatusConsumerTest
038    extends ScmTestCase
039{
040    public void testGoodParse()
041        throws Exception
042    {
043        File testFile = getTestFile( "src/test/resources/perforce/status_good.txt" );
044
045        PerforceStatusConsumer consumer = new PerforceStatusConsumer();
046
047        FileInputStream fis = new FileInputStream( testFile );
048        BufferedReader in = new BufferedReader( new InputStreamReader( fis ) );
049        String s = in.readLine();
050        while ( s != null )
051        {
052            consumer.consumeLine( s );
053            s = in.readLine();
054        }
055
056        assertEquals( "", consumer.getOutput() );
057        assertTrue( consumer.isSuccess() );
058        List<String> results = consumer.getDepotfiles();
059        assertEquals( "Wrong number of entries returned", 4, results.size() );
060        String entry = (String) results.get( 0 );
061        assertEquals( 33, entry.indexOf( "Foo.java" ) );
062
063        List<ScmFile> scmFiles = PerforceStatusCommand.createResults( "//depot/sandbox/mperham/scm-test", consumer );
064        assertEquals( 4, results.size() );
065        ScmFile file = scmFiles.get( 0 );
066        assertEquals( "Foo.java", file.getPath() );
067        assertEquals( ScmFileStatus.ADDED, file.getStatus() );
068    }
069}