Quantcast

Is it possible to unit test a sequence in a domain object?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Is it possible to unit test a sequence in a domain object?

marcopas
Hi there,

i was wondering if it possible to unit test a sequence that is
configured in my domain object like this:

    static mapping = {
        // sequence generator for handing out unique transaction id's
        transactionId generator:'sequence',
params:[sequence:'seq_transaction_id']
    }

Whatever i do the sequence stays 'null'

I am using Grails 2.0.4 + spock + build-test-data plugin.

/Marco

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Is it possible to unit test a sequence in a domain object?

Jeff Brown-3
Marco Pas wrote:

> Hi there,
>
> i was wondering if it possible to unit test a sequence that is
> configured in my domain object like this:
>
>      static mapping = {
>          // sequence generator for handing out unique transaction id's
>          transactionId generator:'sequence',
> params:[sequence:'seq_transaction_id']
>      }
>
> Whatever i do the sequence stays 'null'
>
> I am using Grails 2.0.4 + spock + build-test-data plugin.
>

What is it that you want to unit test?  Do you want to test that the
sequence generator is generating what you expect?



jb


--
Jeff Brown
SpringSource
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Is it possible to unit test a sequence in a domain object?

marcopas
Hi Jeff,

I am using the domain object inside a service. So when a new object is
persisted inside the service i expect the sequence to give my object a
unique value in the mentioned property.
I placed a unique constaint on the property but this is offcourse a
stupid one :) But anyway.. I am testing a service that persists an
object but uses the returned generated id in the further processing.
Guess that i have to split up things and make things more modular so i
can test it correctly without the dependency on the sequence
generation.


2012/5/31 Jeff Brown <[hidden email]>:

> Marco Pas wrote:
>>
>> Hi there,
>>
>> i was wondering if it possible to unit test a sequence that is
>> configured in my domain object like this:
>>
>>     static mapping = {
>>         // sequence generator for handing out unique transaction id's
>>         transactionId generator:'sequence',
>> params:[sequence:'seq_transaction_id']
>>     }
>>
>> Whatever i do the sequence stays 'null'
>>
>> I am using Grails 2.0.4 + spock + build-test-data plugin.
>>
>
> What is it that you want to unit test?  Do you want to test that the
> sequence generator is generating what you expect?
>
>
>
> jb
>
>
> --
> Jeff Brown
> SpringSource
> http://www.springsource.com/
>
> Autism Strikes 1 in 166
> Find The Cause ~ Find The Cure
> http://www.autismspeaks.org/
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>   http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Is it possible to unit test a sequence in a domain object?

marcopas
In reply to this post by Jeff Brown-3
Any suggestion on how i could unit test services etc that use the
domain object with a sequence in it? Or do i have make an integration
test for this?

class Transaction {
    Long transactionId          // unique auto generated transaction id
    // .. code omitted
    static mapping = {
        // sequence generator for handing out unique transaction id's
        transactionId generator:'sequence',
params:[sequence:'seq_transaction_id']
    }
}

The following test will throw an error on the domain object for the
fact that transactionId may not be nullable.

@Build(Transaction)
@TestFor(Transaction)
class TransactionSpec extends Specification {
    def "simple test"() {
        when:
        Transaction transaction = Transaction.build()
        transaction.save()

        then:
        true
    }
}





2012/5/31 Jeff Brown <[hidden email]>:

> Marco Pas wrote:
>>
>> Hi there,
>>
>> i was wondering if it possible to unit test a sequence that is
>> configured in my domain object like this:
>>
>>     static mapping = {
>>         // sequence generator for handing out unique transaction id's
>>         transactionId generator:'sequence',
>> params:[sequence:'seq_transaction_id']
>>     }
>>
>> Whatever i do the sequence stays 'null'
>>
>> I am using Grails 2.0.4 + spock + build-test-data plugin.
>>
>
> What is it that you want to unit test?  Do you want to test that the
> sequence generator is generating what you expect?
>
>
>
> jb
>
>
> --
> Jeff Brown
> SpringSource
> http://www.springsource.com/
>
> Autism Strikes 1 in 166
> Find The Cause ~ Find The Cure
> http://www.autismspeaks.org/
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>   http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Is it possible to unit test a sequence in a domain object?

marcopas
In reply to this post by Jeff Brown-3
I forgot to mention that every test that uses the Transaction domain
object which has a sequence it will fail, this for the simple fact
that storing a transaction will give a validation error that the
sequence property may not be null..
I see no way on how to bypass this..

2012/5/31 Jeff Brown <[hidden email]>:

> Marco Pas wrote:
>>
>> Hi there,
>>
>> i was wondering if it possible to unit test a sequence that is
>> configured in my domain object like this:
>>
>>     static mapping = {
>>         // sequence generator for handing out unique transaction id's
>>         transactionId generator:'sequence',
>> params:[sequence:'seq_transaction_id']
>>     }
>>
>> Whatever i do the sequence stays 'null'
>>
>> I am using Grails 2.0.4 + spock + build-test-data plugin.
>>
>
> What is it that you want to unit test?  Do you want to test that the
> sequence generator is generating what you expect?
>
>
>
> jb
>
>
> --
> Jeff Brown
> SpringSource
> http://www.springsource.com/
>
> Autism Strikes 1 in 166
> Find The Cause ~ Find The Cure
> http://www.autismspeaks.org/
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>   http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...