Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Stef Heyenrath
Unit Test only possible for portal, not for portlets with services? {Solve
August 20, 2009 2:10 AM
Answer

Stef Heyenrath

Rank: Junior Member

Posts: 76

Join Date: December 3, 2008

Recent Posts

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.
Stef Heyenrath
RE: Unit Testing only possible for portal, not for portlets with services?
August 20, 2009 2:09 AM
Answer

Stef Heyenrath

Rank: Junior Member

Posts: 76

Join Date: December 3, 2008

Recent Posts

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.
Chandrasekhar Kothuri
RE: Unit Testing only possible for portal, not for portlets with services?
November 26, 2009 10:10 PM
Answer

Chandrasekhar Kothuri

Rank: Regular Member

Posts: 149

Join Date: July 6, 2009

Recent Posts

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
Laurent Gauthier
RE: Unit Testing only possible for portal, not for portlets with services?
June 8, 2010 10:00 AM
Answer

Laurent Gauthier

Rank: New Member

Posts: 15

Join Date: February 2, 2010

Recent Posts

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