cancel
Showing results for 
Search instead for 
Did you mean: 

Unit test cases for Java Controller based Webscripts in Alfresco

sarakahn
Champ in-the-making
Champ in-the-making

I plan to unit test the webscripts that had Java as controllers. I have found two approaches.

1) Go along the lines of bootstrap code HelloWorldWebScriptControllerTest.java

2) Follow https://github.com/Alfresco/alfresco-remote-api. Here, the test classes extend org.alfresco.repo.web.scripts.BaseWebScriptTest.

For the second approach, I tried adding the following dependency, but cannot find this BaseWebScriptTest.

<!-- https://mvnrepository.com/artifact/org.alfresco/alfresco-remote-api --> <dependency>     <groupId>org.alfresco</groupId>     <artifactId>alfresco-remote-api</artifactId>     <version>5.2.b-EA</version> </dependency>

I tried adding <classifier>tests</classifier> to the above dependency as well. But, cannot find this class.

How can this issue be resolved? Also, which approach is suggested?

3 REPLIES 3

krutik_jayswal
Elite Collaborator
Elite Collaborator

In the second approach you are trying to add EA version,which does not exist in the specified url.

You can use another version.

Check by your self on below URL.

Maven Repository: org.alfresco » alfresco-remote-api 

I have taken the latest one as well. But, the BaseWebScriptTest is missing. I was wondering if my approach to alfresco-remote-api is correct. 

Also, if I follow the first method, I need to mock lot of services as well. How should I mock ServiceRegistry or NodeService? 

However, in this way you would always need an active container. There are other quicker and easier ways to test a controller. You could simply add the alfresco-tests library into your sdk, write a test and run it without needing an active ACS. Here you will find the details https://alfresco-tests.vige.it