cancel
Showing results for 
Search instead for 
Did you mean: 

Unit testing org.alfresco.repo.jscript.People.getPeople()

muralidharand
Star Contributor
Star Contributor
Hi Experts,

I am trying to do unit testing
 org.alfresco.repo.jscript.People.getPeople(String) 
method but I am getting, null pointer exception.

java.lang.NullPointerException
   at org.alfresco.repo.jscript.People.getPeoplePaging(People.java:572)
   at org.alfresco.repo.jscript.People.getPeople(People.java:559)
   at org.alfresco.repo.jscript.People.getPeople(People.java:539)
   at org.alfresco.repo.jscript.People.getPeople(People.java:522)
   at org.alfresco.repo.jscript.PeopleTest.testGetPeople(PeopleTest.java:110)
   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)


After debugging I found that, "Context" is null during unit testing in
 org.alfresco.repo.jscript.People.getPeoplePaging(String, ScriptPagingDetails, String, Boolean)
.

Can you please guide me, how I can do the unit testing
 org.alfresco.repo.jscript.People.getPeople(String) 
method?

Thanks,
Murali
2 REPLIES 2

mrogers
Star Contributor
Star Contributor
Please post your test code.    Or are you just trying to run the alfresco provided org.alfresco.repo.jscript.PeopleTest in Eclipse without modification ?

muralidharand
Star Contributor
Star Contributor
Hi Roger,
Thanks for your time.

<strong>Unit testing code </strong>

protected void onSetUpInTransaction() throws Exception

super.onSetUpInTransaction();
people = (CliQPeople) super.applicationContext.getBean("peopleScript");
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
createSite(SITE_NAME);
createUsers();
AssociateUsersAndSites();
}
@Test
    public void test()
    {
       Scriptable result = people.getPeople("user*", 1000);
       assertTrue(true);
       assertNotNull(result);
       assertEquals(new Double(1.0), result.get("length", result));
    }



Default getPeople() code

public Scriptable getPeople(String filter, int maxResults)
   {…………..
}



Please let me know, if you need any information on this.