001: /*
002: * $Id: TestSequence.java,v 1.5 2004/10/14 17:39:28 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2002 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:
041: package org.axiondb;
042:
043: import java.math.BigInteger;
044:
045: import org.axiondb.types.IntegerType;
046:
047: import junit.framework.Test;
048: import junit.framework.TestCase;
049: import junit.framework.TestSuite;
050:
051: /**
052: * @version $Revision: 1.5 $ $Date: 2004/10/14 17:39:28 $
053: * @author Chuck Burdick
054: * @author Ahimanikya Satapathy
055: */
056: public class TestSequence extends TestCase {
057:
058: //------------------------------------------------------------ Conventional
059:
060: public TestSequence(String testName) {
061: super (testName);
062: }
063:
064: public static void main(String args[]) {
065: String[] testCaseName = { TestSequence.class.getName() };
066: junit.textui.TestRunner.main(testCaseName);
067: }
068:
069: public static Test suite() {
070: return new TestSuite(TestSequence.class);
071: }
072:
073: //--------------------------------------------------------------- Lifecycle
074:
075: private Sequence _seq = null;
076:
077: public void setUp() {
078: _seq = new Sequence("foo", 0);
079: }
080:
081: public void tearDown() {
082: }
083:
084: //-------------------------------------------------------------------- Util
085:
086: //------------------------------------------------------------------- Tests
087:
088: public void testSequence() throws Exception {
089: for (int i = 0; i < 10; i++) {
090: assertEquals(
091: "For access num " + i + " should get next val",
092: new Integer(i), _seq.evaluate());
093: }
094: }
095:
096: public void testSequenceBad() throws Exception {
097: DataType type = new IntegerType();
098:
099: // IncrementBy value should be non-zero numeric
100: try {
101: _seq = getSequence("foo", type, 10, 0, -1, -1, false);
102: fail("Expected IllegalArgumentException");
103: } catch (IllegalArgumentException ex) {
104: // expected
105: }
106:
107: // StartValue value should be greater than MinValue
108: try {
109: _seq = getSequence("foo", type, 0, 1, 100, 1, false);
110: fail("Expected IllegalArgumentException");
111: } catch (IllegalArgumentException ex) {
112: // expected
113: }
114:
115: // MaxValue value should be greater than MinValue
116: try {
117: _seq = getSequence("foo", type, 101, 1, 1, 100, false);
118: fail("Expected IllegalArgumentException");
119: } catch (IllegalArgumentException ex) {
120: // expected
121: }
122:
123: _seq = getSequence("foo", type, 0, -10, 20, 0, true);
124: assertEquals(new Integer(0), _seq.evaluate());
125: assertEquals(new Integer(20), _seq.evaluate());
126: assertEquals(new Integer(10), _seq.evaluate());
127: assertEquals(new Integer(0), _seq.evaluate());
128:
129: _seq = getSequence("foo", type, 0, 10, 20, 0, true);
130: assertEquals(new Integer(0), _seq.evaluate());
131: assertEquals(new Integer(10), _seq.evaluate());
132: assertEquals(new Integer(20), _seq.evaluate());
133: assertEquals(new Integer(0), _seq.evaluate());
134: assertTrue(_seq.equals(_seq));
135:
136: assertFalse(_seq.equals(new Literal("abc")));
137: }
138:
139: private Sequence getSequence(String name, DataType type,
140: int startVal, int incrementBy, int maxValue, int minValue,
141: boolean isCycle) {
142: return new Sequence(name, type, BI(startVal), BI(incrementBy),
143: BI(maxValue), BI(minValue), isCycle);
144: }
145:
146: private BigInteger BI(long value) {
147: return BigInteger.valueOf(value);
148: }
149: }
|