Author: tfischer
Date: Wed Jan 23 20:59:17 2013
New Revision: 1437728
URL: http://svn.apache.org/viewvc?rev=1437728&view=rev
Log:
move clob and blob tests to own test classes
Added:
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/BlobTest.java
(with props)
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/ClobTest.java
(with props)
Modified:
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
Modified:
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java?rev=1437728&r1=1437727&r2=1437728&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
(original)
+++
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
Wed Jan 23 20:59:17 2013
@@ -21,7 +21,6 @@ package org.apache.torque;
import java.sql.Connection;
import java.sql.ResultSet;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -44,9 +43,7 @@ import org.apache.torque.test.Inheritanc
import org.apache.torque.test.InheritanceClassnameTestChild2;
import org.apache.torque.test.dbobject.Author;
import org.apache.torque.test.dbobject.BigintType;
-import org.apache.torque.test.dbobject.BlobType;
import org.apache.torque.test.dbobject.Book;
-import org.apache.torque.test.dbobject.ClobType;
import org.apache.torque.test.dbobject.CompPkContainsFk;
import org.apache.torque.test.dbobject.IfcTable;
import org.apache.torque.test.dbobject.InheritanceChildB;
@@ -63,9 +60,7 @@ import org.apache.torque.test.dbobject.O
import org.apache.torque.test.dbobject.VarcharType;
import org.apache.torque.test.peer.AuthorPeer;
import org.apache.torque.test.peer.BigintTypePeer;
-import org.apache.torque.test.peer.BlobTypePeer;
import org.apache.torque.test.peer.BookPeer;
-import org.apache.torque.test.peer.ClobTypePeer;
import org.apache.torque.test.peer.CompPkContainsFkPeer;
import org.apache.torque.test.peer.IfcTablePeer;
import org.apache.torque.test.peer.InheritanceClassnameTestPeer;
@@ -996,132 +991,6 @@ public class DataTest extends BaseDataba
author.save();
}
-
- /**
- * check that blob cloumns can be read and written correctly
- * @throws Exception if the test fails
- */
- public void testBlobs() throws Exception
- {
- BlobTypePeer.doDelete(new Criteria());
-
- // create a new BlobType Object with large blob values
- // and save it
- BlobType blobType = new BlobType();
- {
- int length = 100000;
- byte[] bytes = new byte[length];
- for (int i = 0; i < length; ++i)
- {
- bytes[i] = new Integer(i % 256).byteValue();
- }
- blobType.setBlobValue(bytes);
- }
- blobType.save();
-
- // read the BlobTypes from the database
- // and check the values against the original values
- List<BlobType> blobTypeList = BlobTypePeer.doSelect(new Criteria());
- assertEquals(1, blobTypeList.size());
-
- BlobType readBlobType = blobTypeList.get(0);
- assertTrue("read and written blobs should be equal. "
- + "Size of read blob is"
- + readBlobType.getBlobValue().length
- + " size of written blob is "
- + blobType.getBlobValue().length,
- Arrays.equals(
- blobType.getBlobValue(),
- readBlobType.getBlobValue()));
-
- // test updating
- blobType = readBlobType;
- {
- int length = 200000;
- byte[] bytes = new byte[length];
- StringBuffer chars = new StringBuffer();
- String charTemplate = "9876543210abcdefghijklmnopqrstuvwxyz";
- for (int i = 0; i < length; ++i)
- {
- bytes[i] = new Integer(i % 256).byteValue();
- chars.append(charTemplate.charAt(i % charTemplate.length()));
- }
- blobType.setBlobValue(bytes);
- }
- blobType.save();
-
- // read the BlobTypes from the database
- // and check the values against the updated values
- blobTypeList = BlobTypePeer.doSelect(new Criteria());
- assertEquals(1, blobTypeList.size());
-
- readBlobType = blobTypeList.get(0);
- assertTrue("read and written blobs should be equal. "
- + "Size of read blob is"
- + readBlobType.getBlobValue().length
- + " size of written blob is "
- + blobType.getBlobValue().length,
- Arrays.equals(
- blobType.getBlobValue(),
- readBlobType.getBlobValue()));
- }
-
-
- /**
- * check that clob cloumns can be read and written correctly
- * @throws Exception if the test fails
- */
- public void testClobs() throws Exception
- {
- ClobTypePeer.doDelete(new Criteria());
-
- // create a new ClobType Object with a large clob value
- // and save it
- ClobType clobType = new ClobType();
- {
- int length = 40000;
- StringBuffer chars = new StringBuffer();
- String charTemplate = "1234567890abcdefghijklmnopqrstuvwxyz";
- for (int i = 0; i < length; ++i)
- {
- chars.append(charTemplate.charAt(i % charTemplate.length()));
- }
- clobType.setClobValue(chars.toString());
- }
- clobType.save();
-
- // read the ClobTypes from the database
- // and check the values against the original values
- List<ClobType> clobTypeList = ClobTypePeer.doSelect(new Criteria());
- assertEquals(1, clobTypeList.size());
-
- ClobType readClobType = clobTypeList.get(0);
- assertEquals(clobType.getClobValue(), readClobType.getClobValue());
-
-
- // Test updating
- clobType = readClobType;
- {
- int length = 50000;
- StringBuffer chars = new StringBuffer();
- String charTemplate = "0987654321abcdefghijklmnopqrstuvwxyz";
- for (int i = 0; i < length; ++i)
- {
- chars.append(charTemplate.charAt(i % charTemplate.length()));
- }
- clobType.setClobValue(chars.toString());
- }
- clobType.save();
-
- // read the ClobTypes from the database
- // and check the values against the original values
- clobTypeList = ClobTypePeer.doSelect(new Criteria());
- assertEquals(1, clobTypeList.size());
-
- readClobType = clobTypeList.get(0);
- assertEquals(clobType.getClobValue(), readClobType.getClobValue());
- }
-
/**
* Test whether equals() is working correctly
* @throws Exception
Added:
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/BlobTest.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/BlobTest.java?rev=1437728&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/BlobTest.java
(added)
+++
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/BlobTest.java
Wed Jan 23 20:59:17 2013
@@ -0,0 +1,108 @@
+package org.apache.torque.datatypes;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.torque.BaseDatabaseTestCase;
+import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.Criteria;
+import org.apache.torque.test.dbobject.BlobType;
+import org.apache.torque.test.peer.BlobTypePeer;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Tests the data type BLOB.
+ * @version $Id$
+ */
+public class BlobTest extends BaseDatabaseTestCase
+{
+ /**
+ * check that blob cloumns can be read and written correctly
+ * @throws Exception if the test fails
+ */
+ public void testBlobs() throws Exception
+ {
+ BlobTypePeer.doDelete(new Criteria());
+
+ // create a new BlobType Object with large blob values
+ // and save it
+ BlobType blobType = fillAndSaveBlobType(new BlobType(), 100000);
+
+ // read the BlobTypes from the database
+ // and check the values against the original values
+ List<BlobType> blobTypeList = BlobTypePeer.doSelect(new Criteria());
+ assertEquals(1, blobTypeList.size());
+
+ BlobType readBlobType = blobTypeList.get(0);
+ assertTrue("read and written blobs should be equal. "
+ + "Size of read blob is"
+ + readBlobType.getBlobValue().length
+ + " size of written blob is "
+ + blobType.getBlobValue().length,
+ Arrays.equals(
+ blobType.getBlobValue(),
+ readBlobType.getBlobValue()));
+
+ // test updating
+ blobType = readBlobType;
+ fillAndSaveBlobType(blobType, 200000);
+
+ // read the BlobTypes from the database
+ // and check the values against the updated values
+ blobTypeList = BlobTypePeer.doSelect(new Criteria());
+ assertEquals(1, blobTypeList.size());
+
+ readBlobType = blobTypeList.get(0);
+ assertTrue("read and written blobs should be equal. "
+ + "Size of read blob is"
+ + readBlobType.getBlobValue().length
+ + " size of written blob is "
+ + blobType.getBlobValue().length,
+ Arrays.equals(
+ blobType.getBlobValue(),
+ readBlobType.getBlobValue()));
+ }
+
+ /**
+ * Fills the Blob in a BlobType, writes it to to the database and returns
it.
+ *
+ * @param blobType the blobType to fill and save, not null.
+ * @param size the size of the blob.
+ *
+ * @return the updated BlobType.
+ *
+ * @throws TorqueException if saving fails
+ */
+ private BlobType fillAndSaveBlobType(BlobType blobType, int size)
+ throws TorqueException
+ {
+ {
+ byte[] bytes = new byte[size];
+ for (int i = 0; i < size; ++i)
+ {
+ bytes[i] = new Integer(i % 256).byteValue();
+ }
+ blobType.setBlobValue(bytes);
+ }
+ blobType.save();
+ return blobType;
+ }
+}
Propchange:
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/BlobTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/ClobTest.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/ClobTest.java?rev=1437728&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/ClobTest.java
(added)
+++
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/ClobTest.java
Wed Jan 23 20:59:17 2013
@@ -0,0 +1,111 @@
+package org.apache.torque.datatypes;
+
+import java.util.List;
+
+import org.apache.torque.BaseDatabaseTestCase;
+import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.Criteria;
+import org.apache.torque.test.dbobject.ClobType;
+import org.apache.torque.test.peer.ClobTypePeer;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Tests the data type CLOB.
+ * @version $Id$
+ */
+public class ClobTest extends BaseDatabaseTestCase
+{
+ /**
+ * Check that clob columns can be created and read.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testCreateAndReadClobs() throws Exception
+ {
+ ClobTypePeer.doDelete(new Criteria());
+
+ ClobType clobType = fillAndSaveClobType(
+ new ClobType(),
+ 40000,
+ "1234567890abcdefghijklmnopqrstuvwxyz");
+
+ // read the ClobTypes from the database
+ // and check the values against the original values
+ List<ClobType> clobTypeList = ClobTypePeer.doSelect(new Criteria());
+ assertEquals(1, clobTypeList.size());
+
+ ClobType readClobType = clobTypeList.get(0);
+ assertEquals(clobType.getClobValue(), readClobType.getClobValue());
+ }
+
+ /**
+ * Check that clob columns can be updated and read correctly.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testUpdateClobs() throws Exception
+ {
+ ClobType clobType = fillAndSaveClobType(
+ new ClobType(),
+ 40000,
+ "1234567890abcdefghijklmnopqrstuvwxyz");
+ clobType = ClobTypePeer.doSelectSingleRecord(clobType);
+ fillAndSaveClobType(
+ clobType,
+ 50000,
+ "0987654321abcdefghijklmnopqrstuvwxyz");
+
+ // read the ClobTypes from the database
+ // and check the values against the original values
+ List<ClobType> clobTypeList = ClobTypePeer.doSelect(new Criteria());
+ assertEquals(1, clobTypeList.size());
+
+ ClobType readClobType = clobTypeList.get(0);
+ assertEquals(clobType.getClobValue(), readClobType.getClobValue());
+ }
+
+ /**
+ * Fills the Clob in a ClobType, writes it to to the database and returns
it.
+ *
+ * @param clobType the clobType to fill and save, not null.
+ * @param size the size of the clob.
+ * @param charTemplate the template to use for filling, not null.
+ *
+ * @return the changed ClobType.
+ *
+ * @throws TorqueException if saving fails
+ */
+ private ClobType fillAndSaveClobType(
+ ClobType clobType, int size, String charTemplate)
+ throws TorqueException
+ {
+ {
+ StringBuffer chars = new StringBuffer();
+ for (int i = 0; i < size; ++i)
+ {
+ chars.append(charTemplate.charAt(i % charTemplate.length()));
+ }
+ clobType.setClobValue(chars.toString());
+ }
+ clobType.save();
+ return clobType;
+ }
+}
Propchange:
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/ClobTest.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]