Planned maintenance is scheduled for the week of June 15th - the exact date and time will be announced soon.
See More Details
Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Unit Test only possible for portal, not for portlets with services? {Solve
In the portal source code, there are several test classes. (portal-impl/test/com/liferay/counter/service/CounterServiceTest.java)
The most interesting class is : BaseTestCase.
In this class the environment is setup to make unit testing possible. (Spring beans are initialized and Jetty is started up.)
The method which does all the work is : InitUtil.initWithSpring().
I want to unit test the business logic from the services (classes created by the service-builder) from my portlet so that I don't need a fully working Liferay environment to test some small functionality.
The question is : How can I correctly initialize the spring beans from my own portlet ?
Because this is needed to solve the "BeanLocator is null" exception.
The most interesting class is : BaseTestCase.
In this class the environment is setup to make unit testing possible. (Spring beans are initialized and Jetty is started up.)
The method which does all the work is : InitUtil.initWithSpring().
I want to unit test the business logic from the services (classes created by the service-builder) from my portlet so that I don't need a fully working Liferay environment to test some small functionality.
The question is : How can I correctly initialize the spring beans from my own portlet ?
Because this is needed to solve the "BeanLocator is null" exception.
I found a solution!.
(It took a lot of searching + developing time to solve this issue, and as far as I know, this is the only solution present in the whole Liferay community!)
I did the following:
1. Create an own test project based on the portal-src from Liferay.
2. Remove all java files but keep all jar files.
3. Add portal-impl.jar, portal-kernel.jar, portal-service.jar and util-java.jar to this project.
4. Create an own version of initWithSpring() which initializes my portlet.
5. Update the build file from the services-portlet project to create a jar file which includes all classes + configuation files. (xml + properties)
See Services-Portlet project and the Test Services-Portlet project for more details.
(It took a lot of searching + developing time to solve this issue, and as far as I know, this is the only solution present in the whole Liferay community!)
I did the following:
1. Create an own test project based on the portal-src from Liferay.
2. Remove all java files but keep all jar files.
3. Add portal-impl.jar, portal-kernel.jar, portal-service.jar and util-java.jar to this project.
4. Create an own version of initWithSpring() which initializes my portlet.
5. Update the build file from the services-portlet project to create a jar file which includes all classes + configuation files. (xml + properties)
See Services-Portlet project and the Test Services-Portlet project for more details.
Hi,
Can you please explain in detail what you have followed the approach.
Actually I want to increment the liferay counter value by using the myeclipse.
Thanks in advance
Regards,
K.chandra sekhar
Can you please explain in detail what you have followed the approach.
Actually I want to increment the liferay counter value by using the myeclipse.
Thanks in advance
Regards,
K.chandra sekhar
For the benefits of those, who, like me, stumbled across the problem of unit testing Liferay portlets, I published a Blog article on the subject at: Liferay Portlet Unit testing.
It outlines a simple and effective solution to this problem. Feedback and comments are welcome.
Laurent
It outlines a simple and effective solution to this problem. Feedback and comments are welcome.
Laurent
Community
Company
Feedback