001: /*
002: * TestSpecialNumbers.java
003: *
004: * Created on October 13, 2006, 4:56 PM
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009: /*
010: * Licensed to the Apache Software Foundation (ASF) under one
011: * or more contributor license agreements. See the NOTICE file
012: * distributed with this work for additional information
013: * regarding copyright ownership. The ASF licenses this file
014: * to you under the Apache License, Version 2.0 (the
015: * "License"); you may not use this file except in compliance
016: * with the License. You may obtain a copy of the License at
017: *
018: * http://www.apache.org/licenses/LICENSE-2.0
019: *
020: * Unless required by applicable law or agreed to in writing,
021: * software distributed under the License is distributed on an
022: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
023: * KIND, either express or implied. See the License for the
024: * specific language governing permissions and limitations
025: * under the License.
026: */
027: package org.apache.openjpa.persistence.kernel;
028:
029: import java.math.BigInteger;
030: import java.util.Collection;
031: import java.util.EnumSet;
032:
033: import org.apache.openjpa.persistence.kernel.common.apps.AllFieldTypesTest;
034: import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
035: import junit.framework.AssertionFailedError;
036:
037: import org.apache.openjpa.persistence.OpenJPAEntityManager;
038: import org.apache.openjpa.persistence.OpenJPAQuery;
039:
040: public class TestSpecialNumbers extends BaseKernelTest {
041:
042: /**
043: * Creates a new instance of TestSpecialNumbers
044: */
045: public TestSpecialNumbers() {
046: }
047:
048: public TestSpecialNumbers(String name) {
049: super (name);
050: }
051:
052: public void setUp() {
053: try {
054: deleteAll(AllFieldTypesTest.class);
055: } catch (Exception e) {
056: // catch errors when deleting ... PostgreSQL has
057: // a couple problems with some of the values that
058: // try to get inserted.
059: }
060: }
061:
062: public void testShortMax() {
063: AllFieldTypesTest aftt = new AllFieldTypesTest();
064: aftt.setTestshort(Short.MAX_VALUE);
065: saveAndQuery(aftt, "testshort = :param", new Short(
066: Short.MAX_VALUE));
067: }
068:
069: public void testShortMin() {
070: AllFieldTypesTest aftt = new AllFieldTypesTest();
071: aftt.setTestshort(Short.MIN_VALUE);
072: try {
073: saveAndQuery(aftt, "testshort = :param", new Short(
074: Short.MIN_VALUE));
075: } catch (Throwable t) {
076: bug(AbstractTestCase.Platform.EMPRESS, 889, t,
077: "Empress cannot store min values");
078: }
079: }
080:
081: public void testLongMax() {
082: AllFieldTypesTest aftt = new AllFieldTypesTest();
083: aftt.setTestlong(Long.MAX_VALUE);
084: saveAndQuery(aftt, "testlong = :param",
085: new Long(Long.MAX_VALUE));
086: }
087:
088: public void testLongMin() {
089: try {
090: AllFieldTypesTest aftt = new AllFieldTypesTest();
091: aftt.setTestlong(Long.MIN_VALUE);
092: saveAndQuery(aftt, "testlong = :param", new Long(
093: Long.MIN_VALUE));
094: } catch (Throwable t) {
095: bug(AbstractTestCase.Platform.HYPERSONIC, 474, t,
096: "Some databases cannot store Long.MIN_VALUE");
097: }
098: }
099:
100: public void testIntegerMax() {
101: AllFieldTypesTest aftt = new AllFieldTypesTest();
102: aftt.setTestint(Integer.MAX_VALUE);
103: saveAndQuery(aftt, "testint = :param", new Integer(
104: Integer.MAX_VALUE));
105: }
106:
107: public void testIntegerMin() {
108: AllFieldTypesTest aftt = new AllFieldTypesTest();
109: aftt.setTestint(Integer.MIN_VALUE);
110: try {
111: saveAndQuery(aftt, "testint = :param", new Integer(
112: Integer.MIN_VALUE));
113: } catch (Throwable t) {
114: bug(AbstractTestCase.Platform.EMPRESS, 889, t,
115: "Empress cannot store min values");
116: }
117: }
118:
119: public void testFloatMax() {
120: try {
121: AllFieldTypesTest aftt = new AllFieldTypesTest();
122: aftt.setTestfloat(Float.MAX_VALUE);
123: saveAndQuery(aftt, "testfloat = :param", new Float(
124: Float.MAX_VALUE));
125: } catch (Exception e) {
126: bug(EnumSet.of(AbstractTestCase.Platform.POSTGRESQL,
127: AbstractTestCase.Platform.DB2,
128: AbstractTestCase.Platform.MYSQL,
129: AbstractTestCase.Platform.DERBY), 494, e,
130: "Some datastores cannot store Float.MAX_VALUE");
131: }
132: }
133:
134: public void testFloatMin() {
135: try {
136: AllFieldTypesTest aftt = new AllFieldTypesTest();
137: aftt.setTestfloat(Float.MIN_VALUE);
138: saveAndQuery(aftt, "testfloat = :param", new Float(
139: Float.MIN_VALUE));
140: } catch (Exception e) {
141: bug(EnumSet.of(AbstractTestCase.Platform.POSTGRESQL,
142: AbstractTestCase.Platform.SQLSERVER,
143: AbstractTestCase.Platform.DB2,
144: AbstractTestCase.Platform.INFORMIX,
145: AbstractTestCase.Platform.DERBY), 494, e,
146: "Some databases cannot store Float.MIN_VALUE");
147: } catch (AssertionFailedError e) {
148: bug(EnumSet.of(AbstractTestCase.Platform.MYSQL,
149: AbstractTestCase.Platform.SQLSERVER), 494, e,
150: "Some databases cannot store Float.MIN_VALUE");
151: }
152: }
153:
154: public void testFloatNaN() {
155: try {
156: AllFieldTypesTest aftt = new AllFieldTypesTest();
157: aftt.setTestfloat(Float.NaN);
158: saveAndQuery(aftt, "testfloat = :param", new Float(
159: Float.NaN));
160: } catch (Throwable t) {
161: bug(461, t, "NaN problems");
162: }
163: }
164:
165: public void testFloatNegativeInfinity() {
166: try {
167: AllFieldTypesTest aftt = new AllFieldTypesTest();
168: aftt.setTestfloat(Float.NEGATIVE_INFINITY);
169: saveAndQuery(aftt, "testfloat = :param", new Float(
170: Float.NEGATIVE_INFINITY));
171: } catch (Exception e) {
172: bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
173: AbstractTestCase.Platform.POSTGRESQL,
174: AbstractTestCase.Platform.MYSQL,
175: AbstractTestCase.Platform.DB2,
176: AbstractTestCase.Platform.ORACLE,
177: AbstractTestCase.Platform.INFORMIX,
178: AbstractTestCase.Platform.DERBY,
179: AbstractTestCase.Platform.SQLSERVER), 494, e,
180: "Some databases cannot store Float.NEGATIVE_INFINITY");
181: }
182: }
183:
184: public void testFloatPostivieInfinity() {
185: try {
186: AllFieldTypesTest aftt = new AllFieldTypesTest();
187: aftt.setTestfloat(Float.POSITIVE_INFINITY);
188: saveAndQuery(aftt, "testfloat = :param", new Float(
189: Float.POSITIVE_INFINITY));
190: } catch (Exception e) {
191: bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
192: AbstractTestCase.Platform.POSTGRESQL,
193: AbstractTestCase.Platform.MYSQL,
194: AbstractTestCase.Platform.DB2,
195: AbstractTestCase.Platform.ORACLE,
196: AbstractTestCase.Platform.INFORMIX,
197: AbstractTestCase.Platform.DERBY,
198: AbstractTestCase.Platform.SQLSERVER), 494, e,
199: "Some databases cannot store Float.POSITIVE_INFINITY");
200: }
201: }
202:
203: public void testDoubleMax() {
204: try {
205: AllFieldTypesTest aftt = new AllFieldTypesTest();
206: aftt.setTestdouble(Double.MAX_VALUE);
207: saveAndQuery(aftt, "testdouble = :param", new Double(
208: Double.MAX_VALUE));
209: } catch (Exception e) {
210: bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
211: AbstractTestCase.Platform.MYSQL,
212: AbstractTestCase.Platform.ORACLE,
213: AbstractTestCase.Platform.POSTGRESQL,
214: AbstractTestCase.Platform.EMPRESS,
215: AbstractTestCase.Platform.DB2,
216: AbstractTestCase.Platform.INFORMIX,
217: AbstractTestCase.Platform.DERBY), 494, e,
218: "Some databases cannot store Double.MAX_VALUE");
219: }
220: }
221:
222: public void testDoubleMin() {
223: try {
224: AllFieldTypesTest aftt = new AllFieldTypesTest();
225: aftt.setTestdouble(Double.MIN_VALUE);
226: saveAndQuery(aftt, "testdouble = :param", new Double(
227: Double.MIN_VALUE));
228: } catch (Exception e) {
229: bug(EnumSet.of(AbstractTestCase.Platform.POSTGRESQL,
230: AbstractTestCase.Platform.SQLSERVER,
231: AbstractTestCase.Platform.ORACLE,
232: AbstractTestCase.Platform.EMPRESS,
233: AbstractTestCase.Platform.DB2,
234: AbstractTestCase.Platform.INFORMIX,
235: AbstractTestCase.Platform.DERBY), 494, e,
236: "Some databases cannot store Double.MIN_VALUE");
237: } catch (AssertionFailedError e) {
238: bug(AbstractTestCase.Platform.MYSQL, 494, e,
239: "Some databases cannot store Double.MIN_VALUE");
240: }
241: }
242:
243: public void testDoubleNaN() {
244: try {
245: AllFieldTypesTest aftt = new AllFieldTypesTest();
246: aftt.setTestdouble(Double.NaN);
247: saveAndQuery(aftt, "testdouble = :param", new Double(
248: Double.NaN));
249: } catch (Throwable t) {
250: bug(461, t, "NaN problems");
251: }
252: }
253:
254: public void testDoubleNegativeInfinity() {
255: try {
256: AllFieldTypesTest aftt = new AllFieldTypesTest();
257: aftt.setTestdouble(Double.NEGATIVE_INFINITY);
258: saveAndQuery(aftt, "testdouble = :param", new Double(
259: Double.NEGATIVE_INFINITY));
260: } catch (Throwable t) {
261: bug(461, t, "infinity problems");
262: }
263: }
264:
265: public void testDoublePostivieInfinity() {
266: try {
267: AllFieldTypesTest aftt = new AllFieldTypesTest();
268: aftt.setTestdouble(Double.POSITIVE_INFINITY);
269: saveAndQuery(aftt, "testdouble = :param", new Double(
270: Double.POSITIVE_INFINITY));
271: } catch (Throwable t) {
272: bug(461, t, "infinity problems");
273: }
274: }
275:
276: public void testByteMin() {
277: AllFieldTypesTest aftt = new AllFieldTypesTest();
278: aftt.setTestbyte(Byte.MIN_VALUE);
279: try {
280: saveAndQuery(aftt, "testbyte = :param", new Byte(
281: Byte.MIN_VALUE));
282: } catch (Throwable t) {
283: bug(AbstractTestCase.Platform.EMPRESS, 889, t,
284: "Empress cannot store min values");
285: }
286: }
287:
288: public void testByteMax() {
289: AllFieldTypesTest aftt = new AllFieldTypesTest();
290: aftt.setTestbyte(Byte.MAX_VALUE);
291: saveAndQuery(aftt, "testbyte = :param",
292: new Byte(Byte.MAX_VALUE));
293: }
294:
295: public void testZeroBigInteger() {
296: AllFieldTypesTest aftt = new AllFieldTypesTest();
297: aftt.setTestBigInteger(BigInteger.ZERO);
298: saveAndQuery(aftt, "testBigInteger = :param", BigInteger.ZERO);
299: }
300:
301: public void testOneBigInteger() {
302: AllFieldTypesTest aftt = new AllFieldTypesTest();
303: aftt.setTestBigInteger(BigInteger.ONE);
304: saveAndQuery(aftt, "testBigInteger = :param", BigInteger.ONE);
305: }
306:
307: private void saveAndQuery(Object obj, String query, Object param) {
308: OpenJPAEntityManager pm = getPM();
309: startTx(pm);
310: pm.persist(obj);
311: endTx(pm);
312: endEm(pm);
313:
314: pm = getPM();
315: OpenJPAQuery q = pm.createQuery("select o from "
316: + obj.getClass().getName() + " o where " + query);
317: q.setParameter("param", param);
318: Collection c = (Collection) q.getResultList();
319: assertSize(1, c);
320: endEm(pm);
321: }
322: }
|