Please, note that the following two unit tests fail in release 12.04.04 when java 7 is used:
- testWithdraw - testDeposit Thanks Anahita 2014-07-16 15:45 GMT+02:00 <jaco...@apache.org>: > Author: jacopoc > Date: Wed Jul 16 13:45:49 2014 > New Revision: 1611010 > > URL: http://svn.apache.org/r1611010 > Log: > Backported and modified a series of unit tests to make them more reliable > with recent versions of Java. > > Modified: > > ofbiz/branches/release12.04/applications/content/src/org/ofbiz/content/test/LuceneTests.java > > ofbiz/branches/release12.04/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java > > ofbiz/branches/release12.04/framework/entity/entitydef/entitymodel_test.xml > > ofbiz/branches/release12.04/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java > > Modified: > ofbiz/branches/release12.04/applications/content/src/org/ofbiz/content/test/LuceneTests.java > URL: > http://svn.apache.org/viewvc/ofbiz/branches/release12.04/applications/content/src/org/ofbiz/content/test/LuceneTests.java?rev=1611010&r1=1611009&r2=1611010&view=diff > > ============================================================================== > --- > ofbiz/branches/release12.04/applications/content/src/org/ofbiz/content/test/LuceneTests.java > (original) > +++ > ofbiz/branches/release12.04/applications/content/src/org/ofbiz/content/test/LuceneTests.java > Wed Jul 16 13:45:49 2014 > @@ -60,7 +60,7 @@ public class LuceneTests extends OFBizTe > protected void tearDown() throws Exception { > } > > - public void testCreateIndex() throws Exception { > + public void testSearchTermHand() throws Exception { > Map<String, Object> ctx = FastMap.newInstance(); > ctx.put("contentId", "WebStoreCONTENT"); > ctx.put("userLogin", userLogin); > @@ -70,9 +70,7 @@ public class LuceneTests extends OFBizTe > > List<String> badIndexList = > UtilGenerics.checkList(resp.get("badIndexList")); > assertEquals(8, badIndexList.size()); > - } > > - public void testSearchTermHand() throws Exception { > Directory directory = FSDirectory.open(new > File(SearchWorker.getIndexPath(null))); > IndexReader r = null; > try { > > Modified: > ofbiz/branches/release12.04/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java > URL: > http://svn.apache.org/viewvc/ofbiz/branches/release12.04/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java?rev=1611010&r1=1611009&r2=1611010&view=diff > > ============================================================================== > --- > ofbiz/branches/release12.04/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java > (original) > +++ > ofbiz/branches/release12.04/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java > Wed Jul 16 13:45:49 2014 > @@ -41,7 +41,7 @@ public class InventoryItemTransferTest e > > @Override > protected void setUp() throws Exception { > - userLogin = delegator.findByPrimaryKey("UserLogin", > UtilMisc.toMap("userLoginId", "system")); > + userLogin = delegator.findOne("UserLogin", > UtilMisc.toMap("userLoginId", "system"), false); > } > > @Override > @@ -49,11 +49,11 @@ public class InventoryItemTransferTest e > } > > public void testCreateInventoryItemsTransfer() throws Exception { > + // create > Map<String, Object> ctx = FastMap.newInstance(); > - String statusId = "IXF_REQUESTED"; > String inventoryItemId = "9005"; > ctx.put("inventoryItemId", inventoryItemId); > - ctx.put("statusId", statusId); > + ctx.put("statusId", "IXF_REQUESTED"); > ctx.put("facilityId", "WebStoreWarehouse"); > ctx.put("facilityIdTo", "WebStoreWarehouse"); > ctx.put("receiveDate", UtilDateTime.nowTimestamp()); > @@ -62,17 +62,14 @@ public class InventoryItemTransferTest e > Map<String, Object> resp = > dispatcher.runSync("createInventoryTransfer", ctx); > inventoryTransferId = (String) resp.get("inventoryTransferId"); > assertNotNull(inventoryTransferId); > - } > > - public void testUpdateInventoryItemTransfer() throws Exception { > - Map<String, Object> ctx = FastMap.newInstance(); > - String statusId = "IXF_COMPLETE"; > + // transfer > + ctx = FastMap.newInstance(); > ctx.put("inventoryTransferId", inventoryTransferId); > - String inventoryItemId = > delegator.findByPrimaryKey("InventoryTransfer", > UtilMisc.toMap("inventoryTransferId", > inventoryTransferId)).getString("inventoryItemId"); > ctx.put("inventoryItemId", inventoryItemId); > - ctx.put("statusId", statusId); > + ctx.put("statusId", "IXF_COMPLETE"); > ctx.put("userLogin", userLogin); > - Map<String, Object> resp = > dispatcher.runSync("updateInventoryTransfer", ctx); > + resp = dispatcher.runSync("updateInventoryTransfer", ctx); > String respMsg = (String) resp.get("responseMessage"); > assertNotSame("error", respMsg); > } > > Modified: > ofbiz/branches/release12.04/framework/entity/entitydef/entitymodel_test.xml > URL: > http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/entity/entitydef/entitymodel_test.xml?rev=1611010&r1=1611009&r2=1611010&view=diff > > ============================================================================== > --- > ofbiz/branches/release12.04/framework/entity/entitydef/entitymodel_test.xml > (original) > +++ > ofbiz/branches/release12.04/framework/entity/entitydef/entitymodel_test.xml > Wed Jul 16 13:45:49 2014 > @@ -186,4 +186,12 @@ under the License. > <key-map field-name="testingId"/> > </relation> > </view-entity> > + <entity entity-name="TestingRemoveAll" > + package-name="org.ofbiz.entity.test" > + title="Testing Entity"> > + <field name="testingRemoveAllId" type="id-ne"/> > + <field name="description" type="description"/> > + <prim-key field="testingRemoveAllId"/> > + </entity> > </entitymodel> > + > > Modified: > ofbiz/branches/release12.04/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java > URL: > http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java?rev=1611010&r1=1611009&r2=1611010&view=diff > > ============================================================================== > --- > ofbiz/branches/release12.04/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java > (original) > +++ > ofbiz/branches/release12.04/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java > Wed Jul 16 13:45:49 2014 > @@ -224,6 +224,27 @@ public class EntityTestSuite extends Ent > TransactionUtil.rollback(transBegin, null, null); > } > > + protected long flushAndRecreateTree(String descriptionPrefix) throws > Exception { > + // > + // The tree has a root, the root has level1max children. > + // > + > + // create the root > + GenericValue root = delegator.create("TestingNode", > + "testingNodeId", > delegator.getNextSeqId("TestingNode"), > + "primaryParentNodeId", GenericEntity.NULL_FIELD, > + "description", descriptionPrefix + ":0:root"); > + int level1; > + for (level1 = 0; level1 < _level1max; level1++) { > + String nextSeqId = delegator.getNextSeqId("TestingNode"); > + GenericValue v = delegator.create("TestingNode", > "testingNodeId", nextSeqId, > + "primaryParentNodeId", > root.get("testingNodeId"), > + "description", descriptionPrefix + > ":1:node-level #1"); > + assertNotNull(v); > + } > + return level1 + 1; > + } > + > /* > * Tests storing data with the delegator's .create method. Also > tests .findCountByCondition and .getNextSeqId > */ > @@ -238,9 +259,9 @@ public class EntityTestSuite extends Ent > > // create the root > GenericValue root = delegator.create("TestingNode", > - "testingNodeId", > delegator.getNextSeqId("TestingNode"), > - "primaryParentNodeId", GenericEntity.NULL_FIELD, > - "description", "root"); > + "testingNodeId", delegator.getNextSeqId("TestingNode"), > + "primaryParentNodeId", GenericEntity.NULL_FIELD, > + "description", "root"); > int level1; > for(level1 = 0; level1 < _level1max; level1++) { > String nextSeqId = delegator.getNextSeqId("TestingNode"); > @@ -294,6 +315,27 @@ public class EntityTestSuite extends Ent > assertEquals("Created/Stored Nodes", newValues.size(), n); > } > > + protected void createNodeMembers(String typeId, String > typeDescription, String descriptionPrefix) throws GenericEntityException { > + delegator.removeByCondition("TestingType", > EntityCondition.makeCondition("testingTypeId", EntityOperator.EQUALS, > typeId)); > + delegator.create("TestingType", "testingTypeId", typeId, > "description", typeDescription); > + int i = 0; > + Timestamp now = UtilDateTime.nowTimestamp(); > + for (GenericValue node: delegator.findList("TestingNode", > EntityCondition.makeCondition("description", EntityOperator.LIKE, > descriptionPrefix + "%"), null, null, null, false)) { > + if (i % 2 == 0) { > + GenericValue testing = delegator.create("Testing", > "testingId", descriptionPrefix + ":" + node.get("testingNodeId"), > "testingTypeId", typeId, "description", node.get("description")); > + GenericValue member = > delegator.makeValue("TestingNodeMember", > + "testingNodeId", node.get("testingNodeId"), > + "testingId", testing.get("testingId") > + ); > + > + member.put("fromDate", now); > + member.put("thruDate", UtilDateTime.getNextDayStart(now)); > + member.create(); > + } > + i++; > + } > + } > + > /* > * Tests findByCondition and tests searching on a view-entity > */ > @@ -319,6 +361,20 @@ public class EntityTestSuite extends Ent > * Tests findByCondition and a find by distinct > */ > public void testFindDistinct() throws Exception { > + delegator.removeByCondition("Testing", > EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, > "TEST-DISTINCT-%")); > + List<GenericValue> testingDistinctList = > delegator.findList("Testing", > EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, > "TEST-DISTINCT-%"), null, null, null, false); > + assertEquals("No existing Testing entities for distinct", 0, > testingDistinctList.size()); > + delegator.removeByCondition("TestingType", > EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, > "TEST-DISTINCT-%")); > + GenericValue testValue = delegator.findOne("TestingType", true, > "testingTypeId", "TEST-DISTINCT-1"); > + assertNull("No pre-existing type value", testValue); > + delegator.create("TestingType", "testingTypeId", > "TEST-DISTINCT-1", "description", "Testing Type #Distinct-1"); > + testValue = delegator.findOne("TestingType", true, > "testingTypeId", "TEST-DISTINCT-1"); > + assertNotNull("Found newly created type value", testValue); > + > + delegator.create("Testing", "testingId", "TEST-DISTINCT-1", > "testingTypeId", "TEST-DISTINCT-1", "testingSize", Long.valueOf(10), > "comments", "No-comments"); > + delegator.create("Testing", "testingId", "TEST-DISTINCT-2", > "testingTypeId", "TEST-DISTINCT-1", "testingSize", Long.valueOf(10), > "comments", "Some-comments"); > + delegator.create("Testing", "testingId", "TEST-DISTINCT-3", > "testingTypeId", "TEST-DISTINCT-1", "testingSize", Long.valueOf(9), > "comments", "No-comments"); > + delegator.create("Testing", "testingId", "TEST-DISTINCT-4", > "testingTypeId", "TEST-DISTINCT-1", "testingSize", Long.valueOf(11), > "comments", "Some-comments"); > List<EntityExpr> exprList = UtilMisc.toList( > EntityCondition.makeCondition("testingSize", > EntityOperator.EQUALS, Long.valueOf(10)), > EntityCondition.makeCondition("comments", > EntityOperator.EQUALS, "No-comments")); > @@ -401,10 +457,13 @@ public class EntityTestSuite extends Ent > * Tests the .getRelatedOne method and removeAll for removing entities > */ > public void testRemoveNodeMemberAndTesting() throws Exception { > + flushAndRecreateTree("rnmat"); > + createNodeMembers("TEST-RNMAT", "remove-node-member-and-testing", > "rnmat"); > // > // Find the testing entities tru the node member and build a list > of them > // > - List<GenericValue> values = > delegator.findList("TestingNodeMember", null, null, null, null, false); > + EntityCondition isNodeWithMember = > EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "rnmat:%"); > + List<GenericValue> values = > delegator.findList("TestingNodeMember", isNodeWithMember, null, null, null, > false); > > ArrayList<GenericValue> testings = new ArrayList<GenericValue>(); > > @@ -413,11 +472,11 @@ public class EntityTestSuite extends Ent > } > // and remove the nodeMember afterwards > delegator.removeAll(values); > - values = delegator.findList("TestingNodeMember", null, null, > null, null, false); > + values = delegator.findList("TestingNodeMember", > isNodeWithMember, null, null, null, false); > assertEquals("No more Node Member entities", 0, values.size()); > > delegator.removeAll(testings); > - values = delegator.findList("Testing", null, null, null, null, > false); > + values = delegator.findList("Testing", > EntityCondition.makeCondition("description", EntityOperator.LIKE, > "rnmat:%"), null, null, null, false); > assertEquals("No more Testing entities", 0, values.size()); > } > > @@ -438,10 +497,11 @@ public class EntityTestSuite extends Ent > * Tests the .removeByCondition method for removing entities directly > */ > public void testRemoveByCondition() throws Exception { > + flushAndRecreateTree("remove-by-condition-a"); > // > // remove all the level1 nodes by using a condition on the > description field > // > - EntityCondition isLevel1 = > EntityCondition.makeCondition("description", EntityOperator.EQUALS, > "node-level #1 (updated)"); > + EntityCondition isLevel1 = > EntityCondition.makeCondition("description", EntityOperator.LIKE, > "remove-by-condition-a:1:%"); > int n = delegator.removeByCondition("TestingNode", isLevel1); > assertTrue("testRemoveByCondition nodes > 0", n > 0); > } > @@ -450,11 +510,16 @@ public class EntityTestSuite extends Ent > * Test the .removeByPrimaryKey by using findByCondition and then > retrieving the GenericPk from a GenericValue > */ > public void testRemoveByPK() throws Exception { > + flushAndRecreateTree("remove-by-pk"); > // > // Find all the root nodes, > // delete them their primary key > // > - EntityCondition isRoot = > EntityCondition.makeCondition("primaryParentNodeId", EntityOperator.EQUALS, > GenericEntity.NULL_FIELD); > + EntityCondition isRoot = EntityCondition.makeCondition( > + EntityCondition.makeCondition("description", > EntityOperator.LIKE, "remove-by-pk:%"), > + EntityOperator.AND, > + EntityCondition.makeCondition("primaryParentNodeId", > EntityOperator.NOT_EQUAL, GenericEntity.NULL_FIELD) > + ); > List<GenericValue> rootValues = delegator.findList("TestingNode", > isRoot, UtilMisc.toSet("testingNodeId"), null, null, false); > > for (GenericValue value: rootValues) { > @@ -465,7 +530,7 @@ public class EntityTestSuite extends Ent > > // no more TestingNode should be in the data base anymore. > > - List<GenericValue> testingNodes = > delegator.findList("TestingNode", null, null, null, null, false); > + List<GenericValue> testingNodes = > delegator.findList("TestingNode", isRoot, null, null, null, false); > assertEquals("No more TestingNode after removing the roots", 0, > testingNodes.size()); > } > > @@ -473,28 +538,38 @@ public class EntityTestSuite extends Ent > * Tests the .removeAll method only. > */ > public void testRemoveType() throws Exception { > - List<GenericValue> values = delegator.findList("TestingType", > null, null, null, null, false); > + List<GenericValue> values = > delegator.findList("TestingRemoveAll", null, null, null, null, false); > + delegator.removeAll(values); > + values = delegator.findList("TestingRemoveAll", null, null, null, > null, false); > + assertEquals("No more TestingRemoveAll: setup", 0, values.size()); > + for (int i = 0; i < 10; i++) { > + delegator.create("TestingRemoveAll", "testingRemoveAllId", > "prefix:" + i); > + } > + values = delegator.findList("TestingRemoveAll", null, null, null, > null, false); > + assertEquals("No more TestingRemoveAll: create", 10, > values.size()); > + > delegator.removeAll(values); > > // now make sure there are no more of these > - values = delegator.findList("TestingType", null, null, null, > null, false); > - assertEquals("No more TestingTypes after remove all", 0, > values.size()); > + values = delegator.findList("TestingRemoveAll", null, null, null, > null, false); > + assertEquals("No more TestingRemoveAll: finish", 0, > values.size()); > } > > /* > * This test will create a large number of unique items and add them > to the delegator at once > */ > public void testCreateManyAndStoreAtOnce() throws Exception { > + EntityCondition condition = > EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T1-%"); > try { > List<GenericValue> newValues = new LinkedList<GenericValue>(); > for (int i = 0; i < TEST_COUNT; i++) { > newValues.add(delegator.makeValue("Testing", "testingId", > getTestId("T1-", i))); > } > delegator.storeAll(newValues); > - List<GenericValue> newlyCreatedValues = > delegator.findList("Testing", null, null, UtilMisc.toList("testingId"), > null, false); > + List<GenericValue> newlyCreatedValues = > delegator.findList("Testing", condition, null, > UtilMisc.toList("testingId"), null, false); > assertEquals("Test to create " + TEST_COUNT + " and store all > at once", TEST_COUNT, newlyCreatedValues.size()); > } finally { > - List<GenericValue> newlyCreatedValues = > delegator.findList("Testing", null, null, UtilMisc.toList("testingId"), > null, false); > + List<GenericValue> newlyCreatedValues = > delegator.findList("Testing", condition, null, > UtilMisc.toList("testingId"), null, false); > delegator.removeAll(newlyCreatedValues); > } > } > @@ -503,39 +578,56 @@ public class EntityTestSuite extends Ent > * This test will create a large number of unique items and add them > to the delegator at once > */ > public void testCreateManyAndStoreOneAtATime() throws Exception { > - for (int i = 0; i < TEST_COUNT; i++) { > - delegator.create(delegator.makeValue("Testing", "testingId", > getTestId("T2-", i))); > + EntityCondition condition = > EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T2-%"); > + try { > + for (int i = 0; i < TEST_COUNT; i++) { > + delegator.create(delegator.makeValue("Testing", > "testingId", getTestId("T2-", i))); > + } > + List<GenericValue> newlyCreatedValues = > delegator.findList("Testing", condition, null, > UtilMisc.toList("testingId"), null, false); > + assertEquals("Test to create " + TEST_COUNT + " and store one > at a time: ", TEST_COUNT, newlyCreatedValues.size()); > + } finally { > + List<GenericValue> newlyCreatedValues = > delegator.findList("Testing", condition, null, > UtilMisc.toList("testingId"), null, false); > + delegator.removeAll(newlyCreatedValues); > } > - List<GenericValue> newlyCreatedValues = > delegator.findList("Testing", null, null, UtilMisc.toList("testingId"), > null, false); > - assertEquals("Test to create " + TEST_COUNT + " and store one at > a time: ", TEST_COUNT, newlyCreatedValues.size()); > } > > /* > * This test will use the large number of unique items from above and > test the EntityListIterator looping through the list > */ > public void testEntityListIterator() throws Exception { > - boolean beganTransaction = false; > + EntityCondition condition = > EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T3-%"); > try { > - beganTransaction = TransactionUtil.begin(); > - EntityListIterator iterator = delegator.find("Testing", > EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T2-%"), > null, null, UtilMisc.toList("testingId"), null); > - assertNotNull("Test if EntityListIterator was created: ", > iterator); > - > - int i = 0; > - GenericValue item = iterator.next(); > - while (item != null) { > - assertEquals("Testing if iterated data matches test data > (row " + i + "): ", getTestId("T2-", i), item.getString("testingId")); > - item = iterator.next(); > - i++; > + List<GenericValue> newValues = new LinkedList<GenericValue>(); > + for (int i = 0; i < TEST_COUNT; i++) { > + newValues.add(delegator.makeValue("Testing", "testingId", > getTestId("T3-", i))); > + } > + delegator.storeAll(newValues); > + List<GenericValue> newlyCreatedValues = > delegator.findList("Testing", condition, null, > UtilMisc.toList("testingId"), null, false); > + assertEquals("Test to create " + TEST_COUNT + " and store all > at once", TEST_COUNT, newlyCreatedValues.size()); > + boolean beganTransaction = false; > + try { > + beganTransaction = TransactionUtil.begin(); > + EntityListIterator iterator = delegator.find("Testing", > condition, null, null, UtilMisc.toList("testingId"), null); > + assertNotNull("Test if EntityListIterator was created: ", > iterator); > + > + int i = 0; > + GenericValue item = iterator.next(); > + while (item != null) { > + assertEquals("Testing if iterated data matches test > data (row " + i + "): ", getTestId("T3-", i), item.getString("testingId")); > + item = iterator.next(); > + i++; > + } > + assertEquals("Test if EntitlyListIterator iterates > exactly " + TEST_COUNT + " times: " , TEST_COUNT, i); > + iterator.close(); > + } catch (GenericEntityException e) { > + TransactionUtil.rollback(beganTransaction, > "GenericEntityException occurred while iterating with EntityListIterator", > e); > + assertTrue("GenericEntityException:" + e.toString(), > false); > + return; > + } finally { > + TransactionUtil.commit(beganTransaction); > } > - assertEquals("Test if EntitlyListIterator iterates exactly " > + TEST_COUNT + " times: " , TEST_COUNT, i); > - iterator.close(); > - } catch (GenericEntityException e) { > - TransactionUtil.rollback(beganTransaction, > "GenericEntityException occurred while iterating with EntityListIterator", > e); > - assertTrue("GenericEntityException:" + e.toString(), false); > - return; > } finally { > - TransactionUtil.commit(beganTransaction); > - List<GenericValue> entitiesToRemove = > delegator.findList("Testing", EntityCondition.makeCondition("testingId", > EntityOperator.LIKE, "T2-%"), null, null, null, false); > + List<GenericValue> entitiesToRemove = > delegator.findList("Testing", condition, null, null, null, false); > delegator.removeAll(entitiesToRemove); > } > } > > >