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