1 /* 2 * Zemucan: A Syntax Assistant for DB2 3 * Copyright (C) 2009, 2010 Andres Gomez Casanova 4 * 5 * This file is part of Zemucan. 6 * 7 * Zemucan is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU Lesser General Public License as published by 9 * the Free Software Foundation; either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * Zemucan is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public License 18 * along with this library; if not, see <http://www.gnu.org/licenses/>. 19 * 20 * Contact: 21 * a n g o c a at y a h o o dot c o m 22 * Cra. 45 No 61 - 31, Bogota, Colombia. 23 * 24 * Author: $LastChangedBy: angoca $: 25 * Date: $LastChangedDate: 2011-03-06 22:39:08 -0500 (dom, 06 mar 2011) $: 26 * Revision: $LastChangedRevision: 1916 $: 27 * URL: $HeadURL: https://zemucan.svn.sourceforge.net/svnroot/zemucan/branches/zemucan_v1/source-code/tools/src/test/java/name/angoca/zemucan/tools/configurator/ConfigurationReaderTest.java $: 28 */ 29 package name.angoca.zemucan.tools.configurator; 30 31 import name.angoca.zemucan.tools.Constants; 32 import name.angoca.zemucan.tools.test.RandomTestRunner; 33 34 import org.junit.AfterClass; 35 import org.junit.Assert; 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 39 /** 40 * Test of the configuration reader. 41 * <p> 42 * <b>Control Version</b> 43 * <p> 44 * <ul> 45 * <li>0.0.1 Class creation.</li> 46 * <li>0.1.0 TearDown.</li> 47 * <li>1.0.0 Moved to version 1.</li> 48 * <li>1.0.1 Exit token.</li> 49 * <li>1.0.2 Strings externalized.</li> 50 * <li>1.1.0 New exception and refactorized existants.</li> 51 * </ul> 52 * 53 * @author Andres Gomez Casanova <a 54 * href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a> 55 * @version 1.1.0 2009-11-02 56 */ 57 @RunWith(RandomTestRunner.class) 58 public final class ConfigurationReaderTest { 59 60 /** 61 * Clears the configuration file name property at the end of the test. 62 */ 63 @AfterClass 64 public static void tearDownAfterClass() { 65 System.clearProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY); 66 } 67 68 /** 69 * Default constructor. 70 */ 71 public ConfigurationReaderTest() { 72 // Nothing. 73 } 74 75 /** 76 * Test the thrown of an exception after reading a file with an invalid 77 * structure. 78 * 79 * @throws AbstractConfiguratorException 80 * Never. 81 */ 82 @Test 83 public void testInvalidFile() throws AbstractConfiguratorException { 84 final String filename = "sa_conf-test-InvalidFormat.properties"; //$NON-NLS-1$ 85 86 Exception e = null; 87 try { 88 ConfigurationReader.readFile(filename); 89 } catch (final Exception exception) { 90 e = exception; 91 } 92 Assert.assertTrue("ConfigurationFileCorruptException", 93 e instanceof ConfigurationFileCorruptException); 94 } 95 96 /** 97 * Test the thrown of an exception after reading a file with an invalid 98 * structure. 99 * 100 * @throws AbstractConfiguratorException 101 * Never. 102 */ 103 @Test 104 public void testNotFoundFile() throws AbstractConfiguratorException { 105 final String filename = "NoFileSpecified"; //$NON-NLS-1$ 106 107 Exception e = null; 108 try { 109 ConfigurationReader.readFile(filename); 110 } catch (final Exception exception) { 111 e = exception; 112 } 113 Assert.assertTrue("GeneralConfigurationFileProblemException", 114 e instanceof GeneralConfigurationFileProblemException); 115 } 116 117 /** 118 * Tests that the file to read cannot be null. 119 * 120 * @throws AbstractConfiguratorException 121 * Never. 122 */ 123 @Test(expected = AssertionError.class) 124 public void testReadNull() throws AbstractConfiguratorException { 125 ConfigurationReader.readFile(null); 126 } 127 128 }