You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Alice Liu <al...@axis41.com> on 2006/12/07 19:15:01 UTC
I got NullPointer Exception when I test my ejb (EJB3.0 version) using Junit with Cactus
HI,
My code is like this.
public class SampleFacadeTest extends ServletTestCase {
@EJB
SampleFacadeLocal sampleFacade;
public void setUp() {
}
public static Test suite()
{
return new TestSuite(SampleFacadeTest.class);
}
*/
public void testFind() throws Exception{
String firsName = "Rick";
String testName = sampleFacade.find(112233).getFirstName();
assertEquals(firsName , testName);
}
}
The sampleFacade variable got null pointer exception at line
String testName = sampleFacade.find(112233).getFirstName();
EJB3.0 is new thing. I wish I could get answer from here.
Thanks.
Re: I got NullPointer Exception when I test my ejb (EJB3.0 version) using Junit with Cactus
Posted by Franz Roth <fr...@gmx.de>.
if this works [and your facade isn't "null":)], check whether the searched
object is null
assertNotNull(sampleFacade.find(112233));
> Hi, Franz
>
> In the new version EJB3.0 we use annotation @EJB to refer an ejb
>
> @EJB
> SampleFacadeLocal sampleFacade;
>
> We don't use instance. Even though I instantiated it, I got Null Pointer
> in SampleFacade class at line that use em(EntityManager). In EJB3.0 we
> define em like this:
>
> @PersistenceContext(unitName="someName")
> private EntityManager em;
>
> Thanks.
>
> -----Original Message-----
> From: Franz Roth [mailto:franzroth@gmx.de]
> Sent: Thursday, December 07, 2006 11:26 AM
> To: Cactus Users List
> Subject: Re: I got NullPointer Exception when I test my ejb (EJB3.0
> version) using Junit with Cactus
>
> hi,
>
> in your sample-code the sampleFacede is never instantiated; so it's null
>
> while you're trying to find somthing with it?!
>
>
>
>> HI,
>>
>>
>> My code is like this.
>>
>>
>> public class SampleFacadeTest extends ServletTestCase {
>>
>>
>> @EJB
>>
>> SampleFacadeLocal sampleFacade;
>>
>>
>> public void setUp() {
>>
>>
>> }
>>
>>
>> public static Test suite()
>>
>> {
>>
>> return new TestSuite(SampleFacadeTest.class);
>>
>> }
>>
>> */
>>
>>
>> public void testFind() throws Exception{
>>
>> String firsName = "Rick";
>>
>> String testName = sampleFacade.find(112233).getFirstName();
>>
>> assertEquals(firsName , testName);
>>
>> }
>>
>>
>>
>>
>> }
>>
>>
>> The sampleFacade variable got null pointer exception at line
>>
>>
>> String testName = sampleFacade.find(112233).getFirstName();
>>
>>
>> EJB3.0 is new thing. I wish I could get answer from here.
>>
>>
>> Thanks.
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
--
franz roth
schulstr. 15
72669 Unterensingen
07022 604963
RE: I got NullPointer Exception when I test my ejb (EJB3.0 version) using Junit with Cactus
Posted by Alice Liu <al...@axis41.com>.
Hi, Franz
In the new version EJB3.0 we use annotation @EJB to refer an ejb
@EJB
SampleFacadeLocal sampleFacade;
We don't use instance. Even though I instantiated it, I got Null Pointer
in SampleFacade class at line that use em(EntityManager). In EJB3.0 we
define em like this:
@PersistenceContext(unitName="someName")
private EntityManager em;
Thanks.
-----Original Message-----
From: Franz Roth [mailto:franzroth@gmx.de]
Sent: Thursday, December 07, 2006 11:26 AM
To: Cactus Users List
Subject: Re: I got NullPointer Exception when I test my ejb (EJB3.0
version) using Junit with Cactus
hi,
in your sample-code the sampleFacede is never instantiated; so it's null
while you're trying to find somthing with it?!
> HI,
>
>
> My code is like this.
>
>
> public class SampleFacadeTest extends ServletTestCase {
>
>
> @EJB
>
> SampleFacadeLocal sampleFacade;
>
>
> public void setUp() {
>
>
> }
>
>
> public static Test suite()
>
> {
>
> return new TestSuite(SampleFacadeTest.class);
>
> }
>
> */
>
>
> public void testFind() throws Exception{
>
> String firsName = "Rick";
>
> String testName = sampleFacade.find(112233).getFirstName();
>
> assertEquals(firsName , testName);
>
> }
>
>
>
>
> }
>
>
> The sampleFacade variable got null pointer exception at line
>
>
> String testName = sampleFacade.find(112233).getFirstName();
>
>
> EJB3.0 is new thing. I wish I could get answer from here.
>
>
> Thanks.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-user-help@jakarta.apache.org
Re: I got NullPointer Exception when I test my ejb (EJB3.0 version) using Junit with Cactus
Posted by Franz Roth <fr...@gmx.de>.
hi,
in your sample-code the sampleFacede is never instantiated; so it's null
while you're trying to find somthing with it?!
> HI,
>
>
> My code is like this.
>
>
> public class SampleFacadeTest extends ServletTestCase {
>
>
> @EJB
>
> SampleFacadeLocal sampleFacade;
>
>
> public void setUp() {
>
>
> }
>
>
> public static Test suite()
>
> {
>
> return new TestSuite(SampleFacadeTest.class);
>
> }
>
> */
>
>
> public void testFind() throws Exception{
>
> String firsName = "Rick";
>
> String testName = sampleFacade.find(112233).getFirstName();
>
> assertEquals(firsName , testName);
>
> }
>
>
>
>
> }
>
>
> The sampleFacade variable got null pointer exception at line
>
>
> String testName = sampleFacade.find(112233).getFirstName();
>
>
> EJB3.0 is new thing. I wish I could get answer from here.
>
>
> Thanks.
>