632N/A/*
632N/A * CDDL HEADER START
632N/A *
632N/A * The contents of this file are subject to the terms of the
632N/A * Common Development and Distribution License (the "License").
632N/A * You may not use this file except in compliance with the License.
632N/A *
632N/A * See LICENSE.txt included in this distribution for the specific
632N/A * language governing permissions and limitations under the License.
632N/A *
632N/A * When distributing Covered Code, include this CDDL HEADER in each
632N/A * file and include the License file at LICENSE.txt.
632N/A * If applicable, add the following below this CDDL HEADER, with the
632N/A * fields enclosed by brackets "[]" replaced with your own identifying
632N/A * information: Portions Copyright [yyyy] [name of copyright owner]
632N/A *
632N/A * CDDL HEADER END
632N/A */
632N/A
632N/A/*
1285N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
632N/A */
1024N/A
632N/Apackage org.opensolaris.opengrok.history;
632N/A
1470N/Aimport static org.junit.Assert.assertEquals;
1470N/Aimport static org.junit.Assert.assertNotNull;
1470N/Aimport static org.junit.Assert.assertTrue;
1470N/A
802N/Aimport java.util.Arrays;
802N/Aimport java.util.HashSet;
1470N/A
632N/Aimport org.junit.After;
632N/Aimport org.junit.Before;
632N/Aimport org.junit.Test;
837N/Aimport org.opensolaris.opengrok.configuration.RuntimeEnvironment;
632N/A
632N/A/**
632N/A *
632N/A * @author austvik
632N/A */
632N/Apublic class BazaarHistoryParserTest {
632N/A
632N/A private BazaarHistoryParser instance;
632N/A
1470N/A @SuppressWarnings("javadoc")
632N/A @Before
632N/A public void setUp() {
1470N/A if (RuntimeEnvironment.getConfig().getSourceRoot() == null) {
1470N/A RuntimeEnvironment.getConfig().setSourceRoot("");
837N/A }
837N/A instance = new BazaarHistoryParser(new BazaarRepository());
632N/A }
632N/A
1470N/A @SuppressWarnings("javadoc")
632N/A @After
632N/A public void tearDown() {
632N/A instance = null;
632N/A }
632N/A
632N/A /**
632N/A * Test of parse method, of class BazaarHistoryParser.
1470N/A * @throws Exception
632N/A */
632N/A @Test
632N/A public void parseEmpty() throws Exception {
632N/A History result = instance.parse("");
632N/A assertNotNull(result);
632N/A assertNotNull(result.getHistoryEntries());
1470N/A assertTrue("Should not contain any history entries",
1470N/A 0 == result.getHistoryEntries().size());
632N/A }
632N/A
1470N/A @SuppressWarnings("javadoc")
632N/A @Test
632N/A public void parseLogNoFile() throws Exception {
632N/A String revId1 = "1234";
632N/A String author1 = "First Last <username@example.com>";
632N/A String date1 = "Wed 2008-10-01 10:01:34 +0200";
632N/A
632N/A String revId2 = "1234";
632N/A String author2 = "First2 Last2 <username2@example.com>";
632N/A String date2 = "Wed 2008-10-15 09:21:31 +0100";
632N/A
632N/A String revId3 = "4";
632N/A String author3 = "First3 Last3 <username3@example.com>";
632N/A String date3 = "Wed 2008-10-15 09:21:31 -0100";
632N/A
632N/A String revId4 = "4.1";
632N/A String author4 = "First3 Last3 <username3@example.com>";
632N/A String date4 = "Wed 2008-10-15 09:21:31 -0100";
632N/A
632N/A String output = "------------------------------------------------------------\n" +
1470N/A "revno: " + revId1 + "\n" +
1470N/A "committer: " + author1 + "\n" +
1470N/A "branch nick: 1.2 branch\n" +
1470N/A "timestamp: " + date1 + "\n" +
1470N/A "message:\n" +
1470N/A " Some message.\n" +
1470N/A "------------------------------------------------------------\n" +
1470N/A "revno: " + revId2 + "\n" +
1470N/A "committer: " + author2 + "\n" +
1470N/A "branch nick: branch-name\n" +
1470N/A "timestamp: " + date2 + "\n" +
1470N/A "message:\n" +
1470N/A " One line comment.\n" +
1470N/A "------------------------------------------------------------\n" +
1470N/A "revno: " + revId3 + "\n" +
1470N/A "committer: " + author3 + "\n" +
1470N/A "timestamp: " + date3 + "\n" +
1470N/A "message:\n" +
1470N/A " Comment over two lines, this is line1\n" +
1470N/A " and this is line2\n" +
1470N/A " ------------------------------------------------------------\n" +
1470N/A " revno: " + revId4 + "\n" +
1470N/A " committer: " + author4 + "\n" +
1470N/A " timestamp: " + date4 + "\n" +
1470N/A " message:\n" +
1470N/A " Just a message\n";
632N/A
632N/A History result = instance.parse(output);
632N/A
632N/A assertNotNull(result);
632N/A assertNotNull(result.getHistoryEntries());
1285N/A assertEquals(3, result.getHistoryEntries().size());
632N/A
632N/A HistoryEntry e1 = result.getHistoryEntries().get(0);
632N/A assertEquals(revId1, e1.getRevision());
632N/A assertEquals(author1, e1.getAuthor());
632N/A assertEquals(0, e1.getFiles().size());
632N/A
632N/A HistoryEntry e2 = result.getHistoryEntries().get(1);
632N/A assertEquals(revId2, e2.getRevision());
632N/A assertEquals(author2, e2.getAuthor());
632N/A assertEquals(0, e2.getFiles().size());
632N/A
632N/A HistoryEntry e3 = result.getHistoryEntries().get(2);
632N/A assertEquals(revId3, e3.getRevision());
632N/A assertEquals(author3, e3.getAuthor());
632N/A assertEquals(0, e3.getFiles().size());
632N/A assertTrue(e3.getMessage().contains("line1"));
632N/A assertTrue(e3.getMessage().contains("line2"));
1285N/A assertTrue(e3.getMessage().contains("revno: " + revId4));
632N/A }
632N/A
632N/A @Test
1470N/A @SuppressWarnings({ "javadoc" })
632N/A public void parseLogDirectory() throws Exception {
632N/A String revId1 = "1234";
632N/A String author1 = "username@example.com";
632N/A String date1 = "Wed 2008-10-01 10:01:34 +0200";
802N/A String[] files = {
802N/A "/filename.ext",
802N/A "/directory",
802N/A "/directory/filename.ext",
802N/A "/directory/filename2.ext2",
802N/A "/otherdir/file.extension"
802N/A };
802N/A
802N/A StringBuilder output = new StringBuilder();
802N/A for (int i = 0; i < 60; i++) {
802N/A output.append('-');
802N/A }
802N/A output.append('\n');
802N/A output.append("revno: " + revId1 + "\n");
802N/A output.append("committer: " + author1 + "\n");
802N/A output.append("timestamp: " + date1 + "\n");
802N/A output.append("message:\n");
802N/A output.append(" Some message\n");
802N/A output.append("added:\n");
802N/A for (String file : files) {
802N/A output.append(" " + file.substring(1) + "\n");
802N/A }
802N/A
802N/A History result = instance.parse(output.toString());
632N/A
632N/A assertNotNull(result);
632N/A assertNotNull(result.getHistoryEntries());
632N/A assertEquals(1, result.getHistoryEntries().size());
632N/A
632N/A HistoryEntry e1 = result.getHistoryEntries().get(0);
632N/A assertEquals(revId1, e1.getRevision());
632N/A assertEquals(author1, e1.getAuthor());
1470N/A assertEquals(new HashSet<String>(Arrays.asList(files)), e1.getFiles());
632N/A }
632N/A
1024N/A}