001: /*
002: * $Id: TestIfThenFunction.java,v 1.6 2005/06/18 01:03:44 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2003-2005 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040: package org.axiondb.functions;
041:
042: import java.util.HashMap;
043: import java.util.Map;
044:
045: import junit.framework.Test;
046: import junit.framework.TestSuite;
047:
048: import org.axiondb.ColumnIdentifier;
049: import org.axiondb.RowDecorator;
050: import org.axiondb.engine.rows.SimpleRow;
051:
052: /**
053: * @version $Revision: 1.6 $ $Date: 2005/06/18 01:03:44 $
054: * @author Rodney Waldhoff
055: * @author Jonathan Giron
056: */
057: public class TestIfThenFunction extends BaseFunctionTest {
058:
059: //------------------------------------------------------------ Conventional
060:
061: public TestIfThenFunction(String testName) {
062: super (testName);
063: }
064:
065: public static Test suite() {
066: TestSuite suite = new TestSuite(TestIfThenFunction.class);
067: return suite;
068: }
069:
070: //--------------------------------------------------------------- Lifecycle
071:
072: private RowDecorator _dec = null;
073: private ColumnIdentifier _cola, _colb = null;
074: private IfThenFunction _function = null;
075:
076: public void setUp() throws Exception {
077: super .setUp();
078: _cola = new ColumnIdentifier("A");
079: _colb = new ColumnIdentifier("B");
080: Map map = new HashMap();
081: map.put(_cola, new Integer(0));
082: map.put(_colb, new Integer(1));
083: _dec = new RowDecorator(map);
084: _function = new IfThenFunction();
085: _function.addArgument(_cola);
086: _function.addArgument(_colb);
087: }
088:
089: public void tearDown() throws Exception {
090: super .tearDown();
091: _cola = null;
092: _colb = null;
093: _dec = null;
094: _function = null;
095: }
096:
097: //--------------------------------------------------------------- Framework
098:
099: protected ConcreteFunction makeFunction() {
100: return new IfThenFunction();
101: }
102:
103: //------------------------------------------------------------------- Tests
104:
105: public void testMakeNewInstance() {
106: IfThenFunction function = new IfThenFunction();
107: assertTrue(function.makeNewInstance() instanceof IfThenFunction);
108: assertTrue(function.makeNewInstance() != function
109: .makeNewInstance());
110: }
111:
112: public void testEvaluateWhenTrue() throws Exception {
113: _dec
114: .setRow(new SimpleRow(new Object[] { Boolean.TRUE,
115: "foo" }));
116: assertEquals("foo", _function.evaluate(_dec));
117: }
118:
119: public void testEvaluateWhenFalse() throws Exception {
120: _dec
121: .setRow(new SimpleRow(new Object[] { Boolean.FALSE,
122: "foo" }));
123: assertNull(_function.evaluate(_dec));
124: }
125:
126: public void testEvaluateWhenNull() throws Exception {
127: _dec.setRow(new SimpleRow(new Object[] { null, "foo" }));
128: assertNull(_function.evaluate(_dec));
129: }
130:
131: public void testValid() throws Exception {
132: IfThenFunction function = new IfThenFunction();
133: assertTrue(!function.isValid());
134: function.addArgument(_cola);
135: assertTrue(!function.isValid());
136: function.addArgument(_colb);
137: assertTrue(function.isValid());
138: function.addArgument(_colb);
139: assertTrue(!function.isValid());
140: }
141: }
|