378N/A/*
378N/A * CDDL HEADER START
378N/A *
378N/A * The contents of this file are subject to the terms of the
378N/A * Common Development and Distribution License (the "License").
378N/A * You may not use this file except in compliance with the License.
378N/A *
378N/A * See LICENSE.txt included in this distribution for the specific
378N/A * language governing permissions and limitations under the License.
378N/A *
378N/A * When distributing Covered Code, include this CDDL HEADER in each
378N/A * file and include the License file at LICENSE.txt.
378N/A * If applicable, add the following below this CDDL HEADER, with the
378N/A * fields enclosed by brackets "[]" replaced with your own identifying
378N/A * information: Portions Copyright [yyyy] [name of copyright owner]
378N/A *
378N/A * CDDL HEADER END
378N/A */
378N/A
378N/A/*
378N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
378N/A * Use is subject to license terms.
378N/A */
378N/Apackage org.opensolaris.opengrok.history;
378N/A
378N/Aimport java.io.File;
378N/Aimport java.io.IOException;
444N/Aimport java.io.InputStream;
378N/Aimport java.util.ArrayList;
1191N/Aimport java.util.Collection;
378N/Aimport java.util.List;
378N/Aimport org.junit.After;
378N/Aimport org.junit.AfterClass;
1419N/Aimport static org.junit.Assert.*;
378N/Aimport org.junit.Before;
378N/Aimport org.junit.BeforeClass;
378N/Aimport org.junit.Test;
378N/Aimport org.opensolaris.opengrok.configuration.RuntimeEnvironment;
378N/Aimport org.opensolaris.opengrok.util.FileUtilities;
378N/Aimport org.opensolaris.opengrok.util.TestRepository;
378N/A
378N/A/**
378N/A * Test the functionality provided by the HistoryGuru (with friends)
378N/A * @author Trond Norbye
378N/A */
378N/Apublic class HistoryGuruTest {
378N/A
378N/A private static TestRepository repository = new TestRepository();
378N/A private static List<File> files = new ArrayList<File>();
378N/A
378N/A public HistoryGuruTest() {
378N/A }
378N/A
378N/A @BeforeClass
378N/A public static void setUpClass() throws Exception {
378N/A repository = new TestRepository();
378N/A repository.create(HistoryGuru.class.getResourceAsStream("repositories.zip"));
489N/A FileUtilities.getAllFiles(new File(repository.getSourceRoot()), files, true);
378N/A RuntimeEnvironment.getInstance().setVerbose(true);
378N/A }
378N/A
378N/A @AfterClass
378N/A public static void tearDownClass() throws Exception {
378N/A repository.destroy();
378N/A }
378N/A
378N/A @Before
1419N/A public void setUp() throws IOException {
378N/A }
378N/A
378N/A @After
1419N/A public void tearDown() {
378N/A }
378N/A
378N/A @Test
378N/A public void testGetInstance() {
378N/A assertNotNull(HistoryGuru.getInstance());
378N/A }
378N/A
378N/A @Test
378N/A public void testAddRepositories() throws IOException {
378N/A HistoryGuru instance = HistoryGuru.getInstance();
489N/A instance.addRepositories(repository.getSourceRoot());
378N/A }
378N/A
378N/A @Test
378N/A public void testCreateCache() {
378N/A HistoryGuru instance = HistoryGuru.getInstance();
378N/A instance.createCache();
1191N/A Collection<String> repos = new ArrayList<String>();
543N/A repos.add("git");
543N/A repos.add("bazaar");
543N/A repos.add("mercurial");
543N/A repos.add("teamware");
543N/A repos.add("rcs");
543N/A repos.add("nonexistent");
543N/A instance.createCache(repos);
378N/A }
378N/A
378N/A @Test
444N/A public void testUpdateRepositories() {
444N/A HistoryGuru instance = HistoryGuru.getInstance();
444N/A instance.updateRepositories();
444N/A }
444N/A
444N/A @Test
615N/A public void getRevision() throws HistoryException, IOException {
445N/A HistoryGuru instance = HistoryGuru.getInstance();
445N/A for (File f : files) {
532N/A if (f.isFile() && instance.hasHistory(f)) {
838N/A for (HistoryEntry entry :
838N/A instance.getHistory(f).getHistoryEntries()) {
838N/A String revision = entry.getRevision();
838N/A InputStream in = instance.getRevision(
838N/A f.getParent(), f.getName(), revision);
838N/A assertNotNull("Failed to get revision " + revision +
838N/A " of " + f.getAbsolutePath(), in);
445N/A in.close();
445N/A }
445N/A }
445N/A }
445N/A }
445N/A
445N/A @Test
1419N/A public void testBug16465() throws HistoryException, IOException {
1102N/A HistoryGuru instance = HistoryGuru.getInstance();
1102N/A for (File f : files) {
1102N/A if (f.getName().equals("bugreport16465@")) {
1102N/A assertNotNull(instance.getHistory(f));
1102N/A assertNotNull(instance.annotate(f, null));
1102N/A }
1102N/A }
1102N/A }
1102N/A
1102N/A @Test
378N/A public void annotation() throws Exception {
378N/A HistoryGuru instance = HistoryGuru.getInstance();
378N/A for (File f : files) {
378N/A if (instance.hasAnnotation(f)) {
378N/A instance.annotate(f, null);
378N/A }
378N/A }
378N/A }
864N/A
864N/A @Test
864N/A public void getCacheInfo() throws HistoryException {
864N/A // FileHistoryCache is used by default
864N/A assertEquals("FileHistoryCache",
864N/A HistoryGuru.getInstance().getCacheInfo());
864N/A }
1024N/A}