1
votes

I am looking for a method for testing Alfresco repository Java services without the need for deploying to a Tomcat server.

My idea is to start Alfresco embedded from a JUnit testclass, inject the classes I want to test into the Alfresco Spring configuration and test the classes using JUnit test methods.

The Alfresco sample application "FirstFoundationClient" is a good entry point for getting the above working but when I try to start the sample with a H2 memory database in MySQL-mode it outputs the following error:

SqlMapException: The <sqlMap> resource is missing: /alfresco/ibatis/#resource.dialect#/qname-insert-SQLMap.xml

My alfresco-global.properties configuration in the sample project:

dir.root=./alf_data
db.driver=org.h2.Driver
db.url=jdbc:h2:alf_data/h2_data/alfresco;MODE=MySQL
db.username=alfresco
db.password=alfresco

Can anyone help me with:

  • how to get FirstFoundationClient (from Alfresco Enterprise SDK 3.4.0) running using a H2 database

  • how to inject the classes under test so I can access them from the Spring application context (like standard Alfresco services are accessed in the FirstFoundationClient sample)

1
Did you try looking at some of the Alfresco unit tests, to see how it's done there? (It might be easier to follow the pattern that Alfresco itself uses for testing) - Gagravarr
Not sure that the post you're pointing to is saying that it's possible to test Alfresco with JUnit. I think it's saying that you can simulate Postgres with h2sqldb. If you want to use JUnit, you can start Alfresco in a jetty server probably, which would be fast enough for unit testing. Or at least functional testing. - Matthew Farwell
Alfresco has a large number of unit tests, all of which involve starting up some/all of the repository inside JUnit, testing something in a unit test, and closing it down. No tomcat or jetty is needed for these. You may find your simplest solution is to copy how the Alfresco unit tests work for you case - Gagravarr
@MatthewFarwell You are right about JUnit and the referenced post. JUnit should not be a problem though. The real problem is getting Alfresco running embedded without the need of an external database. Jetty might be something to try out but a solution where I have to deploy to an application server leads to a more complicated configuration of the continues integration process (and thereby risk of unstable builds). - mrbang
@Gagravarr have you actually had the Alfresco unittests or your own classes extending the Alfresco test base classes running with success? I have searched for documentation on how to setup my environment (e.g. Eclipse) to get this working but with no luck. When I try extending the classes Alfresco use for their testclasses it fails during initialization (e.g. Hibernate exceptions) and when I Google the problems I get no hits. - mrbang

1 Answers

3
votes

If you're willing to give the maven way a try, I published a little tutorial about how to use H2 with Alfresco. Here's a project where I'm leveraging that approach that you might use as a template.

NOTE: Alfresco v4.x might not be compatible with H2 - PostgreSQL mode


EDIT: the new h2-support v1.2 supports Alfresco4


EDIT: h2-support now supports up to Alfresco 4.0.2