710N/A/*
710N/A * CDDL HEADER START
710N/A *
710N/A * The contents of this file are subject to the terms of the
710N/A * Common Development and Distribution License (the "License").
710N/A * You may not use this file except in compliance with the License.
710N/A *
710N/A * See LICENSE.txt included in this distribution for the specific
710N/A * language governing permissions and limitations under the License.
710N/A *
710N/A * When distributing Covered Code, include this CDDL HEADER in each
710N/A * file and include the License file at LICENSE.txt.
710N/A * If applicable, add the following below this CDDL HEADER, with the
710N/A * fields enclosed by brackets "[]" replaced with your own identifying
710N/A * information: Portions Copyright [yyyy] [name of copyright owner]
710N/A *
710N/A * CDDL HEADER END
710N/A */
710N/A
710N/A/*
710N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
710N/A * Use is subject to license terms.
710N/A */
710N/Apackage org.opensolaris.opengrok.history;
710N/A
710N/Aimport org.junit.After;
710N/Aimport org.junit.AfterClass;
710N/Aimport org.junit.Before;
710N/Aimport org.junit.BeforeClass;
710N/Aimport org.junit.Test;
710N/Aimport static org.junit.Assert.*;
710N/A
710N/A/**
710N/A *
710N/A * @author austvik
710N/A */
710N/Apublic class CVSHistoryParserTest {
710N/A
710N/A CVSHistoryParser instance;
710N/A
710N/A public CVSHistoryParserTest() {
710N/A }
710N/A
710N/A @BeforeClass
710N/A public static void setUpClass() throws Exception {
710N/A }
710N/A
710N/A @AfterClass
710N/A public static void tearDownClass() throws Exception {
710N/A }
710N/A
710N/A @Before
710N/A public void setUp() {
710N/A instance = new CVSHistoryParser();
710N/A }
710N/A
710N/A @After
710N/A public void tearDown() {
710N/A instance = null;
710N/A }
710N/A
710N/A /**
710N/A * Test of parse method, of class CVSHistoryParser.
710N/A */
710N/A @Test
710N/A public void parseEmpty() throws Exception {
710N/A History result = instance.parse("");
710N/A assertNotNull(result);
710N/A assertTrue("Should not contain any history entries", 0 == result.getHistoryEntries().size());
710N/A }
710N/A
710N/A /**
710N/A * Parse something that could come out from the W3C public CVS repository
710N/A *
710N/A * @throws java.lang.Exception
710N/A */
710N/A @Test
710N/A public void parseALaW3C() throws Exception {
710N/A String revId1 = "1.2";
710N/A String revId2 = "1.2.4.5";
710N/A String revId3 = "1.134";
710N/A String author1 = "username";
710N/A String author2 = "username2";
710N/A String date1 = "2005-05-16 21:22:34 +0200";
710N/A String date2 = "2007-05-16 22:21:30 +0300";
710N/A String output = "\n" +
710N/A "\n" +
710N/A " RCS file: /some/file/name.ext,v\n" +
710N/A "Working file: name.ext\n" +
710N/A "head: 1.23\n" +
710N/A "branch:\n" +
710N/A "locks: strict\n" +
710N/A "access list:\n" +
710N/A "keyword substitution: kv\n" +
972N/A "total revisions: 4;\tselected revisions: 3\n" +
710N/A "description:\n" +
710N/A "----------------------------\n" +
710N/A "revision " + revId1 + "\n" +
710N/A "date: " + date1 + "; author: " + author1 + "; state: Exp; lines: +2 -2;\n" +
710N/A "a comment\n" +
710N/A "----------------------------\n" +
710N/A "revision " + revId2 + "\n" +
710N/A "date: " + date2 + "; author: " + author2 + "; state: Exp; lines: +2 -4;\n" +
710N/A "just a short comment\n" +
710N/A "----------------------------\n" +
710N/A "revision " + revId3 + "\n" +
710N/A "date: " + date1 + "; author: " + author1 + "; state: Exp; lines: +6 -2;\n" +
710N/A "some comment that is\n" +
710N/A "spanning two lines\n" +
710N/A "=============================================================================\n";
710N/A History result = instance.parse(output);
710N/A assertNotNull(result);
710N/A assertEquals(3, result.getHistoryEntries().size());
710N/A HistoryEntry e0 = result.getHistoryEntries().get(0);
710N/A assertEquals(revId1, e0.getRevision());
710N/A assertEquals(author1, e0.getAuthor());
710N/A assertEquals(0, e0.getFiles().size());
710N/A HistoryEntry e1 = result.getHistoryEntries().get(1);
710N/A assertEquals(revId2, e1.getRevision());
710N/A assertEquals(author2, e1.getAuthor());
710N/A assertEquals(0, e1.getFiles().size());
710N/A HistoryEntry e2 = result.getHistoryEntries().get(2);
710N/A assertEquals(revId3, e2.getRevision());
710N/A assertEquals(author1, e2.getAuthor());
710N/A assertEquals(0, e2.getFiles().size());
710N/A assertTrue("Should contain comment of both lines: line 1", e2.getMessage().contains("some"));
710N/A assertTrue("Should contain comment of both lines: line 2", e2.getMessage().contains("two"));
710N/A }
710N/A}