629N/A/*
629N/A * CDDL HEADER START
629N/A *
629N/A * The contents of this file are subject to the terms of the
629N/A * Common Development and Distribution License (the "License").
629N/A * You may not use this file except in compliance with the License.
629N/A *
629N/A * See LICENSE.txt included in this distribution for the specific
629N/A * language governing permissions and limitations under the License.
629N/A *
629N/A * When distributing Covered Code, include this CDDL HEADER in each
629N/A * file and include the License file at LICENSE.txt.
629N/A * If applicable, add the following below this CDDL HEADER, with the
629N/A * fields enclosed by brackets "[]" replaced with your own identifying
629N/A * information: Portions Copyright [yyyy] [name of copyright owner]
629N/A *
629N/A * CDDL HEADER END
629N/A */
629N/A
629N/A/*
629N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
629N/A * Use is subject to license terms.
629N/A */
629N/Apackage org.opensolaris.opengrok.history;
629N/A
629N/Aimport org.junit.After;
629N/Aimport org.junit.AfterClass;
629N/Aimport org.junit.Before;
629N/Aimport org.junit.BeforeClass;
629N/Aimport org.junit.Test;
629N/Aimport static org.junit.Assert.*;
629N/A
629N/A/**
629N/A *
629N/A * @author austvik
629N/A */
629N/Apublic class SubversionHistoryParserTest {
629N/A
629N/A private SubversionHistoryParser instance;
629N/A
629N/A public SubversionHistoryParserTest() {
629N/A }
629N/A
629N/A @BeforeClass
629N/A public static void setUpClass() throws Exception {
629N/A }
629N/A
629N/A @AfterClass
629N/A public static void tearDownClass() throws Exception {
629N/A }
629N/A
629N/A @Before
629N/A public void setUp() {
629N/A instance = new SubversionHistoryParser();
629N/A }
629N/A
629N/A @After
629N/A public void tearDown() {
629N/A instance = null;
629N/A }
629N/A
629N/A /**
629N/A * Test of parse method, of class SubversionHistoryParser.
629N/A */
629N/A @Test
629N/A public void parseEmpty() throws Exception {
629N/A History result = instance.parse("");
629N/A assertNotNull(result);
629N/A assertNotNull(result.getHistoryEntries());
629N/A assertTrue("Should not contain any history entries", 0 == result.getHistoryEntries().size());
629N/A }
629N/A
629N/A /**
629N/A * Test of parsing output similar to that in subversions own svn repository.
629N/A */
629N/A @Test
629N/A public void ParseALaSvn() throws Exception {
629N/A String revId1 = "12345";
629N/A String author1 = "username1";
629N/A String date1= "2007-09-11T11:48:56.123456Z";
629N/A String file1 = "trunk/project/filename.ext";
629N/A String revId2 = "23456";
629N/A String author2 = "username2";
629N/A String date2= "2006-08-10T11:38:56.123456Z";
629N/A String file2 = "trunk/project/path/filename2.ext2";
629N/A String revId3 = "765432";
629N/A String author3 = "username3";
629N/A String date3= "2006-08-09T10:38:56.123456Z";
629N/A String output = "<?xml version=\"1.0\"?>\n" +
629N/A "<log>\n" +
629N/A "<logentry\n" +
629N/A " revision=\"" + revId1 + "\">\n" +
629N/A "<author>" + author1 + "</author>\n" +
629N/A "<date>" + date1 + "</date>\n" +
629N/A "<paths>\n" +
629N/A "<path\n" +
629N/A " action=\"M\">" + file1 + "</path>\n" +
629N/A "</paths>\n" +
629N/A "<msg>* " + file1 + "\n" +
629N/A " Description.\n" +
629N/A "</msg>\n" +
629N/A "</logentry>\n" +
629N/A "<logentry\n" +
629N/A " revision=\"" + revId2 + "\">\n" +
629N/A "<author>" + author2 + "</author>\n" +
629N/A "<date>" + date2 + "</date>\n" +
629N/A "<paths>\n" +
629N/A "<path\n" +
629N/A " action=\"M\">" + file2 + "</path>\n" +
629N/A "</paths>\n" +
629N/A "<msg>* " + file2 +"\n" +
629N/A " some comment\n" +
629N/A " over several lines.\n" +
629N/A "</msg>\n" +
629N/A "</logentry>\n" +
629N/A "<logentry\n" +
629N/A " revision=\"" + revId3 + "\">\n" +
629N/A "<author>" + author3 + "</author>\n" +
629N/A "<date>" + date3 + "</date>\n" +
629N/A "<paths>\n" +
629N/A "<path\n" +
629N/A " action=\"M\">" + file1 + "</path>\n" +
629N/A "<path\n" +
629N/A " action=\"A\">" + file2 + "</path>\n" +
629N/A "</paths>\n" +
629N/A "<msg>this is a longer comment - line1\n" +
629N/A " that spans some lines,\n" +
629N/A " three in fact - line3.\n" +
629N/A "</msg>\n" +
629N/A "</logentry>\n" +
629N/A "</log>";
629N/A History result = instance.parse(output);
629N/A assertNotNull(result);
629N/A assertNotNull(result.getHistoryEntries());
629N/A assertEquals(3, result.getHistoryEntries().size());
629N/A
629N/A HistoryEntry e1 = result.getHistoryEntries().get(0);
629N/A assertEquals(revId1, e1.getRevision());
629N/A assertEquals(author1, e1.getAuthor());
629N/A assertEquals(1, e1.getFiles().size());
802N/A assertEquals("/" + file1, e1.getFiles().first());
629N/A
629N/A HistoryEntry e2 = result.getHistoryEntries().get(1);
629N/A assertEquals(revId2, e2.getRevision());
629N/A assertEquals(author2, e2.getAuthor());
629N/A assertEquals(1, e2.getFiles().size());
802N/A assertEquals("/" + file2, e2.getFiles().first());
629N/A
629N/A HistoryEntry e3 = result.getHistoryEntries().get(2);
629N/A assertEquals(revId3, e3.getRevision());
629N/A assertEquals(author3, e3.getAuthor());
629N/A assertEquals(2, e3.getFiles().size());
802N/A assertEquals("/" + file1, e3.getFiles().first());
802N/A assertEquals("/" + file2, e3.getFiles().last());
629N/A assertTrue(e3.getMessage().contains("line1"));
629N/A assertTrue(e3.getMessage().contains("line3"));
629N/A }
629N/A
1024N/A}