Foren
Junit Examples
pooja mahajan, geändert vor 11 Jahren.
Junit Examples
Junior Member Beiträge: 45 Beitrittsdatum: 30.01.13 Neueste 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
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, geändert vor 11 Jahren.
RE: Junit Examples
Junior Member Beiträge: 45 Beitrittsdatum: 30.01.13 Neueste 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)
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 Kumar Saini, geändert vor 11 Jahren.
RE: Junit Examples
Regular Member Beiträge: 104 Beitrittsdatum: 27.07.11 Neueste 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
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, geändert vor 11 Jahren.
RE: Junit Examples
Junior Member Beiträge: 45 Beitrittsdatum: 30.01.13 Neueste 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
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 Kumar Saini, geändert vor 11 Jahren.
RE: Junit Examples
Regular Member Beiträge: 104 Beitrittsdatum: 27.07.11 Neueste 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);
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, geändert vor 11 Jahren.
RE: Junit Examples
Junior Member Beiträge: 45 Beitrittsdatum: 30.01.13 Neueste Beiträge
Thanks for helping me...
Suggestion provided by you is working....
Suggestion provided by you is working....
pooja mahajan, geändert vor 10 Jahren.
RE: Junit Examples
Junior Member Beiträge: 45 Beitrittsdatum: 30.01.13 Neueste 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.
// httpReq
HttpServletRequest httpRequest=mock(HttpServletRequest.class);
// how to mock or skip following call
AuthTokenUtil.getToken(httpRequest) ;
for junit testcases.
pooja mahajan, geändert vor 10 Jahren.
RE: Help for Junit for liferay 5.2
Junior Member Beiträge: 45 Beitrittsdatum: 30.01.13 Neueste Beiträge
Hi,
Can anyone please help me to mock /execute following in junit:
UserLocalServiceUtil.getUserById(userId).getRoles()
I was unable to mock UserLocalServiceUtil :
Can anyone please help me to mock /execute following in junit:
UserLocalServiceUtil.getUserById(userId).getRoles()
I was unable to mock UserLocalServiceUtil :
Sushil Kumar Saini, geändert vor 10 Jahren.
RE: Junit Examples
Regular Member Beiträge: 104 Beitrittsdatum: 27.07.11 Neueste 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
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