cancel
Showing results for 
Search instead for 
Did you mean: 

How to use BaseAlfrescoSpringTest

legolas
Champ in-the-making
Champ in-the-making
Hi All,

I am developing a custom action and would like to add a Unit test to it especially to ease the devlopment cycle.

As a starting point I used the SDK custom aspect project, which contains a Unit test, but that unit test won't run.
Can someone please shed some light on this?

I started the
org.alfresco.sample.ContentHitsAspectTest
class from eclipse, but it gave me the following results:

16:41:47,821 ERROR [transform.magick.AbstractImageMagickContentTransformer] ImageMagickContentTransformer not available: Failed to execute command: imconvert "C:\DOCUME~1\md80469\LOCALS~1\Temp\Alfresco\ImageMagickContentTransformer_init_source_23436.gif"  "C:\DOCUME~1\md80469\LOCALS~1\Temp\Alfresco\ImageMagickContentTransformer_init_target_23437.png"
16:41:49,977 WARN  [remoting.rmi.RmiRegistryFactoryBean] Could not detect RMI registry - creating new one
16:41:52,805 WARN  [alfresco.util.OpenOfficeConnectionTester] A connection to OpenOffice could not be established.
16:42:01,617 WARN  [repo.admin.ConfigurationChecker] The Alfresco 'dir.root' property is set to a relative path './alf_data'.  'dir.root' should be overridden to point to a specific folder.
16:42:01,617 INFO  [repo.admin.ConfigurationChecker] The Alfresco root data directory ('dir.root') is: .\alf_data
16:42:01,805 ERROR [repo.admin.ConfigurationChecker] CONTENT INTEGRITY ERROR: Indexes not found for 5 stores.
16:42:01,805 INFO  [repo.admin.ConfigurationChecker] You may set 'index.recovery.mode=FULL' if you need to rebuild the indexes.
16:42:01,805 ERROR [repo.admin.ConfigurationChecker] CONTENT INTEGRITY ERROR: System content not found in content store.
16:42:01,805 ERROR [repo.admin.ConfigurationChecker] Ensure that the 'dir.root' property is pointing to the correct data location.
java.lang.ExceptionInInitializerError
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
   at junit.framework.TestSuite.createTest(TestSuite.java:131)
   at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
   at junit.framework.TestSuite.<init>(TestSuite.java:75)
   at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:102)
   at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:59)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.alfresco.error.AlfrescoRuntimeException: Ensure that the 'dir.root' property is pointing to the correct data location.
   at org.alfresco.repo.admin.ConfigurationChecker.check(ConfigurationChecker.java:313)
   at org.alfresco.repo.admin.ConfigurationChecker.access$000(ConfigurationChecker.java:74)
   at org.alfresco.repo.admin.ConfigurationChecker$1.doWork(ConfigurationChecker.java:180)
   at org.alfresco.repo.transaction.TransactionUtil.executeInTransaction(TransactionUtil.java:176)
   at org.alfresco.repo.transaction.TransactionUtil.executeInUserTransaction(TransactionUtil.java:82)
   at org.alfresco.repo.admin.ConfigurationChecker.onBootstrap(ConfigurationChecker.java:184)
   at org.alfresco.util.AbstractLifecycleBean.onApplicationEvent(AbstractLifecycleBean.java:62)
   at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:45)
   at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:225)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:323)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:87)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:72)
   at org.alfresco.util.ApplicationContextHelper.getApplicationContext(ApplicationContextHelper.java:48)
   at org.alfresco.sample.ContentHitsAspectTest.<clinit>(ContentHitsAspectTest.java:55)
   … 13 more
Thanks.
Mracel
4 REPLIES 4

legolas
Champ in-the-making
Champ in-the-making
Is there nobody out there who can shed some light on this problem or did I post in the wrong forum?

Hope someone can help, it really eases the development cycle of custom actions if they can be tested outside of a running appserver that needs to be restarted each time the code has changed.

frederick
Champ in-the-making
Champ in-the-making
When those unit tests are run, they launch an embedded Alfresco repository using the 'custom-repository.properties' config file.
There, you can specify a db schema and data folder for the embedded repository.
You can use your existing repository to run your tests in, or you can create a new repository exclusively for unit tests.
However, if you use an existing db schema, you must ensure that the 'dir.root' property in custom-repository.properties points to the folder that matches your existing schema.

E.g. in an out-of-the-box Alfresco installation on windows, dir.root is set to the absolute path '<installation-path>/alf_data'.
But the custom-repository.properties file of the SDK CustomAspect unit test defines dir.root as the relative path './alf-data' (that is relative to your execution path, e.g. your eclipse project folder).

The error you get is caused by a mismatch between your db schema and your alf_data folder. To solve it, you must change the dir.root property in your unit test to point to the folder that matches your db schema.

Regards,

avro
Champ in-the-making
Champ in-the-making
However, if you use an existing db schema, you must ensure that the 'dir.root' property in custom-repository.properties points to the folder that matches your existing schema.

In my case the dir.root property points to ./alf_data

How do I see if it matches my existing db schema?

legolas
Champ in-the-making
Champ in-the-making
Thank you for your clarification Frederick.
I have changed the custom-repository.properties to reflect the following, and now the unit test runs fine.

#
# Sample custom content and index data location
#

dir.root=./alf_data


#db.username=alfresco
#db.password=alfresco

#
# MySQL connection (This is default and requires mysql-connector-java-3.1.12-bin.jar, which ships with the Alfresco server)
#
db.driver=org.gjt.mm.mysql.Driver
db.url=jdbc:mysql://localhost/alfresco_test

Next thing is to make the unit tests independent of any existing environment, meaning building the database before starting the actual test and destroying it again afterwards.

Thanks again,
Marcel
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.