Ignore:
Timestamp:
Apr 22, 2011, 5:18:04 PM (14 years ago)
Author:
gav
Message:

Add savePurchaseOrderNumber() and savePurchaseOrderNumberRange() to PurchaseOrderService.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/features/purchaseOrders/test/unit/PurchaseOrderServiceTests.groovy

    r896 r898  
    11import grails.test.*
     2import com.henyo.BaseUnitTestCase
    23import static org.junit.Assert.assertThat
    34import static org.hamcrest.CoreMatchers.equalTo
     
    67 * Unit tests for PurchaseOrderService class.
    78 */
    8 class PurchaseOrderServiceTests extends GrailsUnitTestCase {
     9class PurchaseOrderServiceTests extends BaseUnitTestCase {
    910    def pos = new PurchaseOrderService()
    1011
     
    2122    }
    2223
     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
    2362    void testFindsFirstUnusedPurchaseOrderWhenAllUnused() {
    24         createTenPurchaseOrderNumbers()
    25         assertThat PurchaseOrderNumber.list().size(), equalTo(10)
     63        mockForTransaction(PurchaseOrderNumber)
     64        pos.savePurchaseOrderNumberRange("P", 1000, 1009)
    2665
    2766        def next = pos.findNextUnusedPurchaseOrderNumber()
     
    3170
    3271    void testFindsFirstUnusuedPurchaseOrderWhenSomeUsed() {
    33         createTenPurchaseOrderNumbers()
     72        mockForTransaction(PurchaseOrderNumber)
     73        pos.savePurchaseOrderNumberRange("P", 1000, 1009)
    3474        createPurchaseOrders(4)
    3575
     
    4080
    4181    void testFindsNullIfNoUnusedPurchaseOrderNumbers() {
    42         createTenPurchaseOrderNumbers()
     82        mockForTransaction(PurchaseOrderNumber)
     83        pos.savePurchaseOrderNumberRange("P", 1000, 1009)
    4384        createPurchaseOrders(10)
    4485
     
    4990
    5091    void testGetOrCreatePurchaseOrderWithExistingOrder() {
    51         createTenPurchaseOrderNumbers()
     92        mockForTransaction(PurchaseOrderNumber)
     93        pos.savePurchaseOrderNumberRange("P", 1000, 1009)
    5294        createPurchaseOrders(3)
    5395        def params=[purchaseOrderNumber:[id:2]]
     
    60102
    61103    void testGetOrCreatePurchaseOrderWithNoExistingOrder() {
    62         createTenPurchaseOrderNumbers()
     104        mockForTransaction(PurchaseOrderNumber)
     105        pos.savePurchaseOrderNumberRange("P", 1000, 1009)
    63106        createPurchaseOrders(3)
    64107        createSuppliers(1)
     
    72115
    73116    void testFindsDraftPurchaseOrderNumbers() {
    74         createTenPurchaseOrderNumbers()
     117        mockForTransaction(PurchaseOrderNumber)
     118        pos.savePurchaseOrderNumberRange("P", 1000, 1009)
    75119        createPurchaseOrders(3)
    76120        releaseOrder(PurchaseOrder.get(2))
     
    103147    }
    104148
    105     private createTenPurchaseOrderNumbers() {
    106         for (int i = 1000; i < 1010; i++) {
    107             new PurchaseOrderNumber(value: "P${i}").save(failOnError: true)
    108         }
    109     }
    110 
    111149    def releaseOrder(PurchaseOrder po) {
    112150        po.ordered = new Date()
Note: See TracChangeset for help on using the changeset viewer.