Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Tal M
Junit service in liferay
August 28, 2011 10:05 AM
Answer

Tal M

Rank: New Member

Posts: 5

Join Date: May 4, 2011

Recent Posts

Hi,
I'm trying to create a new service using liferay 6.0.6 with the recent liferay IDE 1.3. I crated a hook project with a service (the entity called country) and a junit:

public class CountriesLoader extends BaseServiceTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
ServiceTestUtil.initServices();
}

public void testLoadCountries() throws Exception {
CountryLocalService service = CountryLocalServiceUtil.getService();
...
}
}


I modified the relevant properties: portal-test.properties, test-portal-impl.properties

In addition I added a reference to portal (liferay source) project.

Once I run the junit (or even from a main method), I got this error:

java.lang.NullPointerException
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:73)


Please advise on how to resolve this error.


Thanks a lot.
Jelmer Kuperus
RE: Junit service in liferay
August 28, 2011 11:20 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

It's this issue : http://issues.liferay.com/browse/LPS-17126

basically you have a service with no @Transactional annotation slapped on
Tal M
RE: Junit service in liferay
August 29, 2011 8:25 AM
Answer

Tal M

Rank: New Member

Posts: 5

Join Date: May 4, 2011

Recent Posts

Thanks jelmer, I applied that patch and it solves the issue of null transaction.
However the junit is not working. I assume the way I'm using the service is wrong

CountryLocalService service = CountryLocalServiceUtil.getService();



portal-test.properties contains following xmls
spring.configs=\
META-INF/base-spring.xml,\
META-INF/hibernate-spring.xml,\
META-INF/infrastructure-spring.xml,\
META-INF/cluster-spring.xml,\
META-INF/portlet-spring.xml,\
META-INF/dynamic-data-source-spring.xml,\
META-INF/shard-data-source-spring.xml,\
META-INF/portlet-hbm.xml



Do I need the whole portal war in order execute a junit?
Andrés Cerezo
RE: Junit service in liferay
September 8, 2011 3:48 PM
Answer

Andrés Cerezo

Rank: Junior Member

Posts: 92

Join Date: November 11, 2010

Recent Posts

Hello Tai, Do you knwo the solution to run junit test in a portlet ?

Cheers
Tal M
RE: Junit service in liferay
September 10, 2011 8:47 AM
Answer

Tal M

Rank: New Member

Posts: 5

Join Date: May 4, 2011

Recent Posts

No, I did not find the solution for running liferay services Junit.
Kailas Lokhande
RE: Junit service in liferay
January 6, 2013 7:17 PM
Answer

Kailas Lokhande

Rank: New Member

Posts: 10

Join Date: November 6, 2012

Recent Posts

Anyone got solution for JUNIT in liferay??

Please reply...