001package org.apache.maven.scm.provider.starteam.command.changelog;
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.ChangeSet;
023import org.apache.maven.scm.ScmTestCase;
024import org.apache.maven.scm.log.DefaultLog;
025import org.apache.maven.scm.util.ConsumerUtils;
026
027import java.io.File;
028import java.util.Iterator;
029import java.util.List;
030import java.util.Locale;
031
032/**
033 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
034 *
035 */
036public class StarteamChangeLogConsumerTest
037    extends ScmTestCase
038{
039    private File testFile;
040
041    public void setUp()
042        throws Exception
043    {
044        super.setUp();
045
046        String language = Locale.getDefault().getLanguage();
047
048        testFile = getTestFile( "/src/test/resources/starteam/changelog/starteamlog_" + language + ".txt" );
049
050        if ( !testFile.exists() )
051        {
052            testFile = getTestFile( "/src/test/resources/starteam/changelog/starteamlog_en.txt" );
053        }
054    }
055
056    private List<ChangeSet> parseTestFile()
057        throws Exception
058    {
059        /* must match the working directory in the text test file */
060
061        File basedir = new File( "C:/Test" );
062
063        StarteamChangeLogConsumer consumer =
064            new StarteamChangeLogConsumer( basedir, new DefaultLog(), null, null, null );
065
066        ConsumerUtils.consumeFile( testFile, consumer );
067
068        return consumer.getModifications();
069    }
070
071    public void testNumberOfModifications()
072        throws Exception
073    {
074        List<ChangeSet> entries = parseTestFile();
075
076        assertEquals( "Wrong number of entries returned", 6, entries.size() );
077
078        for ( Iterator<ChangeSet> i = entries.iterator(); i.hasNext(); )
079        {
080            assertTrue( "ChangeLogEntry erroneously picked up",
081                        i.next().toString().indexOf( "ChangeLogEntry.java" ) == -1 );
082        }
083    }
084
085    public void testRelativeFilePath()
086        throws Exception
087    {
088        List<ChangeSet> entries = parseTestFile();
089
090        // ensure the filename in the first ChangeSet has correct relative path
091        ChangeSet entry = (ChangeSet) entries.get( 1 );
092
093        assertTrue( entry.containsFilename( "./maven/src/File2.java" ));
094    }
095
096    public void testLocales()
097        throws Exception
098    {
099        Locale currentLocale = Locale.getDefault();
100
101        Locale[] availableLocales = Locale.getAvailableLocales();
102        try
103        {
104            for ( int i = 0; i < availableLocales.length; i++ )
105            {
106                Locale.setDefault( availableLocales[i] );
107
108                String language = availableLocales[i].getLanguage();
109
110                testFile = getTestFile( "/src/test/resources/starteam/changelog/starteamlog_" + language + ".txt" );
111
112                if ( !testFile.exists() )
113                {
114                    testFile = getTestFile( "/src/test/resources/starteam/changelog/starteamlog_en.txt" );
115                }
116
117                parseTestFile();
118            }
119        }
120        finally
121        {
122            Locale.setDefault( currentLocale );
123        }
124    }
125}