掲示板

Configure liferay for Junit ..

thumbnail
12年前 に Rojalin Patri によって更新されました。

Configure liferay for Junit ..

Expert 投稿: 287 参加年月日: 11/03/22 最新の投稿
Hi All,
we have a method that creates a new user using Liferay,we need to write a Junit case for that.And in order to do that we need to replicate the Liferay environment,to test that in standalone mode i.e Junit.How can we configure liferay first for junit....
Please help..
Thanks
Rojalin
thumbnail
12年前 に Sandeep Nair によって更新されました。

RE: Configure liferay for Junit ..

Liferay Legend 投稿: 1744 参加年月日: 08/11/06 最新の投稿
Check the following link please

http://www.liferay.com/community/wiki/-/wiki/Main/Integrating+unit+tests+with+plugins+SDK

Regards,
Sandeep
thumbnail
12年前 に Rojalin Patri によって更新されました。

RE: Configure liferay for Junit ..

Expert 投稿: 287 参加年月日: 11/03/22 最新の投稿
Thanks for the reply Sandeep.i have alreday gone through the wiki link.and i am sorry i didn't mention my requirement clearly.
Actually i am testing a application developed on liferay.so one of my testcase requirement is "It has to test whether the liferay services are up or not".For that i need the server should be up and running.while doing automation testing it's not always possible to start and shut down the server.so i need somehow the startup.bat file should be invoked programatically.or we need to simulate the environment somehow so that i can check the services are up or not.
Any idea on this Sandeep??????or any suggestions how to proceed??
Thanks
Rojalin
thumbnail
12年前 に Michael Wall によって更新されました。

RE: Configure liferay for Junit ..

Junior Member 投稿: 60 参加年月日: 10/07/22 最新の投稿
You could have your JUnit setup method call a batch file that checks the status of the App Server service (e.g. if you are using JBoss) and stops / starts the Service as needed.

You can monitor and stop / start services on a remote machine.

Alternatively have your JUnit setup method, attempt to connect to the app server url programatically and proceed based on the response code.
thumbnail
12年前 に Rojalin Patri によって更新されました。

RE: Configure liferay for Junit ..

Expert 投稿: 287 参加年月日: 11/03/22 最新の投稿
Hi Michael,
thanks for the reply.it was helpful.
Thanks
Rojalin
thumbnail
12年前 に Rojalin Patri によって更新されました。

RE: Configure liferay for Junit ..

Expert 投稿: 287 参加年月日: 11/03/22 最新の投稿
Hi All,
finally got it worked.i wanted to test default liferay services let's say addUser() function or getUsers() function.So i did it in following way.
1.i imported junit.jar to the library folder of my project and all jars related to struts,hibernate and the jars like portal-service.jar,portal-impl.jar whose functions i am gonna test.
2.then in src folder i placed my testcase.for example:the below code in my program.
package com.liferay.JunitTest;
import org.junit.After;
import org.junit.Before;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.service.UserService;
import com.liferay.portal.service.UserLocalService;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portal.service.UserServiceUtil;
import com.liferay.portal.service.UserServiceTest;
//import com.liferay.portal.model.*;
import com.liferay.portal.model.User;
import com.liferay.portal.kernel.*;
//import com.liferay.portal.*;
import org.junit.Test;
import junit.framework.TestCase;
//import junit.framework.TestSuite;
import java.util.Locale;

import javax.portlet.PortletRequest;
import javax.servlet.http.HttpServletRequest;
import com.liferay.portal.util.InitUtil;

public class NewTest extends TestCase
{
private User user=null;
private Locale locale;
private UserService userService=null;
private ServiceContext serviceContext=new ServiceContext();
private UserServiceTest test=new UserServiceTest();

@Before
public void setUp() throws Exception {
super.setUp();
}
@After
public void tearDown() throws Exception {
super.tearDown();
}
@Test
public void testmyTest()throws Exception
{

System.out.println("A new Testcase");

UserLocalService localService=UserLocalServiceUtil.getService();

java.util.List<com.liferay.portal.model.User> user=localService.getUsers(0,9);
System.out.println("Number of User:"+localService.getUsersCount());

for(User u:user)
{
System.out.println("users first name:"+u.getFirstName()+"-"+u.getEmailAddress());

}

}
}
3.In src folder itself added two more property files portal-ext.properties and portal-test.properties and added the following code to the property files respectively
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=

hibernate.cache.use_query_cache=false
hibernate.cache.use_second_level_cache=false
hibernate.cache.use_minimal_puts=false
hibernate.cache.use_structured_entries=false
..................................................................................
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=

value.object.listener.com.liferay.portal.model.LayoutSet=
ehcache.portal.cache.manager.jmx.enabled=false
resource.repositories.root=/home/rojalin/Desktop/liferay-portal-5.2.3/tomcat-6.0.18/webapps/ROOT(path of the tomcat bundle)
scheduler.enabled=false

hibernate.configs=\
META-INF/mail-hbm.xml,\
META-INF/portal-hbm.xml,\
META-INF/ext-hbm.xml
4.then i run the run the testcase as Junit testcase.and it compile the Testcase.java file successfully.
This may not be a significant one.but hope this will help someone in the community who would be struggling like me regarding Junit.
Thanks to the community for the inputs i have got to make it work.
thumbnail
12年前 に P.C. SUN によって更新されました。

