KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > entity > test > EntityTestSuite


1 /*
2  * $Id: EntityTestSuite.java 6132 2005-11-16 22:36:54Z sichen $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.entity.test;
26
27 import java.sql.Timestamp JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.LinkedList JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.lang.Thread JavaDoc;
35
36 import junit.framework.TestCase;
37
38 import org.ofbiz.base.util.Debug;
39 import org.ofbiz.base.util.UtilDateTime;
40 import org.ofbiz.base.util.UtilMisc;
41 import org.ofbiz.entity.GenericDelegator;
42 import org.ofbiz.entity.GenericEntity;
43 import org.ofbiz.entity.GenericEntityException;
44 import org.ofbiz.entity.GenericPK;
45 import org.ofbiz.entity.GenericValue;
46 import org.ofbiz.entity.condition.EntityCondition;
47 import org.ofbiz.entity.condition.EntityConditionList;
48 import org.ofbiz.entity.condition.EntityExpr;
49 import org.ofbiz.entity.condition.EntityOperator;
50 import org.ofbiz.entity.util.EntityFindOptions;
51 import org.ofbiz.entity.util.EntityListIterator;
52 import org.ofbiz.entity.transaction.GenericTransactionException;
53 import org.ofbiz.entity.transaction.TransactionUtil;
54
55 /**
56  *
57  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
58  * @author <a HREF="mailto:sichen@opensourcestrategies.com">Si Chen</a>
59  * @author <a HREF="mailto:m.meyer@wanadoo.fr">Manuel Meyer</a>
60  * @version $Rev: 6132 $
61  * @since Apr 16, 2005
62  */

