- Timestamp:
- Apr 22, 2011, 5:18:04 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/features/purchaseOrders/test/unit/PurchaseOrderServiceTests.groovy
r896 r898 1 1 import grails.test.* 2 import com.henyo.BaseUnitTestCase 2 3 import static org.junit.Assert.assertThat 3 4 import static org.hamcrest.CoreMatchers.equalTo … … 6 7 * Unit tests for PurchaseOrderService class. 7 8 */ 8 class PurchaseOrderServiceTests extends GrailsUnitTestCase {9 class PurchaseOrderServiceTests extends BaseUnitTestCase { 9 10 def pos = new PurchaseOrderService() 10 11 … … 21 22 } 22 23 24 void testSavePurchaseOrderNumberExpectCommit() { 25 mockForTransaction(PurchaseOrderNumber) 26 27 def p = [value: "P100"] 28 def r = pos.savePurchaseOrderNumber(p) 29 30 assert ! r.error 31 assert PurchaseOrderNumber.count() == 1 32 } 33 34 void testSavePurchaseOrderNumberExpectRollback() { 35 mockForTransaction(PurchaseOrderNumber, true) 36 37 def p = [value: ""] 38 def r = pos.savePurchaseOrderNumber(p) 39 40 assert r.error 41 assert PurchaseOrderNumber.count() == 0 42 } 43 44 void testSavePurchaseOrderNumberRangeExpectCommit() { 45 mockForTransaction(PurchaseOrderNumber) 46 47 def r = pos.savePurchaseOrderNumberRange("P", 1000, 1009) 48 49 assert ! r.error 50 assert PurchaseOrderNumber.count() == 10 51 } 52 53 void testSavePurchaseOrderNumberRangeExpectRollback() { 54 mockForTransaction(PurchaseOrderNumber, true) 55 56 def r = pos.savePurchaseOrderNumberRange("P", -1000, 1009) 57 58 assert r.error 59 assert PurchaseOrderNumber.count() == 0 60 } 61 23 62 void testFindsFirstUnusedPurchaseOrderWhenAllUnused() { 24 createTenPurchaseOrderNumbers()25 assertThat PurchaseOrderNumber.list().size(), equalTo(10)63 mockForTransaction(PurchaseOrderNumber) 64 pos.savePurchaseOrderNumberRange("P", 1000, 1009) 26 65 27 66 def next = pos.findNextUnusedPurchaseOrderNumber() … … 31 70 32 71 void testFindsFirstUnusuedPurchaseOrderWhenSomeUsed() { 33 createTenPurchaseOrderNumbers() 72 mockForTransaction(PurchaseOrderNumber) 73 pos.savePurchaseOrderNumberRange("P", 1000, 1009) 34 74 createPurchaseOrders(4) 35 75 … … 40 80 41 81 void testFindsNullIfNoUnusedPurchaseOrderNumbers() { 42 createTenPurchaseOrderNumbers() 82 mockForTransaction(PurchaseOrderNumber) 83 pos.savePurchaseOrderNumberRange("P", 1000, 1009) 43 84 createPurchaseOrders(10) 44 85 … … 49 90 50 91 void testGetOrCreatePurchaseOrderWithExistingOrder() { 51 createTenPurchaseOrderNumbers() 92 mockForTransaction(PurchaseOrderNumber) 93 pos.savePurchaseOrderNumberRange("P", 1000, 1009) 52 94 createPurchaseOrders(3) 53 95 def params=[purchaseOrderNumber:[id:2]] … … 60 102 61 103 void testGetOrCreatePurchaseOrderWithNoExistingOrder() { 62 createTenPurchaseOrderNumbers() 104 mockForTransaction(PurchaseOrderNumber) 105 pos.savePurchaseOrderNumberRange("P", 1000, 1009) 63 106 createPurchaseOrders(3) 64 107 createSuppliers(1) … … 72 115 73 116 void testFindsDraftPurchaseOrderNumbers() { 74 createTenPurchaseOrderNumbers() 117 mockForTransaction(PurchaseOrderNumber) 118 pos.savePurchaseOrderNumberRange("P", 1000, 1009) 75 119 createPurchaseOrders(3) 76 120 releaseOrder(PurchaseOrder.get(2)) … … 103 147 } 104 148 105 private createTenPurchaseOrderNumbers() {106 for (int i = 1000; i < 1010; i++) {107 new PurchaseOrderNumber(value: "P${i}").save(failOnError: true)108 }109 }110 111 149 def releaseOrder(PurchaseOrder po) { 112 150 po.ordered = new Date()
Note: See TracChangeset
for help on using the changeset viewer.