RuntimeEnvironmentTest.java revision 565
0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
0N/A *
0N/A * See LICENSE.txt included in this distribution for the specific
0N/A * language governing permissions and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at LICENSE.txt.
0N/A * If applicable, add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your own identifying
0N/A * information: Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
830N/A
0N/A/*
0N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/Apackage org.opensolaris.opengrok.configuration;
0N/A
0N/Aimport java.io.File;
0N/Aimport java.io.IOException;
0N/Aimport java.net.InetSocketAddress;
0N/Aimport java.net.SocketAddress;
170N/Aimport org.junit.After;
0N/Aimport org.junit.AfterClass;
0N/Aimport org.junit.Before;
0N/Aimport org.junit.BeforeClass;
0N/Aimport org.junit.Test;
0N/Aimport static org.junit.Assert.*;
0N/A
0N/A/**
0N/A * Test the RuntimeEnvironment class
0N/A *
0N/A * @author Trond Norbye
0N/A */
0N/Apublic class RuntimeEnvironmentTest {
0N/A private static File orgiginalConfig;
0N/A
0N/A public RuntimeEnvironmentTest() {
0N/A }
0N/A
0N/A @BeforeClass
188N/A public static void setUpClass() throws Exception {
188N/A // preserve the original
170N/A orgiginalConfig = File.createTempFile("config", ".xml");
170N/A RuntimeEnvironment.getInstance().writeConfiguration(orgiginalConfig);
170N/A
170N/A // Create a default configuration
170N/A Configuration config = new Configuration();
170N/A RuntimeEnvironment.getInstance().setConfiguration(config);
940N/A }
170N/A
940N/A @AfterClass
170N/A public static void tearDownClass() throws Exception {
830N/A // restore the configuration
830N/A RuntimeEnvironment.getInstance().readConfiguration(orgiginalConfig);
170N/A RuntimeEnvironment.getInstance().register();
170N/A orgiginalConfig.delete();
170N/A }
170N/A
170N/A @Before
940N/A public void setUp() {
170N/A }
170N/A
830N/A @After
830N/A public void tearDown() {
170N/A }
170N/A
170N/A @Test
170N/A public void testDataRoot() throws IOException {
170N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
283N/A assertNull(instance.getDataRootFile());
0N/A assertNull(instance.getDataRootPath());
0N/A File f = File.createTempFile("dataroot", null);
0N/A String path = f.getCanonicalPath();
0N/A assertTrue(f.delete());
0N/A instance.setDataRoot(path);
0N/A assertTrue(f.delete());
0N/A assertEquals(path, instance.getDataRootPath());
0N/A assertEquals(path, instance.getDataRootFile().getCanonicalPath());
0N/A }
0N/A
170N/A @Test
170N/A public void testSourceRoot() throws IOException {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertNull(instance.getSourceRootFile());
0N/A assertNull(instance.getSourceRootPath());
0N/A File f = File.createTempFile("sourceroot", null);
0N/A String path = f.getCanonicalPath();
0N/A assertTrue(f.delete());
0N/A instance.setSourceRoot(path);
0N/A assertEquals(path, instance.getSourceRootPath());
0N/A assertEquals(path, instance.getSourceRootFile().getCanonicalPath());
0N/A }
0N/A
0N/A @Test
0N/A public void testProjects() throws IOException {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertFalse(instance.hasProjects());
947N/A assertNotNull(instance.getProjects());
0N/A assertEquals(0, instance.getProjects().size());
0N/A assertNull(instance.getDefaultProject());
0N/A
0N/A File file = new File("/opengrok_automatic_test/foo/bar");
0N/A instance.setSourceRoot("/opengrok_automatic_test/foo");
0N/A Project p = new Project();
0N/A p.setPath("/bar");
0N/A assertEquals("/bar", p.getId());
947N/A instance.getProjects().add(p);
0N/A assertEquals(p, Project.getProject(file));
0N/A instance.setProjects(null);
0N/A assertNull(instance.getProjects());
0N/A }
0N/A
0N/A @Test
0N/A public void testRegister() throws InterruptedException {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A String path = "/tmp/dataroot";
0N/A instance.setDataRoot(path);
0N/A instance.register();
0N/A Thread t = new Thread(new Runnable() {
0N/A
0N/A public void run() {
0N/A Configuration c = new Configuration();
0N/A RuntimeEnvironment.getInstance().setConfiguration(c);
0N/A
0N/A }
0N/A });
0N/A t.start();
0N/A t.join();
0N/A assertEquals(path, instance.getDataRootPath());
0N/A }
0N/A
0N/A @Test
0N/A public void testUrlPrefix() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertEquals("/source/s?", instance.getUrlPrefix());
188N/A String prefix = "/opengrok/s?";
0N/A instance.setUrlPrefix(prefix);
0N/A assertEquals(prefix, instance.getUrlPrefix());
0N/A }
0N/A
0N/A @Test
188N/A public void testCtags() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertEquals("ctags", instance.getCtags());
0N/A String path = "/usr/bin/ctags";
0N/A instance.setCtags(path);
0N/A assertEquals(path, instance.getCtags());
188N/A }
0N/A
0N/A @Test
0N/A public void testHistoryReaderTimeLimit() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertEquals(30, instance.getHistoryReaderTimeLimit());
188N/A instance.setHistoryReaderTimeLimit(50);
0N/A assertEquals(50, instance.getHistoryReaderTimeLimit());
0N/A }
0N/A
0N/A @Test
0N/A public void testUseHistoryCache() {
188N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertEquals(true, instance.useHistoryCache());
0N/A instance.setUseHistoryCache(false);
0N/A assertEquals(false, instance.useHistoryCache());
188N/A }
0N/A
188N/A @Test
0N/A public void testGenerateHtml() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertTrue(instance.isGenerateHtml());
0N/A instance.setGenerateHtml(false);
0N/A assertFalse(instance.isGenerateHtml());
0N/A }
0N/A
0N/A @Test
0N/A public void testCompressXref() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertTrue(instance.isCompressXref());
0N/A instance.setCompressXref(false);
0N/A assertFalse(instance.isCompressXref());
0N/A }
345N/A
0N/A @Test
0N/A public void testQuickContextScan() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertTrue(instance.isQuickContextScan());
0N/A instance.setQuickContextScan(false);
0N/A assertFalse(instance.isQuickContextScan());
0N/A }
0N/A
0N/A @Test
0N/A public void testRepositories() {
1025N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertNotNull(instance.getRepositories());
0N/A instance.setRepositories(null);
0N/A assertNull(instance.getRepositories());
0N/A }
0N/A
345N/A @Test
0N/A public void testIndexWordLimit() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertEquals(60000, instance.getIndexWordLimit());
0N/A instance.setIndexWordLimit(100000);
0N/A assertEquals(100000, instance.getIndexWordLimit());
0N/A }
345N/A
0N/A @Test
0N/A public void testVerbose() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertFalse(instance.isVerbose());
0N/A instance.setVerbose(true);
0N/A assertTrue(instance.isVerbose());
0N/A }
0N/A
0N/A @Test
0N/A public void testAllowLeadingWildcard() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
345N/A assertFalse(instance.isAllowLeadingWildcard());
0N/A instance.setAllowLeadingWildcard(true);
0N/A assertTrue(instance.isAllowLeadingWildcard());
0N/A }
345N/A
0N/A @Test
488N/A public void testIgnoredNames() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertNotNull(instance.getIgnoredNames());
345N/A instance.setIgnoredNames(null);
0N/A assertNull(instance.getIgnoredNames());
0N/A }
0N/A
0N/A @Test
0N/A public void testUserPage() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A String page = "http://www.opensolaris.org/viewProfile.jspa?username=";
0N/A assertEquals(page, instance.getUserPage());
0N/A instance.setUserPage(page.substring(5));
0N/A assertEquals(page.substring(5), instance.getUserPage());
0N/A }
0N/A
0N/A @Test
0N/A public void testBugPage() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A String page = "http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=";
0N/A assertEquals(page, instance.getBugPage());
0N/A instance.setBugPage(page.substring(5));
0N/A assertEquals(page.substring(5), instance.getBugPage());
0N/A }
0N/A
0N/A @Test
0N/A public void testBugPattern() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A String page = "\\b([12456789][0-9]{6})\\b";
0N/A assertEquals(page, instance.getBugPattern());
0N/A instance.setBugPattern(page.substring(5));
0N/A assertEquals(page.substring(5), instance.getBugPattern());
0N/A }
0N/A
345N/A @Test
0N/A public void testReviewPage() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A String page = "http://www.opensolaris.org/os/community/arc/caselog/";
345N/A assertEquals(page, instance.getReviewPage());
0N/A instance.setReviewPage(page.substring(5));
0N/A assertEquals(page.substring(5), instance.getReviewPage());
0N/A }
345N/A
0N/A @Test
488N/A public void testReviewPattern() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A String page = "\\b(\\d{4}/\\d{3})\\b";
345N/A assertEquals(page, instance.getReviewPattern());
0N/A instance.setReviewPattern(page.substring(5));
0N/A assertEquals(page.substring(5), instance.getReviewPattern());
0N/A }
345N/A
0N/A @Test
488N/A public void testWebappLAF() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertEquals("default", instance.getWebappLAF());
345N/A instance.setWebappLAF("foo");
0N/A assertEquals("foo", instance.getWebappLAF());
0N/A }
0N/A
0N/A @Test
0N/A public void testRemoteScmSupported() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertFalse(instance.isRemoteScmSupported());
0N/A instance.setRemoteScmSupported(true);
0N/A assertTrue(instance.isRemoteScmSupported());
0N/A }
0N/A
705N/A @Test
0N/A public void testOptimizeDatabase() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertTrue(instance.isOptimizeDatabase());
0N/A instance.setOptimizeDatabase(false);
0N/A assertFalse(instance.isOptimizeDatabase());
0N/A }
0N/A
0N/A @Test
345N/A public void testUsingLuceneLocking() {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertFalse(instance.isUsingLuceneLocking());
0N/A instance.setUsingLuceneLocking(true);
345N/A assertTrue(instance.isUsingLuceneLocking());
0N/A }
488N/A
0N/A @Test
0N/A public void testIndexVersionedFilesOnly() {
345N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A assertFalse(instance.isIndexVersionedFilesOnly());
0N/A instance.setIndexVersionedFilesOnly(true);
0N/A assertTrue(instance.isIndexVersionedFilesOnly());
0N/A }
0N/A
0N/A @Test
0N/A public void testConfigListenerThread() throws IOException {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A SocketAddress addr = new InetSocketAddress(0);
0N/A assertTrue(instance.startConfigurationListenerThread(addr));
0N/A try {
0N/A Thread.sleep(1000);
0N/A } catch (InterruptedException exp) {
0N/A // do nothing
0N/A }
0N/A instance.writeConfiguration();
345N/A instance.stopConfigurationListenerThread();
0N/A }
0N/A
0N/A @Test
345N/A public void testBug3095() throws IOException {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
488N/A File file = new File("foobar");
0N/A assertTrue(file.createNewFile());
0N/A assertFalse(file.isAbsolute());
345N/A instance.setDataRoot(file.getName());
0N/A File f = instance.getDataRootFile();
0N/A assertNotNull(f);
0N/A assertEquals("foobar", f.getName());
0N/A assertTrue(f.isAbsolute());
0N/A assertTrue(file.delete());
0N/A }
0N/A
0N/A @Test
0N/A public void testBug3154() throws IOException {
0N/A RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
0N/A File file = File.createTempFile("dataroot", null);
0N/A assertTrue(file.delete());
0N/A assertFalse(file.exists());
0N/A instance.setDataRoot(file.getAbsolutePath());
0N/A assertTrue(file.exists());
0N/A assertTrue(file.delete());
0N/A }
0N/A}
0N/A