63 public class EntityTestSuite extends TestCase {
64
65     public static final String JavaDoc module = EntityTestSuite.class.getName();
66     public static final String JavaDoc DELEGATOR_NAME = "test";
67     public GenericDelegator delegator = null;
68     /*
69      * This sets how many values to insert when trying to create a large number of values. 10,000 causes HSQL to crash but is ok
70      * with Derby. Going up to 100,000 causes problems all around because Java List seems to be capped at about 65,000 values.
71      */

72     public static final long TEST_COUNT = 10000;
73
74     public EntityTestSuite(String JavaDoc name) {
75         super(name);
76     }
77
78     final static private int _level1max = 3; // number of TestingNode entities to create
79

80     protected void setUp() throws Exception JavaDoc {
81         this.delegator = GenericDelegator.getGenericDelegator(DELEGATOR_NAME);
82     }
83     
84     /*
85      * Tests storing values with the delegator's .create, .makeValue, and .storeAll methods
86      */

87     public void testMakeValue() throws Exception JavaDoc {
88         try {
89             // This method call directly stores a new value into the entity engine
90
delegator.create("TestingType", UtilMisc.toMap("testingTypeId", "TEST-1", "description", "Testing Type #1"));
91
92             // This sequence creates the GenericValue entities first, puts them in a List, then calls the delegator to store them all
93
List JavaDoc newValues = new LinkedList JavaDoc();
94
95             newValues.add(delegator.makeValue("TestingType", UtilMisc.toMap("testingTypeId", "TEST-2", "description", "Testing Type #2")));
96             newValues.add(delegator.makeValue("TestingType", UtilMisc.toMap("testingTypeId", "TEST-3", "description", "Testing Type #3")));
97             newValues.add(delegator.makeValue("TestingType", UtilMisc.toMap("testingTypeId", "TEST-4", "description", "Testing Type #4")));
98             delegator.storeAll(newValues);
99
100             // finds a List of newly created values. the second parameter specifies the fields to order results by.
101
List JavaDoc newlyCreatedValues = delegator.findAll("TestingType", UtilMisc.toList("testingTypeId"));
102             TestCase.assertEquals("4 TestingTypes found", 4, newlyCreatedValues.size());
103         } catch (GenericEntityException ex) {
104             TestCase.fail(ex.getMessage());
105         }
106     }
107
108     /*
109      * Tests updating entities by doing a GenericValue .put(key, value) and .store()
110      */

111     public void testUpdateValue() throws Exception JavaDoc {
112         try {
113
114             // retrieve a sample GenericValue, make sure it's correct
115
GenericValue testValue = delegator.findByPrimaryKey("TestingType", UtilMisc.toMap("testingTypeId", "TEST-1"));
116             TestCase.assertEquals("Retrieved value has the correct description", testValue.getString("description"), "Testing Type #1");
117
118             // now update and store it
119
testValue.put("description", "New Testing Type #1");
120             testValue.store();
121
122             // now retrieve it again and make sure that the updated value is correct
123
testValue = delegator.findByPrimaryKey("TestingType", UtilMisc.toMap("testingTypeId", "TEST-1"));
124             TestCase.assertEquals("Retrieved value has the correct description", testValue.getString("description"), "New Testing Type #1");
125
126         } catch (GenericEntityException ex) {
127             TestCase.fail(ex.getMessage());
128         }
129     }
130
131     /*
132      * Tests storing data with the delegator's .create method. Also tests .findCountByCondition and .getNextSeqId
133      */

134     public void testCreateTree() throws Exception JavaDoc {
135         try {
136         // get how many child nodes did we have before creating the tree
137
EntityCondition isChild = new EntityExpr("primaryParentNodeId", EntityOperator.NOT_EQUAL, GenericEntity.NULL_FIELD);
138         long alreadyStored = delegator.findCountByCondition("TestingNode", isChild, null);
139
140         //
141
// The tree has a root, the root has level1max children.
142
//
143

144         // create the root
145
GenericValue root = delegator.create("TestingNode",
146                 UtilMisc.toMap(
147                         "testingNodeId", delegator.getNextSeqId("testingNodeId"),
148                         "primaryParentNodeId", GenericEntity.NULL_FIELD,
149                         "description", "root")
150                 );
151         int level1;
152         for(level1 = 0; level1 < _level1max; level1++) {
153             String JavaDoc nextSeqId = delegator.getNextSeqId("testingNodeId");
154             GenericValue v =
155                 delegator.create("TestingNode",
156                     UtilMisc.toMap("testingNodeId", nextSeqId,
157                                     "primaryParentNodeId", (String JavaDoc)root.get("testingNodeId"),
158                                     "description", "node-level #1")
159                                 );
160         }
161
162         long created = level1;
163         long newlyStored = delegator.findCountByCondition("TestingNode", isChild, null);
164
165         // Normally, newlyStored = alreadyStored + created
166
TestCase.assertEquals("Created/Stored Nodes", newlyStored, created + alreadyStored);
167         } catch(GenericEntityException e) {
168             Debug.logInfo(e.getMessage(), module);
169         }
170     }
171
172     /*
173      * More tests of storing data with .storeAll. Also prepares data for testing view-entities (see below.)
174      */

175     public void testAddMembersToTree() throws Exception JavaDoc {
176         // get the level1 nodes
177
EntityCondition isLevel1 = new EntityExpr("primaryParentNodeId", EntityOperator.NOT_EQUAL, GenericEntity.NULL_FIELD);
178         List JavaDoc nodeLevel1 = delegator.findByCondition("TestingNode", isLevel1, null, null);
179
180         List JavaDoc newValues = new LinkedList JavaDoc();
181         Timestamp JavaDoc now = UtilDateTime.nowTimestamp();
182
183         Iterator JavaDoc nodeIterator = nodeLevel1.iterator();
184         while(nodeIterator.hasNext()) {
185             GenericValue node = (GenericValue)nodeIterator.next();
186             GenericValue testing = delegator.makeValue("Testing",
187                     UtilMisc.toMap(
188                             "testingId", delegator.getNextSeqId("testing"),
189                             "testingTypeId", "TEST-1"
190                             )
191                     );
192             testing.put("testingName", "leaf-#" + node.getString("testingNodeId"));
193             testing.put("description", "level1 leaf");
194             testing.put("comments", "No-comments");
195             testing.put("testingSize", new Long JavaDoc(10));
196             testing.put("testingDate", now);
197
198             newValues.add(testing);
199             GenericValue member = delegator.makeValue("TestingNodeMember",
200                     UtilMisc.toMap(
201                             "testingNodeId", node.get("testingNodeId"),
202                             "testingId", testing.get("testingId")
203                             )
204                     );
205
206             member.put("fromDate", now);
207             member.put("thruDate", UtilDateTime.getNextDayStart(now));
208
209             newValues.add(member);
210         }
211         int n = delegator.storeAll(newValues);
212         TestCase.assertEquals("Created/Stored Nodes", n, newValues.size());
213     }
214
215     /*
216      * Tests findByCondition and tests searching on a view-entity
217      */

218     public void testCountViews() throws Exception JavaDoc {
219         EntityCondition isNodeWithMember = new EntityExpr("testingId", EntityOperator.NOT_EQUAL, GenericEntity.NULL_FIELD);
220         List JavaDoc nodeWithMembers = delegator.findByCondition("TestingNodeAndMember", isNodeWithMember, null, null);
221
222         Iterator JavaDoc it;
223         it = nodeWithMembers.iterator();
224
225         while(it.hasNext()) {
226             GenericValue v = (GenericValue)it.next();
227             Map JavaDoc fields = v.getAllFields();
228             Debug.logInfo("--------------------------", module);
229             // For values of a map
230
for(Iterator JavaDoc it1 = fields.keySet().iterator(); it1.hasNext(); ) {
231                 Object JavaDoc field = it1.next();
232                 Object JavaDoc value = fields.get(field);
233                 Debug.logInfo(field.toString() + " = " + ((value == null) ? "[null]" : value.toString()), module);
234             }
235         }
236         long testingcount = delegator.findCountByCondition("Testing", null, null);
237         TestCase.assertEquals("Number of views should equal number of created entities in the test.", nodeWithMembers.size(), testingcount);
238     }
239
240     /*
241      * Tests findByCondition and a find by distinct
242      */

243     public void testFindDistinct() throws Exception JavaDoc {
244         List JavaDoc exprList = UtilMisc.toList(
245                 new EntityExpr("testingSize", EntityOperator.EQUALS, new Long JavaDoc(10)),
246                 new EntityExpr("comments", EntityOperator.EQUALS, "No-comments")
247                 );
248         EntityConditionList condition = new EntityConditionList(exprList, EntityOperator.AND);
249
250         EntityFindOptions findOptions = new EntityFindOptions();
251         findOptions.setDistinct(true);
252
253         List JavaDoc testingSize10 = delegator.findByCondition("Testing", condition, null, UtilMisc.toList("testingSize", "comments"), null, findOptions);
254         Debug.logInfo("testingSize10 is " + testingSize10.size(), module);
255
256         TestCase.assertEquals("There should only be 1 result found by findDistinct()", testingSize10.size(), 1);
257     }
258
259     /*
260      * Tests a findByCondition using not like
261      */

262     public void testNotLike() throws Exception JavaDoc {
263         EntityCondition cond = new EntityExpr("description", EntityOperator.NOT_LIKE, "root%");
264         List JavaDoc nodes = delegator.findByCondition("TestingNode", cond, null, null);
265         TestCase.assertTrue("Found nodes", nodes != null);
266
267         Iterator JavaDoc i = nodes.iterator();
268         while (i.hasNext()) {
269             GenericValue product = (GenericValue) i.next();
270             String JavaDoc nodeId = product.getString("description");
271             Debug.logInfo("Testing name - " + nodeId, module);
272             TestCase.assertTrue("No nodes starting w/ root", !nodeId.startsWith("root"));
273         }
274     }
275
276     /*
277      * Tests foreign key integrity by trying to remove an entity which has foreign-key dependencies. Should cause an exception.
278      */

279     public void testForeignKeyCreate() throws Exception JavaDoc {
280         try {
281             delegator.create("Testing", UtilMisc.toMap("testingId", delegator.getNextSeqId("Testing"), "testingTypeId", "NO-SUCH-KEY"));
282         } catch(GenericEntityException e) {
283             Debug.logInfo(e.toString(), module);
284             return;
285         }
286         TestCase.fail("Foreign key referential integrity is not observed for create (INSERT)");
287     }
288
289     /*
290      * Tests foreign key integrity by trying to remove an entity which has foreign-key dependencies. Should cause an exception.
291      */

292     public void testForeignKeyRemove() throws Exception JavaDoc {
293         try {
294             EntityCondition isLevel1 = new EntityExpr("description", EntityOperator.EQUALS, "node-level #1");
295             delegator.removeByCondition("TestingNode", isLevel1);
296         } catch(GenericEntityException e) {
297             Debug.logInfo(e.toString(), module);
298             return;
299         }
300         TestCase.fail("Foreign key referential integrity is not observed for remove (DELETE)");
301     }
302
303     /*
304      * Tests the .getRelatedOne method and removeAll for removing entities
305      */

306     public void testRemoveNodeMemberAndTesting() throws Exception JavaDoc {
307             //
308
// Find the testing entities tru the node member and build a list of them
309
//
310
List JavaDoc values = delegator.findAll("TestingNodeMember");
311             Iterator JavaDoc i = values.iterator();
312
313             ArrayList JavaDoc testings = new ArrayList JavaDoc();
314
315             while(i.hasNext()) {
316                 GenericValue nodeMember = (GenericValue)i.next();
317                 testings.add(nodeMember.getRelatedOne("Testing"));
318             }
319             // and remove the nodeMember afterwards
320
delegator.removeAll(values);
321             values = delegator.findAll("TestingNodeMember");
322             TestCase.assertTrue("No more Node Member entities", values.size() == 0);
323
324             delegator.removeAll(testings);
325             values = delegator.findAll("Testing");
326             TestCase.assertTrue("No more Testing entities", values.size() == 0);
327     }
328
329     /*
330      * Tests the storeByCondition operation
331      */

332     public void testStoreByCondition() throws Exception JavaDoc {
333         // change the description of all the level1 nodes
334
EntityCondition isLevel1 = new EntityExpr("description", EntityOperator.EQUALS, "node-level #1");
335         Map JavaDoc fieldsToSet = UtilMisc.toMap("description", "node-level #1 (updated)");
336         int n = 0;
337         try {
338             delegator.storeByCondition("TestingNode", fieldsToSet, isLevel1);
339             List JavaDoc updatedNodes = delegator.findByAnd("TestingNode", fieldsToSet);
340             n = updatedNodes.size();
341         } catch (GenericEntityException e) {
342             TestCase.fail("testStoreByCondition threw an exception");
343         }
344
345         TestCase.assertTrue("testStoreByCondition updated nodes > 0", n > 0);
346     }
347
348     /*
349      * Tests the .removeByCondition method for removing entities directly
350      */

351     public void testRemoveByCondition() throws Exception JavaDoc {
352         //
353
// remove all the level1 nodes by using a condition on the description field
354
//
355
EntityCondition isLevel1 = new EntityExpr("description", EntityOperator.EQUALS, "node-level #1 (updated)");
356         int n = 0;
357
358         try {
359             n = delegator.removeByCondition("TestingNode", isLevel1);
360         } catch (GenericEntityException e) {
361             TestCase.fail("testRemoveByCondition threw an exception");
362         }
363
364         TestCase.assertTrue("testRemoveByCondition nodes > 0", n > 0);
365     }
366
367     /*
368      * Test the .removeByPrimaryKey by using findByCondition and then retrieving the GenericPk from a GenericValue
369      */

370     public void testRemoveByPK() throws Exception JavaDoc {
371         //
372
// Find all the root nodes,
373
// delete them their primary key
374
//
375
EntityCondition isRoot = new EntityExpr("primaryParentNodeId", EntityOperator.EQUALS, GenericEntity.NULL_FIELD);
376         List JavaDoc rootValues = delegator.findByCondition("TestingNode", isRoot, UtilMisc.toList("testingNodeId"), null);
377
378         Iterator JavaDoc it = rootValues.iterator();
379         while(it.hasNext()) {
380             GenericPK pk = ((GenericValue)it.next()).getPrimaryKey();
381             int del = delegator.removeByPrimaryKey(pk);
382             TestCase.assertEquals("Removing Root by primary key", del, 1);
383         }
384
385         // no more TestingNode should be in the data base anymore.
386

387         List JavaDoc testingNodes = delegator.findAll("TestingNode");
388         TestCase.assertEquals("No more TestingNode after removing the roots", testingNodes.size(), 0);
389     }
390
391     /*
392      * Tests the .removeAll method only.
393      */

394     public void testRemoveType() throws Exception JavaDoc {
395         List JavaDoc values = delegator.findAll("TestingType");
396         delegator.removeAll(values);
397
398         // now make sure there are no more of these
399
values = delegator.findAll("TestingType");
400         TestCase.assertEquals("No more TestingTypes after remove all", values.size(), 0);
401     }
402
403     /*
404      * This test will create a large number of unique items and add them to the delegator at once
405      */

406     public void testCreateManyAndStoreAtOnce() throws Exception JavaDoc {
407         try {
408             List JavaDoc newValues = new LinkedList JavaDoc();
409             for (int i = 0; i < TEST_COUNT; i++) {
410                 newValues.add(delegator.makeValue("Testing", UtilMisc.toMap("testingId", getTestId("T1-", i))));
411             }
412             delegator.storeAll(newValues);
413             List JavaDoc newlyCreatedValues = delegator.findAll("Testing", UtilMisc.toList("testingId"));
414             TestCase.assertEquals("Test to create " + TEST_COUNT + " and store all at once", TEST_COUNT, newlyCreatedValues.size());
415         } catch (GenericEntityException e) {
416             assertTrue("GenericEntityException:" + e.toString(), false);
417             return;
418         } finally {
419             List JavaDoc newlyCreatedValues = delegator.findAll("Testing", UtilMisc.toList("testingId"));
420             delegator.removeAll(newlyCreatedValues);
421         }
422     }
423
424     /*
425      * This test will create a large number of unique items and add them to the delegator at once
426      */

427     public void testCreateManyAndStoreOneAtATime() throws Exception JavaDoc {
428         try {
429             for (int i = 0; i < TEST_COUNT; i++){
430                 delegator.create(delegator.makeValue("Testing", UtilMisc.toMap("testingId", getTestId("T2-", i))));
431             }
432             List JavaDoc newlyCreatedValues = delegator.findAll("Testing", UtilMisc.toList("testingId"));
433             TestCase.assertEquals("Test to create " + TEST_COUNT + " and store one at a time: ", TEST_COUNT, newlyCreatedValues.size());
434         } catch (GenericEntityException e){
435             assertTrue("GenericEntityException:" + e.toString(), false);
436             return;
437         }
438     }
439  
440     /*
441      * This test will use the large number of unique items from above and test the EntityListIterator looping through the list
442      */

443     public void testEntityListIterator() throws Exception JavaDoc {
444         try {
445             EntityListIterator iterator = delegator.findListIteratorByCondition("Testing", new EntityExpr("testingId", EntityOperator.LIKE, "T2-%"), null, null);
446             assertTrue("Test if EntityListIterator was created: ", iterator != null);
447
448             int i = 0;
449             GenericValue item = (GenericValue) iterator.next();
450             while (item != null) {
451                 assertTrue("Testing if iterated data matches test data (row " + i + "): ", item.getString("testingId").equals(getTestId("T2-", i)));
452                 item = (GenericValue) iterator.next();
453                 i++;
454             }
455             assertTrue("Test if EntitlyListIterator iterates exactly " + TEST_COUNT + " times: " , i == TEST_COUNT);
456             iterator.close();
457         } catch (GenericEntityException e) {
458             assertTrue("GenericEntityException:" + e.toString(), false);
459             return;
460         } finally {
461             List JavaDoc entitiesToRemove = delegator.findByCondition("Testing", new EntityExpr("testingId", EntityOperator.LIKE, "T2-%"), null, null);
462             delegator.removeAll(entitiesToRemove);
463         }
464     }
465
466     /*
467      * This test will verify transaction rollbacks using TransactionUtil.
468      */

469     public void testTransactionUtilRollback() throws Exception JavaDoc {
470         try {
471             GenericValue testValue = delegator.makeValue("Testing", UtilMisc.toMap("testingId", "rollback-test"));
472             boolean transBegin = TransactionUtil.begin();
473             delegator.create(testValue);
474             TransactionUtil.rollback(transBegin, null, null);
475             GenericValue testValueOut = delegator.findByPrimaryKey("Testing", UtilMisc.toMap("testingId", "rollback-test"));
476             assertEquals("Test that transaction rollback removes value: ", testValueOut, null);
477         } catch (GenericEntityException e) {
478             assertTrue("GenericEntityException:" + e.toString(), false);
479             return;
480         }
481     }
482
483     /*
484      * This test will verify that a transaction which takes longer than the pre-set timeout are rolled back.
485      */

486     public void testTransactionUtilMoreThanTimeout() throws Exception JavaDoc {
487         try {
488             GenericValue testValue = delegator.makeValue("Testing", UtilMisc.toMap("testingId", "timeout-test"));
489             boolean transBegin = TransactionUtil.begin(10); // timeout set to 10 seconds
490
delegator.create(testValue);
491             Thread.sleep(20*1000);
492             TransactionUtil.commit(transBegin);
493             assertTrue(false);
494         } catch (GenericTransactionException e) {
495             assertTrue(true);
496         } catch (GenericEntityException e) {
497             assertTrue("Other GenericEntityException encountered:" + e.toString(), false);
498             return;
499         } finally {
500             delegator.removeByAnd("Testing", UtilMisc.toMap("testingId", "timeout-test"));
501         }
502     }
503     
504     /*
505      * This test will verify that the same transaction transaction which takes less time than timeout will be committed.
506      */

507     public void testTransactionUtilLessThanTimeout() throws Exception JavaDoc {
508         try {
509             GenericValue testValue = delegator.makeValue("Testing", UtilMisc.toMap("testingId", "timeout-test"));
510             boolean transBegin = TransactionUtil.begin();
511             TransactionUtil.setTransactionTimeout(20); // now set timeout to 20 seconds
512
delegator.create(testValue);
513             Thread.sleep(10*1000);
514             TransactionUtil.commit(transBegin);
515             assertTrue(true);
516         } catch (GenericTransactionException e) {
517             assertTrue("Transaction error when testing transaction less than timeout " + e.toString(), false);
518         } catch (GenericEntityException e) {
519             assertTrue("Other GenericEntityException encountered:" + e.toString(), false);
520             return;
521         } finally {
522             delegator.removeByAnd("Testing", UtilMisc.toMap("testingId", "timeout-test"));
523         }
524     }
525
526   /*
527    * This will test setting a blob field to null by creating a TestBlob entity whose blob field is not set
528    */

529   public void testSetNullBlob() throws Exception JavaDoc {
530       try {
531           delegator.create("TestBlob", UtilMisc.toMap("testBlobId", "null-blob"));
532       } catch (GenericEntityException ex) {
533           assertTrue("GenericEntityException:" + ex.toString(), false);
534           return;
535       } finally {
536           List JavaDoc allTestBlobs = delegator.findAll("TestBlob");
537           delegator.removeAll(allTestBlobs);
538       }
539   }
540
541   /*
542    * Tests setting a byte value into a blob data type using the GenericValue .setBytes method
543    */

544   public void testBlobCreate() throws Exception JavaDoc {
545       try {
546           byte[] b = new byte[1];
547           b[0] = (byte)0x01;
548           GenericValue testingBlob = delegator.makeValue("TestBlob", UtilMisc.toMap("testBlobId", "byte-blob"));
549           testingBlob.setBytes("testBlobField", b);
550           testingBlob.create();
551           
552           TestCase.assertTrue("Blob with byte value successfully created...", true);
553       } catch(Exception JavaDoc ex) {
554         TestCase.fail(ex.getMessage());
555       } finally {
556           // Remove all our newly inserted values.
557
List JavaDoc values = delegator.findAll("TestBlob");
558         delegator.removeAll(values);
559       }
560   }
561
562   /*
563    * This creates an string id from a number
564    */

565   private String JavaDoc getTestId(String JavaDoc strTestBase, int iNum) {
566       StringBuffer JavaDoc strBufTemp = new StringBuffer JavaDoc(strTestBase);
567       if (iNum < 10000) {
568          strBufTemp.append("0");
569       }
570       if (iNum < 1000) {
571          strBufTemp.append("0");
572       }
573       if (iNum < 100) {
574          strBufTemp.append("0");
575       }
576       if (iNum < 10) {
577          strBufTemp.append("0");
578       }
579       strBufTemp.append(iNum);
580       return strBufTemp.toString();
581   }
582
583 }
584
Popular Tags