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