RE: Configure liferay for Junit ..

New Member 投稿: 9 参加年月日: 11/10/18 最新の投稿
Hi Rojalin,

I also tried to write Junit test code and I tried your sample as well. However, I always got the error: BeanLocator is Null. Could u tell me how you handle that?

And in the project build path, I put all jar files in which are from ROOT/lib. However, I still cannot find the UserServiceTest test=new UserServiceTest(). Can you let me know whether it is useful or how we get that?

Thank you and looking forwards to your reply.

P.C.(JACK) Sun
thumbnail
12年前 に Rojalin Patri によって更新されました。

RE: Configure liferay for Junit ..

Expert 投稿: 287 参加年月日: 11/03/22 最新の投稿
Hi P.C,
first of all i apologize for not removing unwanted local variables and imports while posting the solution here in the thread.
and yes,u r right.this UserServiceTest test=new UserServiceTest() is not at all needed.i just imported to try it using the in built test services available inside Liferay.
Here i have just initiated the services using UserLocalService localService=UserLocalServiceUtil.getService();.
and could you please tell me where exactly you are getting this beanLocator Null problem???
thumbnail
12年前 に P.C. SUN によって更新されました。

RE: Configure liferay for Junit ..

New Member 投稿: 9 参加年月日: 11/10/18 最新の投稿
Hi Rojalin,

Thanks for your reply. I've already mode it work. emoticon The ext-spring.xml I put into a wrong place. And I post the update as a new wiki:

http://www.liferay.com/community/wiki/-/wiki/Main/How+to+use+JUnit+to+test+servi­ce+in+portlets

emoticon Thanks a lot for your information, it's very helpful.

B.R.

P.C.SUN
11年前 に Gautam Sharma によって更新されました。

RE: Configure liferay for Junit ..

Junior Member 投稿: 92 参加年月日: 12/04/30 最新の投稿
can you please share your sample war.

It would be great help
thumbnail
11年前 に P.C. SUN によって更新されました。

RE: Configure liferay for Junit ..

New Member 投稿: 9 参加年月日: 11/10/18 最新の投稿
Hi Gautam,

All the related source code and config files, I've already put into that WIKI. You can refer to that and try to make it.

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

I paste that URL into browser, seems not work, you can go to wiki and find that article.

Thanks.

P.C.
11年前 に Gautam Sharma によって更新されました。

RE: Configure liferay for Junit ..

Junior Member 投稿: 92 参加年月日: 12/04/30 最新の投稿
Hi its working fine with liferay 6.0 ce but not working in 6.1 ce any idea????
thumbnail
11年前 に P.C. SUN によって更新されました。

RE: Configure liferay for Junit ..

New Member 投稿: 9 参加年月日: 11/10/18 最新の投稿
Hi,

Basically, I tried that and it didn't work, seems the dependencies are changed in 6.1, as I didn't have enough time to do it further, I wish someone could help to make it work.

Thanks.
thumbnail
11年前 に Marco Dussin によって更新されました。

RE: Configure liferay for Junit ..

Junior Member 投稿: 45 参加年月日: 10/07/06 最新の投稿
I've got the same problem on LR 6.1 CE.

Have you resolved the "BeanLocator is null" error?

Thank you

Marco
thumbnail
11年前 に Rajender Reddy Nagulapalle によって更新されました。

RE: Configure liferay for Junit ..

Junior Member 投稿: 33 参加年月日: 11/05/21 最新の投稿
any one solved this issue. i am having same bean creation errors
11年前 に SZ khan によって更新されました。

RE: Configure liferay for Junit ..

Regular Member 投稿: 145 参加年月日: 09/10/31 最新の投稿
I don't see any working example of Junit with LIferay 6.1
thumbnail
11年前 に P.C. SUN によって更新されました。

RE: Configure liferay for Junit ..

New Member 投稿: 9 参加年月日: 11/10/18 最新の投稿
Hi CZ,

The JUnit way in this article is for 6.0, no idea anyone did some approach to 6.1

Did u try it? You may get some error for spring obj injection?

P.C.Sun
thumbnail
7年前 に Kalai Arasan によって更新されました。

RE: Configure liferay for Junit ..

Regular Member 投稿: 127 参加年月日: 13/01/02 最新の投稿
Hi,
I have tried the example in Liferay 6.2 and getting the below error.


A new Testcase
Loading jar:file:.m2/repository/com/liferay/portal/portal-impl/6.2.4/portal-impl-6.2.4.jar!/system.properties
Jun 07, 2016 9:58:47 AM com.liferay.portal.kernel.log.Jdk14LogImpl error
SEVERE: BeanLocator is null
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1365)
at com.liferay.portal.kernel.bean.PortalBeanLocatorUtil.locate(PortalBeanLocatorUtil.java:74)
at com.liferay.portal.service.UserLocalServiceUtil.getService(UserLocalServiceUtil.java:3417)
at com.junit.test.NewTest.testmyTest(NewTest.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)