Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
pooja mahajan
Junit Examples
26. Februar 2013 22:49
Antwort

pooja mahajan

Rang: Junior Member

Nachrichten: 45

Eintrittsdatum: 29. Januar 2013

Neue Beiträge

Can anyone please help me with junit test cases for any portlet Controller.
I am unable to create proxy [mock objects ] for PortalUtil.
Issue:
@Mock HttpServletRequest httpRequest;
@Mock PortletRequest portletRequest ;

@Before
public void setUp() throws Exception {
when(PortalUtil.getHttpServletRequest(portletRequest)).thenReturn(httpRequest);

}

above line is giving me null pointer exception
pooja mahajan
RE: Junit Examples
28. Februar 2013 23:34
Antwort

pooja mahajan

Rang: Junior Member

Nachrichten: 45

Eintrittsdatum: 29. Januar 2013

Neue Beiträge

Can anyone please help:
We are using liferay 5.2 + junit 4
want to write junit test case:

Isuues:

@Before
public void setUp() throws Exception {

InitUtil.initWithSpring();
}

Error:

java.lang.NoClassDefFoundError: javax/servlet/jsp/JspException
at com.liferay.portal.kernel.util.JavaProps.<init>(JavaProps.java:114)
at com.liferay.portal.kernel.util.JavaProps.<clinit>(JavaProps.java:119)
at com.liferay.portal.util.InitUtil.init(InitUtil.java:115)
at com.liferay.portal.util.InitUtil.initWithSpring(InitUtil.java:130)
Sushil Saini
RE: Junit Examples
1. März 2013 02:52
Antwort

Sushil Saini

Rang: Regular Member

Nachrichten: 102

Eintrittsdatum: 27. Juli 2011

Neue Beiträge

Hi Pooja,

I am using the mockito liberary for Junit testing and creating the mock objects in the following manner. And it is working fine for me.

PortletConfig mockConfig = mock(PortletConfig.class);
PortletContext mockContext = mock(PortletContext.class);

when(mockConfig.getPortletContext()).thenReturn(mockContext);



Cheers
pooja mahajan
RE: Junit Examples
5. März 2013 05:21
Antwort

pooja mahajan

Rang: Junior Member

Nachrichten: 45

Eintrittsdatum: 29. Januar 2013

Neue Beiträge

Thanks,
getting an nullpointerException for below:

HttpServletRequest httpRequest = PortalUtil .getHttpServletRequest(portletRequest);


when i am trying to run junit test case for a method in controller....
please help
Sushil Saini
RE: Junit Examples
5. März 2013 10:33
Antwort

Sushil Saini

Rang: Regular Member

Nachrichten: 102

Eintrittsdatum: 27. Juli 2011

Neue Beiträge

Please try the below sample code ....

Portal portal = mock(Portal.class);
HttpServletRequest httpRequest = mock(HttpServletRequest.class);

new PortalUtil().setPortal(portal);
when(portal.getHttpServletRequest(eq(renderRequest))).thenReturn(httpRequest);


HttpServletRequest originalHttpServletRequest = mock(HttpServletRequest.class);
when(portal.getOriginalServletRequest(eq(httpRequest))).thenReturn(originalHttpServletRequest);
pooja mahajan
RE: Junit Examples
7. März 2013 00:58
Antwort

pooja mahajan

Rang: Junior Member

Nachrichten: 45

Eintrittsdatum: 29. Januar 2013

Neue Beiträge

Thanks for helping me...
Suggestion provided by you is working....
pooja mahajan
RE: Junit Examples
2. Mai 2013 01:59
Antwort

pooja mahajan

Rang: Junior Member

Nachrichten: 45

Eintrittsdatum: 29. Januar 2013

Neue Beiträge

Hi can anyone please help me to mock :

// httpReq
HttpServletRequest httpRequest=mock(HttpServletRequest.class);

// how to mock or skip following call
AuthTokenUtil.getToken(httpRequest) ;

for junit testcases.
pooja mahajan
RE: Help for Junit for liferay 5.2
5. Mai 2013 23:45
Antwort

pooja mahajan

Rang: Junior Member

Nachrichten: 45

Eintrittsdatum: 29. Januar 2013

Neue Beiträge

Hi,

Can anyone please help me to mock /execute following in junit:

UserLocalServiceUtil.getUserById(userId).getRoles()

I was unable to mock UserLocalServiceUtil :
Sushil Saini
RE: Junit Examples
8. Mai 2013 16:12
Antwort

Sushil Saini

Rang: Regular Member

Nachrichten: 102

Eintrittsdatum: 27. Juli 2011

Neue Beiträge

Hi Pooja,

Can you check the below link ... it have the example of mocking UserLocalServiceUtil.

http://www.liferay.com/community/wiki/-/wiki/Main/How+to+use+JUnit+to+test+service+in+portlets/maximized

Cheers
Sushil Saini