001: // -*- Java -*-
002: //
003: // Copyright (c) 2005, Matthew J. Rutherford <rutherfo@cs.colorado.edu>
004: // Copyright (c) 2005, University of Colorado at Boulder
005: // All rights reserved.
006: //
007: // Redistribution and use in source and binary forms, with or without
008: // modification, are permitted provided that the following conditions are
009: // met:
010: //
011: // * Redistributions of source code must retain the above copyright
012: // notice, this list of conditions and the following disclaimer.
013: //
014: // * Redistributions in binary form must reproduce the above copyright
015: // notice, this list of conditions and the following disclaimer in the
016: // documentation and/or other materials provided with the distribution.
017: //
018: // * Neither the name of the University of Colorado at Boulder nor the
019: // names of its contributors may be used to endorse or promote
020: // products derived from this software without specific prior written
021: // permission.
022: //
023: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
024: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
025: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
026: // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
027: // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
028: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
029: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
030: // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
031: // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
032: // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
033: // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
034: //
035: package org.xbill.DNS;
036:
037: import junit.framework.TestCase;
038:
039: public class OptionsTest extends TestCase {
040: public void setUp() {
041: // reset the options table before each test
042: Options.clear();
043: }
044:
045: public void test_set_1arg() {
046: Options.set("Option1");
047: assertEquals("true", Options.value("option1"));
048:
049: Options.set("OPTION2");
050: assertEquals("true", Options.value("option1"));
051: assertEquals("true", Options.value("OpTIOn2"));
052:
053: Options.set("option2");
054: assertEquals("true", Options.value("option2"));
055: }
056:
057: public void test_set_2arg() {
058: Options.set("OPTION1", "Value1");
059: assertEquals("value1", Options.value("Option1"));
060:
061: Options.set("option2", "value2");
062: assertEquals("value1", Options.value("Option1"));
063: assertEquals("value2", Options.value("OPTION2"));
064:
065: Options.set("OPTION2", "value2b");
066: assertEquals("value1", Options.value("Option1"));
067: assertEquals("value2b", Options.value("option2"));
068: }
069:
070: public void test_check() {
071: assertFalse(Options.check("No Options yet"));
072:
073: Options.set("First Option");
074: assertFalse(Options.check("Not a valid option name"));
075: assertTrue(Options.check("First Option"));
076: assertTrue(Options.check("FIRST option"));
077: }
078:
079: public void test_unset() {
080: // unset something non-existant
081: Options.unset("Not an option Name");
082:
083: Options.set("Temporary Option");
084: assertTrue(Options.check("Temporary Option"));
085: Options.unset("Temporary Option");
086: assertFalse(Options.check("Temporary Option"));
087:
088: Options.set("Temporary Option");
089: assertTrue(Options.check("Temporary Option"));
090: Options.unset("temporary option");
091: assertFalse(Options.check("Temporary Option"));
092:
093: // unset something now that the table is non-null
094: Options.unset("Still Not an Option Name");
095: }
096:
097: public void test_value() {
098: assertNull(Options.value("Table is Null"));
099:
100: Options.set("Testing Option");
101: assertNull(Options.value("Not an Option Name"));
102:
103: assertEquals("true", Options.value("Testing OPTION"));
104: }
105:
106: public void test_intValue() {
107: assertEquals(-1, Options.intValue("Table is Null"));
108:
109: Options.set("A Boolean Option");
110: Options.set("An Int Option", "13");
111: Options.set("Not An Int Option", "NotAnInt");
112: Options.set("A Negative Int Value", "-1000");
113:
114: assertEquals(-1, Options.intValue("A Boolean Option"));
115: assertEquals(-1, Options.intValue("Not an Option NAME"));
116: assertEquals(13, Options.intValue("an int option"));
117: assertEquals(-1, Options.intValue("NOT an INT option"));
118: assertEquals(-1, Options.intValue("A negative int Value"));
119: }
120:
121: public void test_systemProperty() {
122: System
123: .setProperty("dnsjava.options",
124: "booleanOption,valuedOption1=10,valuedOption2=NotAnInteger");
125:
126: Options.refresh();
127:
128: assertTrue(Options.check("booleanOPTION"));
129: assertTrue(Options.check("booleanOption"));
130: assertTrue(Options.check("valuedOption1"));
131: assertTrue(Options.check("ValuedOption2"));
132:
133: assertEquals("true", Options.value("booleanOption"));
134: assertEquals(-1, Options.intValue("BOOLEANOPTION"));
135: assertEquals("10", Options.value("valuedOption1"));
136: assertEquals(10, Options.intValue("valuedOption1"));
137: assertEquals("notaninteger", Options.value("VALUEDOPTION2"));
138: assertEquals(-1, Options.intValue("valuedOption2"));
139: }
140: }
|