612N/A/*
613N/A * CDDL HEADER START
613N/A *
613N/A * The contents of this file are subject to the terms of the
613N/A * Common Development and Distribution License (the "License").
613N/A * You may not use this file except in compliance with the License.
613N/A *
613N/A * See LICENSE.txt included in this distribution for the specific
613N/A * language governing permissions and limitations under the License.
613N/A *
613N/A * When distributing Covered Code, include this CDDL HEADER in each
613N/A * file and include the License file at LICENSE.txt.
613N/A * If applicable, add the following below this CDDL HEADER, with the
613N/A * fields enclosed by brackets "[]" replaced with your own identifying
613N/A * information: Portions Copyright [yyyy] [name of copyright owner]
613N/A *
613N/A * CDDL HEADER END
613N/A */
613N/A
613N/A/*
613N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
613N/A * Use is subject to license terms.
612N/A */
612N/Apackage org.opensolaris.opengrok.history;
612N/A
612N/Aimport org.junit.After;
612N/Aimport org.junit.AfterClass;
612N/Aimport org.junit.Before;
612N/Aimport org.junit.BeforeClass;
612N/Aimport org.junit.Test;
1024N/Aimport org.opensolaris.opengrok.util.TestRepository;
612N/Aimport static org.junit.Assert.*;
612N/A
612N/A/**
612N/A *
612N/A * @author austvik
612N/A */
612N/Apublic class GitHistoryParserTest {
612N/A
612N/A GitHistoryParser instance;
1016N/A private static TestRepository repository = new TestRepository();
612N/A
612N/A public GitHistoryParserTest() {
612N/A }
612N/A
612N/A @BeforeClass
612N/A public static void setUpClass() throws Exception {
1016N/A repository = new TestRepository();
1016N/A repository.create(HistoryGuru.class.getResourceAsStream("repositories.zip"));
612N/A }
612N/A
612N/A @AfterClass
612N/A public static void tearDownClass() throws Exception {
612N/A }
612N/A
612N/A @Before
612N/A public void setUp() {
612N/A instance = new GitHistoryParser();
612N/A }
612N/A
612N/A @After
612N/A public void tearDown() {
612N/A instance = null;
612N/A }
612N/A
612N/A /**
612N/A * Test of parse method, of class GitHistoryParser.
612N/A */
612N/A @Test
612N/A public void parseEmpty() throws Exception {
625N/A History result = instance.parse("");
612N/A assertNotNull(result);
612N/A assertTrue("Should not contain any history entries", 0 == result.getHistoryEntries().size());
612N/A }
612N/A
612N/A /**
612N/A * Parse something that could come out from the Memcached repository
612N/A *
612N/A * @throws java.lang.Exception
612N/A */
612N/A @Test
612N/A public void parseALaMemcached() throws Exception {
612N/A String commitId1 = "1a23456789abcdef123456789abcderf123456789";
612N/A String commitId2 = "2a2323487092314kjsdafsad7829342kjhsdf3289";
612N/A String commitId3 = "3asdfq234242871934g2sadfsa327894234sa2389";
612N/A String author1 = "username <username@asfdsaf-23412-sadf-cxvdsfg3123-sfasdf>";
612N/A String author2 = "username2 <username2@as345af-23412-sadf-cxvdsfg3123-sfasdf>";
612N/A String date1 = "Sat Apr 1 15:12:51 2008 +0000";
612N/A String date2 = "Wed Mar 22 15:23:15 2006 +0000";
612N/A String output =
612N/A "commit " + commitId1 + "\n" +
612N/A "Author: " + author1 + "\n" +
612N/A "AuthorDate: " + date1 + "\n" +
612N/A "Commit: " + author1 + "\n" +
612N/A "CommitDate: " + date1 + "\n" +
612N/A "\n" +
612N/A " patch from somebody <user.name@example.com>:\n" +
612N/A " \n" +
612N/A " commit message.\n" +
612N/A " \n" +
612N/A " \n" +
612N/A " git-svn-id: http://host.example.com/svn/product/trunk/server@324-fdws-2342-fsdaf-gds-234\n" +
612N/A "\n" +
612N/A "commit " + commitId2 + "\n" +
612N/A "Author: " + author2 + "\n" +
612N/A "AuthorDate: " + date2 + "\n" +
612N/A "Commit: " + author2 + "\n" +
612N/A "CommitDate: " + date2 + "\n" +
612N/A "\n" +
612N/A " r123@branch: username | some date\n" +
612N/A " some comment\n" +
612N/A " \n" +
612N/A " \n" +
612N/A " git-svn-id: http://host.example.com/svn/product/trunk/server@324-fdws-2342-fsdaf-gds-234\n" +
612N/A "\n" +
612N/A "commit " + commitId3 + "\n" +
612N/A "Author: " + author1 + "\n" +
612N/A "AuthorDate: " + date1 + "\n" +
612N/A "Commit: " + author2 + "\n" +
612N/A "CommitDate: " + date2 + "\n" +
612N/A "\n" +
612N/A " some comment\n" +
612N/A " \n" +
612N/A " git-svn-id: http://host.example.com/svn/product/trunk/server@324-fdws-2342-fsdaf-gds-234\n";
612N/A
625N/A History result = instance.parse(output);
612N/A assertNotNull(result);
612N/A assertTrue("Should contain three history entries", 3 == result.getHistoryEntries().size());
612N/A HistoryEntry e0 = result.getHistoryEntries().get(0);
612N/A assertEquals(commitId1, e0.getRevision());
612N/A assertEquals(author1, e0.getAuthor());
612N/A assertEquals(0, e0.getFiles().size());
612N/A HistoryEntry e1 = result.getHistoryEntries().get(1);
612N/A assertEquals(commitId2, e1.getRevision());
612N/A assertEquals(author2, e1.getAuthor());
612N/A assertEquals(0, e1.getFiles().size());
612N/A HistoryEntry e2 = result.getHistoryEntries().get(2);
612N/A assertEquals(commitId3, e2.getRevision());
612N/A assertEquals(author1, e2.getAuthor());
612N/A assertEquals(0, e2.getFiles().size());
612N/A }
612N/A
612N/A /**
612N/A * Parse something that could come out from the git repository
612N/A *
612N/A * @throws java.lang.Exception
612N/A */
612N/A @Test
612N/A public void parseALaGit() throws Exception {
612N/A String commitId1 = "1a23456789abcdef123456789abcderf123456789";
612N/A String commitId2 = "2a2323487092314kjsdafsad7829342kjhsdf3289";
612N/A String author1 = "username <username@example.com>";
612N/A String author2 = "username2 <username2@example.com>";
612N/A String date1 = "Sun Jan 13 01:12:05 2008 -0700";
612N/A String filename = "filename.c";
612N/A
612N/A String output = "commit " + commitId1 + "\n" +
612N/A "Author: " + author1 + "\n" +
612N/A "AuthorDate: " + date1 + "\n" +
612N/A "Commit: " + author2 + "\n" +
612N/A "CommitDate: " + date1 + "\n" +
612N/A "\n" +
612N/A " Some heading\n" +
612N/A " \n" +
612N/A " First paragraph of text.\n" +
612N/A " \n" +
612N/A " Second paragraph\n" +
612N/A " of text.\n" +
612N/A " \n" +
612N/A " Signed-off-by: Somebody <username@example.com>\n" +
612N/A "\n" +
612N/A filename + "\n" +
612N/A "\n" +
612N/A "commit " + commitId2 + "\n" +
612N/A "Author: " + author2 + "\n" +
612N/A "AuthorDate: " + date1 + "\n" +
612N/A "Commit: " + author2 + "\n" +
612N/A "CommitDate: " + date1 + "\n" +
612N/A "\n" +
612N/A " Make \"--somethind\" do something.\n" +
612N/A " \n" +
612N/A " This is a full\n" +
612N/A " paragraph of text\n" +
612N/A " \n" +
612N/A " Signed-off-by: Somebody <username@example.com>\n" +
612N/A "\n" +
612N/A filename + "\n";
710N/A
625N/A History result = instance.parse(output);
612N/A assertNotNull(result);
612N/A assertTrue("Should contain two history entries", 2 == result.getHistoryEntries().size());
612N/A HistoryEntry e0 = result.getHistoryEntries().get(0);
612N/A assertEquals(commitId1, e0.getRevision());
612N/A assertEquals(author1, e0.getAuthor());
612N/A assertEquals(1, e0.getFiles().size());
802N/A assertEquals("/" + filename, e0.getFiles().first());
612N/A assertTrue(e0.getMessage().contains("Some heading"));
612N/A assertTrue(e0.getMessage().contains("Signed-off-by"));
612N/A HistoryEntry e1 = result.getHistoryEntries().get(1);
612N/A assertEquals(commitId2, e1.getRevision());
612N/A assertEquals(author2, e1.getAuthor());
612N/A assertEquals(1, e1.getFiles().size());
802N/A assertEquals("/" + filename, e1.getFiles().first());
612N/A assertTrue(e1.getMessage().contains("paragraph of text"));
612N/A assertTrue(e1.getMessage().contains("Signed-off-by"));
612N/A }
612N/A
612N/A /**
612N/A * Parse something that could come out from the linux kernel repository
612N/A *
612N/A * @throws java.lang.Exception
612N/A */
612N/A @Test
612N/A public void parseALaLK() throws Exception {
612N/A String commitId1 = "1a23456789abcdef123456789abcderf123456789";
612N/A String commitId2 = "2a2323487092314kjsdafsad7829342kjhsdf3289";
612N/A String author1 = "username <username@example.com>";
612N/A String author2 = "username2 <username2@example.com>";
612N/A String committer = "committer <committer@example.com>";
612N/A String date1 = "Sun Jan 13 01:12:05 2008 -0700";
612N/A String date2 = "Mon Jan 14 01:12:05 2008 -0800";
612N/A String filename1 = "directory/filename.c";
612N/A String filename2 = "directory/filename.h";
612N/A
612N/A String output = "commit " + commitId1 + "\n" +
612N/A "Author: " + author1 + "\n" +
612N/A "AuthorDate: " + date1 + "\n" +
612N/A "Commit: " + committer + "\n" +
612N/A "CommitDate: " + date2 + "\n" +
612N/A "\n" +
612N/A " Subject: subject title\n" +
612N/A " \n" +
612N/A " sdj fasodjfads jfa.kdsmf asdknf sadlfkm sad fma\n" +
612N/A " dpojfv adsjv a,s.kdnvlø aok åpwaiorjf aldjfg ladijfg adkgf\n" +
612N/A " jsdkgfj sadhkjfgs dlkjfg dksjgfh.\n" +
612N/A " \n" +
612N/A " djkhfgv ksadhg kdajhg ,dsn \n" +
612N/A " x,nv ,xmcnvkadsjfnv,. zxmcnv edfhsgdksgf.\n" +
612N/A " Dsdn ,dn ,dsng .,xcmnvefjhgiorfhgdskhg fdsg dfh sdf\n" +
612N/A " skdjfas djskdjf ksadjhfn sa.,df .\n" +
612N/A " \n" +
612N/A " Zkjd flsdj flksadj fødsakjf asd jfsadijfosdhva.\n" +
612N/A " \n" +
612N/A " [user@example.com: something or another]\n" +
612N/A " Signed-off-by: First Last <username@example.com>\n" +
612N/A " Cc: Firstr Last <username@example.com>\n" +
612N/A " Signed-off-by: First Last <username3@example.com>\n" +
612N/A " Signed-off-by: Pinguin <pingu@example.com>\n" +
612N/A "\n" +
612N/A filename1 + "\n" +
612N/A "\n" +
612N/A "commit " + commitId2 + "\n" +
612N/A "Author: " + author2 + "\n" +
612N/A "AuthorDate: " + date1 + "\n" +
612N/A "Commit: " + committer + "\n" +
612N/A "CommitDate: " + date2 + "\n" +
612N/A "\n" +
612N/A " [PATCH] Subject heading.\n" +
612N/A " \n" +
612N/A " Some description of what is to come:\n" +
612N/A " \n" +
612N/A " * item 1\n" +
612N/A " * item 2\n" +
612N/A " * ...\n" +
612N/A " * item n\n" +
612N/A " \n" +
612N/A " Signed-off-by: User <user@example.com>\n" +
612N/A " Cc: \"First.Last\" <user2@example.com>\n" +
612N/A " Signed-off-by: First Last <username3@example.com>\n" +
612N/A " Signed-off-by: Pinguin <pingu@example.com>\n" +
612N/A "\n" +
612N/A filename1 + "\n" +
612N/A filename2 + "\n";
625N/A History result = instance.parse(output);
612N/A assertNotNull(result);
612N/A assertTrue("Should contain two history entries", 2 == result.getHistoryEntries().size());
612N/A HistoryEntry e0 = result.getHistoryEntries().get(0);
612N/A assertEquals(commitId1, e0.getRevision());
612N/A assertEquals(author1, e0.getAuthor());
612N/A assertEquals(1, e0.getFiles().size());
802N/A assertEquals("/" + filename1, e0.getFiles().first());
612N/A assertTrue(e0.getMessage().contains("subject title"));
612N/A assertTrue(e0.getMessage().contains("Signed-off-by"));
612N/A HistoryEntry e1 = result.getHistoryEntries().get(1);
612N/A assertEquals(commitId2, e1.getRevision());
612N/A assertEquals(author2, e1.getAuthor());
612N/A assertEquals(2, e1.getFiles().size());
802N/A assertEquals("/" + filename1, e1.getFiles().first());
802N/A assertEquals("/" + filename2, e1.getFiles().last());
612N/A assertTrue(e1.getMessage().contains("[PATCH]"));
612N/A assertTrue(e1.getMessage().contains("Signed-off-by"));
612N/A }
612N/A}