1   package org.apache.maven.mkslib;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  
22  import junit.framework.TestCase;
23  
24  import org.apache.maven.changelog.ChangeLog;
25  import org.apache.maven.changelog.ChangeLogEntry;
26  
27  import java.io.FileInputStream;
28  import java.io.IOException;
29  
30  import java.util.Collection;
31  import java.util.Date;
32  import java.util.Iterator;
33  import java.util.Locale;
34  
35  /**
36   * This class test the mks parser with an inputstream.
37   *
38   * @author dion (writes CvsChangeLogParserTest)
39   * @author <a href="mailto:c.jerolimov@tarent.de">Christoph Jerolimov</a>
40   * @version $Id: MksChangeLogParserTest.java 532339 2007-04-25 12:28:56Z ltheussl $
41   */
42  public class MksChangeLogParserTest extends TestCase
43  {
44      /** the {link ChangeLog} used for testing */
45      private ChangeLog changeLog;
46  
47      /** the {@link MksChangeLogParser} used for testing */
48      private MksChangeLogParser instance;
49  
50      /** file with test results to check against */
51      private String testFile;
52  
53      /**
54       * Create a test with the given name
55       * @param testName the name of the test
56       */
57      public MksChangeLogParserTest( String testName )
58      {
59          super( testName );
60      }
61  
62      /**
63       * Initialize per test data
64       * @throws Exception when there is an unexpected problem
65       */
66      public void setUp() throws Exception
67      {
68          // We force the german locale
69          // because the test file uses it.
70          Locale.setDefault(Locale.GERMAN);
71          String baseDir = System.getProperty( "basedir" );
72          if (baseDir == null)
73              baseDir = "/home/christoph/workspace/changelog";
74  
75          assertNotNull( "The system property basedir was not defined.", baseDir );
76          testFile = baseDir + "/src/test-resources/mkslib/mkslog.txt";
77          
78          System.out.println(new Date());
79          
80          changeLog = new ChangeLog();
81          changeLog.setType("date");
82          changeLog.setMarkerStart("2006-01-15");
83          changeLog.setMarkerEnd("2006-01-31");
84          
85          instance = new MksChangeLogParser();
86          instance.init( changeLog );
87      }
88  
89      /**
90       * Test the mks parser.
91       * @throws IOException when there is an unexpected problem
92       */
93      public void testParser()
94          throws IOException
95      {
96          FileInputStream fis = new FileInputStream( testFile );
97          Collection entries = instance.parse( fis );
98  
99          assertEquals( "Wrong number of entries returned", 3, entries.size() );
100 
101         ChangeLogEntry entry = null;
102 
103         for ( Iterator i = entries.iterator(); i.hasNext(); )
104         {
105             entry = (ChangeLogEntry) i.next();
106             assertEquals( "Wrong author parsed", "AUTHOR", entry.getAuthor() );
107             System.out.println( entry );
108             assertTrue( "ChangeLogEntry erroneously picked up",
109                 entry.toString().indexOf( "ChangeLogEntry.java" ) == -1 );
110         }
111     }
112 }