1   package org.apache.maven.clearcaselib;
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  import java.io.FileInputStream;
22  import java.util.Collection;
23  import java.util.Iterator;
24  import junit.framework.TestCase;
25  
26  import org.apache.maven.changelog.ChangeLogEntry;
27  
28  /**
29   */
30  public class ClearcaseChangeLogParserTest extends TestCase {
31  
32      /** the {@link ClearcaseChangeLogParser}used for testing */
33      private ClearcaseChangeLogParser instance;
34  
35      /** file with test results to check against */
36      private String testFile;
37  
38      /**
39       * Create a test with the given name
40       * 
41       * @param testName
42       *            the name of the test
43       */
44      public ClearcaseChangeLogParserTest(String testName) {
45          super(testName);
46      }
47  
48      /**
49       * Initialize per test data
50       * 
51       * @throws Exception
52       *             when there is an unexpected problem
53       */
54      public void setUp() throws Exception {
55          String baseDir = System.getProperty("basedir");
56          assertNotNull("The system property basedir was not defined.", baseDir);
57          testFile = baseDir
58                  + "/src/test-resources/clearcaselib/clearcaselog.txt";
59          instance = new ClearcaseChangeLogParser();
60      }
61  
62      /**
63       * Test of parse method
64       * 
65       * @throws Exception
66       *             when there is an unexpected problem
67       */
68      public void testParse() throws Exception {
69          FileInputStream fis = new FileInputStream(testFile);
70          Collection entries = instance.parse(fis);
71          assertEquals("Wrong number of entries returned", 3, entries.size());
72          ChangeLogEntry entry = null;
73          for (Iterator i = entries.iterator(); i.hasNext();) {
74              entry = (ChangeLogEntry) i.next();
75              assertTrue("ChangeLogEntry erroneously picked up", entry.toString()
76                      .indexOf("ChangeLogEntry.java") == -1);
77          }
78  
79      }
80  
81      public void testParseCorrectUsername() throws Exception {
82  
83          // parse the test file
84          FileInputStream fis = new FileInputStream(testFile);
85          Collection entries = instance.parse(fis);
86  
87          // check 8 char usernames are parsed correctly
88          Iterator i = entries.iterator();
89          ChangeLogEntry entry = (ChangeLogEntry) i.next();
90          assertEquals("exactly 8 chars expected", "88888888", entry.getAuthor());
91  
92          // check < 8 char usernames are parsed correctly
93          entry = (ChangeLogEntry) i.next();
94          assertEquals("exactly 5 chars expected", "55555", entry.getAuthor());
95  
96  
97      }
98  
99      // Add test methods here, they have to start with 'test' name.
100     // for example:
101     // public void testHello() {}
102 
103 }