You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@deltaspike.apache.org by Paul Wills <pa...@engsol.com.au> on 2015/12/10 05:56:36 UTC
CdiTestRunner fails to create proxy for the test class so
@Transactional annotation is ignored
I don't know if this is viewed as a problem or not, but when I wrote a test
class and annotated it with
@RunWith(CdiTestRunner.*class*)
the following test method is called as a non proxied method call from
reflection, indicating to me that the @Transactional annotation cannot be
having any effect.
@Test
@Transactional
*public* *void testSaveAndFetchUser() {*
// Given - a new user
*final* User randomUser = createRandomUser(*false*);
// When - saved
*final* User savedUser = userService.saveUser(randomUser);
// Then - user is saved as well as history and can be retrieved by id
and username
*assertThat*(savedUser.getRoles(), *hasSize*(*greaterThan*(0)));
...
}
Regards,
Paul Wills
Re: CdiTestRunner fails to create proxy for the test class so
@Transactional annotation is ignored
Posted by Gerhard Petracek <ge...@gmail.com>.
hi paul,
you are welcome - great that it works for you!
regards,
gerhard
http://www.irian.at
Your JavaEE powerhouse -
JavaEE Consulting, Development and
Courses in English and German
Professional Support for Apache
MyFaces, DeltaSpike and OpenWebBeans
2015-12-14 4:15 GMT+01:00 Paul Wills <pa...@engsol.com.au>:
> Hi Gerhard,
>
> adding
>
> deltaspike.testcontrol.use_test_class_as_cdi_bean=true
>
> to src/test/resources/META-INF/apache-deltaspike.properties fixed the
> problem.
>
> Thanks,
>
> Paul
>
> On 10 December 2015 at 18:57, Gerhard Petracek <gerhard.petracek@gmail.com
> > wrote:
>
>> hi paul,
>>
>> if the test-class itself should be handled as a cdi-bean, you need to
>> enable
>> deltaspike.testcontrol.use_test_class_as_cdi_bean
>> in META-INF/apache-deltaspike.properties.
>> it's disabled per default, because there are some limitations.
>>
>> regards,
>> gerhard
>>
>> http://www.irian.at
>>
>> Your JavaEE powerhouse -
>> JavaEE Consulting, Development and
>> Courses in English and German
>>
>> Professional Support for Apache
>> MyFaces, DeltaSpike and OpenWebBeans
>>
>>
>>
>> 2015-12-10 5:56 GMT+01:00 Paul Wills <pa...@engsol.com.au>:
>>
>>> I don't know if this is viewed as a problem or not, but when I wrote a
>>> test
>>> class and annotated it with
>>> @RunWith(CdiTestRunner.*class*)
>>> the following test method is called as a non proxied method call from
>>> reflection, indicating to me that the @Transactional annotation cannot be
>>> having any effect.
>>>
>>> @Test
>>> @Transactional
>>> *public* *void testSaveAndFetchUser() {*
>>>
>>> // Given - a new user
>>> *final* User randomUser = createRandomUser(*false*);
>>>
>>> // When - saved
>>> *final* User savedUser = userService.saveUser(randomUser);
>>>
>>> // Then - user is saved as well as history and can be retrieved by id
>>> and username
>>> *assertThat*(savedUser.getRoles(), *hasSize*(*greaterThan*(0)));
>>> ...
>>> }
>>>
>>> Regards,
>>> Paul Wills
>>>
>>
>>
>
Re: CdiTestRunner fails to create proxy for the test class so
@Transactional annotation is ignored
Posted by Paul Wills <pa...@engsol.com.au>.
Hi Gerhard,
adding
deltaspike.testcontrol.use_test_class_as_cdi_bean=true
to src/test/resources/META-INF/apache-deltaspike.properties fixed the
problem.
Thanks,
Paul
On 10 December 2015 at 18:57, Gerhard Petracek <ge...@gmail.com>
wrote:
> hi paul,
>
> if the test-class itself should be handled as a cdi-bean, you need to
> enable
> deltaspike.testcontrol.use_test_class_as_cdi_bean
> in META-INF/apache-deltaspike.properties.
> it's disabled per default, because there are some limitations.
>
> regards,
> gerhard
>
> http://www.irian.at
>
> Your JavaEE powerhouse -
> JavaEE Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache
> MyFaces, DeltaSpike and OpenWebBeans
>
>
>
> 2015-12-10 5:56 GMT+01:00 Paul Wills <pa...@engsol.com.au>:
>
>> I don't know if this is viewed as a problem or not, but when I wrote a
>> test
>> class and annotated it with
>> @RunWith(CdiTestRunner.*class*)
>> the following test method is called as a non proxied method call from
>> reflection, indicating to me that the @Transactional annotation cannot be
>> having any effect.
>>
>> @Test
>> @Transactional
>> *public* *void testSaveAndFetchUser() {*
>>
>> // Given - a new user
>> *final* User randomUser = createRandomUser(*false*);
>>
>> // When - saved
>> *final* User savedUser = userService.saveUser(randomUser);
>>
>> // Then - user is saved as well as history and can be retrieved by id
>> and username
>> *assertThat*(savedUser.getRoles(), *hasSize*(*greaterThan*(0)));
>> ...
>> }
>>
>> Regards,
>> Paul Wills
>>
>
>
Re: CdiTestRunner fails to create proxy for the test class so
@Transactional annotation is ignored
Posted by Gerhard Petracek <ge...@gmail.com>.
hi paul,
if the test-class itself should be handled as a cdi-bean, you need to enable
deltaspike.testcontrol.use_test_class_as_cdi_bean
in META-INF/apache-deltaspike.properties.
it's disabled per default, because there are some limitations.
regards,
gerhard
http://www.irian.at
Your JavaEE powerhouse -
JavaEE Consulting, Development and
Courses in English and German
Professional Support for Apache
MyFaces, DeltaSpike and OpenWebBeans
2015-12-10 5:56 GMT+01:00 Paul Wills <pa...@engsol.com.au>:
> I don't know if this is viewed as a problem or not, but when I wrote a test
> class and annotated it with
> @RunWith(CdiTestRunner.*class*)
> the following test method is called as a non proxied method call from
> reflection, indicating to me that the @Transactional annotation cannot be
> having any effect.
>
> @Test
> @Transactional
> *public* *void testSaveAndFetchUser() {*
>
> // Given - a new user
> *final* User randomUser = createRandomUser(*false*);
>
> // When - saved
> *final* User savedUser = userService.saveUser(randomUser);
>
> // Then - user is saved as well as history and can be retrieved by id
> and username
> *assertThat*(savedUser.getRoles(), *hasSize*(*greaterThan*(0)));
> ...
> }
>
> Regards,
> Paul Wills
>